summaryrefslogtreecommitdiff
path: root/src/groups.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/groups.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/groups.c')
-rw-r--r--src/groups.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/groups.c b/src/groups.c
index abb7bc7c7..279b83168 100644
--- a/src/groups.c
+++ b/src/groups.c
@@ -97,9 +97,23 @@ main (int argc, char **argv)
if (optind == argc)
{
/* No arguments. Divulge the details of the current process. */
+ uid_t NO_UID = -1;
+ gid_t NO_GID = -1;
+
+ errno = 0;
ruid = getuid ();
+ if (ruid == NO_UID && errno)
+ error (EXIT_FAILURE, errno, _("cannot get real UID"));
+
+ errno = 0;
egid = getegid ();
+ if (egid == NO_GID && errno)
+ error (EXIT_FAILURE, errno, _("cannot get effective GID"));
+
+ errno = 0;
rgid = getgid ();
+ if (rgid == NO_GID && errno)
+ error (EXIT_FAILURE, errno, _("cannot get real GID"));
if (!print_group_list (NULL, ruid, rgid, egid, true))
ok = false;