Copy test of getpwuid from st - utmp - simple login manager  
 (HTM) git clone git://git.suckless.org/utmp
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 9631182347109af70cc725aabd6d567c83e989ec
 (DIR) parent 5ac5ede22b55ec5820dbacf1c5e5e9d9c2b2d9ad
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
       Date:   Thu, 28 Aug 2014 11:41:54 +0200
       
       Copy test of getpwuid from st
       
       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.
       
       Diffstat:
         M utmp.c                              |      10 +++++++---
       
       1 file changed, 7 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/utmp.c b/utmp.c
       @@ -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);