Set errno to 0 before getpwuid() and check it afterwards - slock - simple X display locker utility
(HTM) git clone git://git.suckless.org/slock
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 6a5512835485ac501d983161ca15b311a95c5649
(DIR) parent ba3acfc0dcf1d0603bd9d6bdee1e319339b1a509
(HTM) Author: sin <sin@2f30.org>
Date: Thu, 14 Nov 2013 11:24:08 +0000
Set errno to 0 before getpwuid() and check it afterwards
Diffstat:
M slock.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/slock.c b/slock.c
@@ -65,8 +65,11 @@ getpw(void) { /* only run as root */
const char *rval;
struct passwd *pw;
+ errno = 0;
pw = getpwuid(getuid());
- if(!pw)
+ 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");
endpwent();
rval = pw->pw_passwd;