coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] doc: update for ISO/IEC 80000-13


From: Paul Eggert
Subject: [PATCH] doc: update for ISO/IEC 80000-13
Date: Tue, 15 Nov 2011 08:28:35 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0) Gecko/20110927 Thunderbird/7.0

I checked in the following, intending only to update the
documentation for SI prefixes etc., but now I see that by mistake
I also committed the patch to id.c that was still under discussion.
Sorry about that.  If you would like me to undo the change to src/id.c
please let me know -- I am tempted to do it now but am holding back
because I don't want to cause *further* confusion....

* doc/coreutils.texi (Block size): IEC 60027-2 has been superseded
by ISO/IEC 80000-13, so prefer the newer standard but also mention
the old.  The new standard specifies Zi and Yi, so they are no
longer GNU extensions.  Fix stale URL to BIPM.

2011-11-14  Paul Eggert  <address@hidden>

id: handle (uid_t) -1 more portably
* src/id.c (GETID_MAY_FAIL): Remove.
(main): Check for negative return values, not for -1.
The old code was incorrect if uid_t was narrower than int,
regardless of whether we were on a GNU or a POSIX platform.
The new code is simpler and doesn't need GETID_MAY_FAIL.
(print_full_info): Remove unnecessary cast to -1.
---
 doc/coreutils.texi |   10 ++++------
 src/id.c           |   31 +++++++++++++++++++------------
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 4531440..fa82a31 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -901,10 +901,10 @@ A block size specification can be a positive integer 
specifying the number
 of bytes per block, or it can be @code{human-readable} or @code{si} to
 select a human-readable format.  Integers may be followed by suffixes
 that are upward compatible with the
address@hidden://www.bipm.fr/enus/3_SI/si-prefixes.html, SI prefixes}
address@hidden://www.bipm.org/en/si/si_brochure/chapter3/prefixes.html, SI 
prefixes}
 for decimal multiples and with the
address@hidden://physics.nist.gov/cuu/Units/binary.html, IEC 60027-2
-prefixes for binary multiples}.
address@hidden://physics.nist.gov/cuu/Units/binary.html, ISO/IEC 80000-13
+(formerly IEC 60027-2) prefixes} for binary multiples.
 
 With human-readable formats, output sizes are followed by a size letter
 such as @samp{M} for megabytes.  @code{BLOCK_SIZE=human-readable} uses
@@ -946,7 +946,7 @@ kilobyte: @math{10^3 = 1000}.
 @itemx KiB
 @cindex kibibyte, definition of
 kibibyte: @math{2^{10} = 1024}.  @samp{K} is special: the SI prefix is
address@hidden and the IEC 60027-2 prefix is @samp{Ki}, but tradition and
address@hidden and the ISO/IEC 80000-13 prefix is @samp{Ki}, but tradition and
 @acronym{POSIX} use @samp{k} to mean @samp{KiB}.
 @item MB
 @cindex megabyte, definition of
@@ -989,14 +989,12 @@ zettabyte: @math{10^{21} = 1,000,000,000,000,000,000,000}
 @item Z
 @itemx ZiB
 @math{2^{70} = 1,180,591,620,717,411,303,424}.
-(@samp{Zi} is a @acronym{GNU} extension to IEC 60027-2.)
 @item YB
 @cindex yottabyte, definition of
 yottabyte: @math{10^{24} = 1,000,000,000,000,000,000,000,000}.
 @item Y
 @itemx YiB
 @math{2^{80} = 1,208,925,819,614,629,174,706,176}.
-(@samp{Yi} is a @acronym{GNU} extension to IEC 60027-2.)
 @end table
 
 @opindex -k
diff --git a/src/id.c b/src/id.c
index 047e40b..b3ee437 100644
--- a/src/id.c
+++ b/src/id.c
@@ -38,13 +38,6 @@
   proper_name ("Arnold Robbins"), \
   proper_name ("David MacKenzie")
 
-/* Whether the functions getuid, geteuid, getgid and getegid may fail.  */
-#ifdef __GNU__
-# define GETID_MAY_FAIL 1
-#else
-# define GETID_MAY_FAIL 0
-#endif
-
 /* If nonzero, output only the SELinux context. -Z */
 static int just_context = 0;
 
@@ -208,22 +201,36 @@ main (int argc, char **argv)
     }
   else
     {
+      /* On GNU/Hurd hosts, getuid etc. can fail and return -1.
+         However, on GNU/Linux hosts, uid_t is an unsigned value and
+         getuid etc. can return the positive value (uid_t) -1.  To
+         handle both cases correctly, consider getuid etc. to fail if
+         it returns a negative value (a value that is impossible on
+         GNU/Linux hosts).
+
+         GNU/Linux sysadmins should not give users the UID (uid_t) -1
+         even though uid_t is unsigned, as system calls like chown would
+         not have the desired behavior with such a UID, and other
+         coreutils applications therefore do not support such a UID.
+         However, 'id' makes a special attempt to handle this UID, to
+         help people diagnose the problem.  */
+
       euid = geteuid ();
-      if (GETID_MAY_FAIL && euid == -1 && !use_real
+      if (euid < 0 && !use_real
           && !just_group && !just_group_list && !just_context)
         error (EXIT_FAILURE, errno, _("cannot get effective UID"));
 
       ruid = getuid ();
-      if (GETID_MAY_FAIL && ruid == -1 && use_real
+      if (ruid < 0 && use_real
           && !just_group && !just_group_list && !just_context)
         error (EXIT_FAILURE, errno, _("cannot get real UID"));
 
       egid = getegid ();
-      if (GETID_MAY_FAIL && egid == -1 && !use_real && !just_user)
+      if (egid < 0 && !use_real && !just_user)
         error (EXIT_FAILURE, errno, _("cannot get effective GID"));
 
       rgid = getgid ();
-      if (GETID_MAY_FAIL && rgid == -1 && use_real && !just_user)
+      if (rgid < 0 && use_real && !just_user)
         error (EXIT_FAILURE, errno, _("cannot get real GID"));
     }
 
@@ -316,7 +323,7 @@ print_full_info (const char *username)
     gid_t *groups;
     int i;
 
-    int n_groups = xgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
+    int n_groups = xgetgroups (username, (pwd ? pwd->pw_gid : -1),
                                &groups);
     if (n_groups < 0)
       {
-- 
1.7.6.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]