[dev] [utmp][PATCH 2/3] Copy test of getpwuid from st

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Tue, 16 Sep 2014 08:48:00 +0200

This part of the code is identicall to the code of st, and st does
better tests that utmp was doing, so we take the code of st.
---
 utmp.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/utmp.c b/utmp.c
index bda11d3..f551f9d 100644
--- a/utmp.c
+++ b/utmp.c
_AT_@ -46,9 +46,13 @@ main(int argc, char *argv[])
 	gid = getgid();
 	setgid(gid);
 
-	pw = getpwuid(uid = getuid());
-	if (!pw || !pw->pw_name)
-		die("Process is running with an incorrect uid %d", uid);
+	errno = 0;
+	if ((pw = getpwuid(uid = getuid())) == NULL) {
+		if(errno)
+			die("getpwuid:%s", strerror(errno));
+		else
+			die("who are you?");
+	}
 
 	setenv("LOGNAME", pw->pw_name, 1);
 	setenv("USER", pw->pw_name, 1);
-- 
1.9.3
Received on Tue Sep 16 2014 - 08:48:00 CEST

This archive was generated by hypermail 2.3.0 : Tue Sep 16 2014 - 09:00:17 CEST