summaryrefslogtreecommitdiff
path: root/src/whoami.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-11-20 14:08:33 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2011-11-20 14:09:53 -0800
commit71b7ddcdd5c473f9eaf6035b96acc68c14cb379e (patch)
treea4d7544dc4ed5123a2ffaf40105fc8d0049ddf22 /src/whoami.c
parent8ffc159611db3443282aee42465afc8a1597519c (diff)
downloadcoreutils-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/whoami.c')
-rw-r--r--src/whoami.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/whoami.c b/src/whoami.c
index e563dcf20..1b0c3cdb6 100644
--- a/src/whoami.c
+++ b/src/whoami.c
@@ -61,6 +61,7 @@ main (int argc, char **argv)
{
struct passwd *pw;
uid_t uid;
+ uid_t NO_UID = -1;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -81,8 +82,9 @@ main (int argc, char **argv)
usage (EXIT_FAILURE);
}
+ errno = 0;
uid = geteuid ();
- pw = getpwuid (uid);
+ pw = (uid == NO_UID && errno ? NULL : getpwuid (uid));
if (pw)
{
puts (pw->pw_name);