From: sin Date: Wed, 9 Jul 2014 13:40:49 +0000 (+0100) Subject: Only check errno if getpwuid() fails X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=8745098fa440ef3bf1d8e173dcd91514b34600c6;p=slock.git Only check errno if getpwuid() fails Checking errno otherwise is unspecified. --- diff --git a/slock.c b/slock.c index aedee2e..399386b 100644 --- a/slock.c +++ b/slock.c @@ -67,10 +67,12 @@ getpw(void) { /* only run as root */ errno = 0; pw = getpwuid(getuid()); - if (errno) - die("slock: getpwuid: %s\n", strerror(errno)); - else if (!pw) - die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n"); + if (!pw) { + if (errno) + die("slock: getpwuid: %s\n", strerror(errno)); + else + die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n"); + } endpwent(); rval = pw->pw_passwd;