bug-coreutils
[Top][All Lists]
Advanced

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

Re: Found and fixed bug in groups(1). Want the diff?


From: Paul Eggert
Subject: Re: Found and fixed bug in groups(1). Want the diff?
Date: Tue, 26 Sep 2006 10:20:05 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Those changes to groups.sh change its behavior to make it more
compatible with FreeBSD and Solaris.  The old behavior was:

  $ groups root
  root : root

and the new behavior is:

  $ groups root
  root

I think this change is a good one (as compatibility is good), but it
should be documented.

While we're in the neighborhood:

  * "groups" should print a diagnostic if there's a write error, rather
    than merely exiting with status 1.

  * groups should handle options like "--vers" and "--" compatibly
    with everyone else.

  * "id" should be invoked with "--" to protect user names beginning
    with "-".

Here's a proposed patch.  Normally I'd just install this, but you're
about to release a new version so I am holding off.

2006-09-26  Paul Eggert  <address@hidden>

        * NEWS: "groups user" no longer outputs "user :"; you need at least
        two users.  "groups" now processes options like --help more compatibly.
        * doc/coreutils.texi (groups invocation): "groups" no longer prefixes
        the output with "user :" unless more than one user is specified.
        * src/groups.sh: Implement the option-processing change.
        Handle user and group names with special characters more robustly.
        Report write errors instead of exiting silently with status 1.

Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.429
diff -p -u -r1.429 NEWS
--- NEWS        26 Sep 2006 09:28:18 -0000      1.429
+++ NEWS        26 Sep 2006 17:17:34 -0000
@@ -22,8 +22,14 @@ GNU coreutils NEWS                      
   With --verbose (-v), cp and mv would sometimes generate no output,
   or neglect to report file removal.
 
-  "groups user" now exits nonzero when it gets a write error.
+  For the "groups" command:
 
+    "groups" no longer prefixes the output with "user :" unless more
+    than one user is specified; this is for compatibility with BSD.
+
+    "groups user" now exits nonzero when it gets a write error.
+
+    "groups" now processes options like --help more compatibly.
 
 * Major changes in release 6.2 (2006-09-18) [stable candidate]
 
Index: doc/coreutils.texi
===================================================================
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.352
diff -p -u -r1.352 coreutils.texi
--- doc/coreutils.texi  19 Sep 2006 22:39:38 -0000      1.352
+++ doc/coreutils.texi  26 Sep 2006 17:17:36 -0000
@@ -11973,7 +11973,8 @@ options}.
 
 @command{groups} prints the names of the primary and any supplementary
 groups for each given @var{username}, or the current process if no names
-are given.  If names are given, the name of each user is printed before
+are given.  If more than one name is given, the name of each user is
+printed before
 the list of that user's groups.  Synopsis:
 
 @example
Index: src/groups.sh
===================================================================
RCS file: /fetish/cu/src/groups.sh,v
retrieving revision 1.21
diff -p -u -r1.21 groups.sh
--- src/groups.sh       26 Sep 2006 09:46:35 -0000      1.21
+++ src/groups.sh       26 Sep 2006 17:17:36 -0000
@@ -34,36 +34,49 @@ Report bugs to <@PACKAGE_BUGREPORT@>."
 version='groups (@GNU_PACKAGE@) @VERSION@
 Written by David MacKenzie.
 
-Copyright (C) 2004 Free Software Foundation, Inc.
+Copyright (C) 2006 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.'
 
 
-fail=0
-case $# in
-  1 )
-    case "z${1}" in
-      z--help )
-        echo "$usage" || fail=1; exit $fail;;
-      z--version )
-        echo "$version" || fail=1; exit $fail;;
-      * ) ;;
-    esac
-    ;;
-  * ) ;;
-esac
+for arg
+do
+  case $arg in
+    --help | --hel | --he | --h)
+      exec echo "$usage" ;;
+    --version | --versio | --versi | --vers | --ver | --ve | --v)
+      exec echo "$version" ;;
+    --)
+      shift
+      break ;;
+    -*)
+      echo "$0: invalid option: $arg" >&2
+      exit 1 ;;
+  esac
+done
 
 # With fewer than two arguments, simply exec "id".
 case $# in
-  0|1) exec id -Gn "$@" ;;
+  0|1) exec id -Gn -- "$@" ;;
 esac
 
 # With more, we need a loop, and be sure to exit nonzero upon failure.
-for name in "$@"; do
-  if groups=`id -Gn -- $name`; then
-    echo $name : $groups || fail=1
+status=0
+write_error=0
+
+for name
+do
+  if groups=`id -Gn -- "$name"`; then
+    echo "$name : $groups" || {
+      status=$?
+      if test $write_error = 0; then
+       echo "$0: write error" >&2
+       write_error=1
+      fi
+    }
   else
-    fail=1
+    status=$?
   fi
 done
-exit $fail
+
+exit $status




reply via email to

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