diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-11-20 14:08:33 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-11-20 14:09:53 -0800 |
commit | 71b7ddcdd5c473f9eaf6035b96acc68c14cb379e (patch) | |
tree | a4d7544dc4ed5123a2ffaf40105fc8d0049ddf22 /src/su.c | |
parent | 8ffc159611db3443282aee42465afc8a1597519c (diff) | |
download | coreutils-71b7ddcdd5c473f9eaf6035b96acc68c14cb379e.tar.xz |
port to GNU hosts, where getuid and friends can fail
* src/groups.c (main):
* src/install.c (need_copy):
* src/su.c (log_su):
* src/test.c (unary_operator):
* src/whoami.c (main):
Don't assume that getuid and friends always succeed.
This fixes the same problem that we recently fixed with 'id'.
Diffstat (limited to 'src/su.c')
-rw-r--r-- | src/su.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -173,7 +173,10 @@ log_su (struct passwd const *pw, bool successful) { /* getlogin can fail -- usually due to lack of utmp entry. Resort to getpwuid. */ - struct passwd *pwd = getpwuid (getuid ()); + errno = 0; + uid_t ruid = getuid (); + uid_t NO_UID = -1; + struct passwd *pwd = (ruid == NO_UID && errno ? NULL : getpwuid (ruid)); old_user = (pwd ? pwd->pw_name : ""); } tty = ttyname (STDERR_FILENO); |