]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
groups: do not exit early
authorJim Meyering <meyering@fb.com>
Sat, 8 Jul 2017 11:01:55 +0000 (13:01 +0200)
committerJim Meyering <meyering@fb.com>
Mon, 10 Jul 2017 08:17:57 +0000 (10:17 +0200)
Most programs take care to operate on all command-line-specified
operands before exiting.  That is an important feature that allows
to identify all problems with the first run.  However, groups would
exit upon the first problematic user name.
Bug introduced via commit v6.10-56-g167b8025ac.
* src/groups.c (main): Do not exit immediately upon error.
* tests/misc/groups-process-all.sh: New file. Test for this.
* tests/local.mk (all_tests): Add it.
* NEWS (Bug fixes): Mention this.

NEWS
src/groups.c
tests/local.mk
tests/misc/groups-process-all.sh [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 35ba311971a663a8b96d1d2fdea3951d297f56f8..110229bd8e020e30ff7f290422efaa3883401ee4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   specifying -x nfs no longer hangs with problematic nfs mounts.
   [bug introduced in coreutils-8.21]
 
+  `groups inva:lid root` no longer exits immediately upon failure.
+  Now, it prints a diagnostic or a line to stdout for each argument.
+  [bug introduced in the bourne-shell-to-C rewrite for coreutils-6.11]
+
   split no longer exits when invocations of a --filter return EPIPE.
   [bug introduced in coreutils-8.26]
 
index 0a5c5be88c7cbb89e2b24603d2f143037d287479..ccfe8a2d5304a44e2eec6acc3ece12c434a78815 100644 (file)
@@ -122,17 +122,20 @@ main (int argc, char **argv)
   else
     {
       /* At least one argument.  Divulge the details of the specified users.  */
-      while (optind < argc)
+      for ( ; optind < argc; optind++)
         {
           struct passwd *pwd = getpwnam (argv[optind]);
           if (pwd == NULL)
-            die (EXIT_FAILURE, 0, _("%s: no such user"),
-                 quote (argv[optind]));
+            {
+              error (0, 0, _("%s: no such user"), quote (argv[optind]));
+              ok = false;
+              continue;
+            }
           ruid = pwd->pw_uid;
           rgid = egid = pwd->pw_gid;
 
           printf ("%s : ", argv[optind]);
-          if (!print_group_list (argv[optind++], ruid, rgid, egid, true, ' '))
+          if (!print_group_list (argv[optind], ruid, rgid, egid, true, ' '))
             ok = false;
           putchar ('\n');
         }
index 235bcbe65d4069e34864e67fa848ce6158d46e52..8fc48c48928dced12c510cc3e4d958c873685bb1 100644 (file)
@@ -296,6 +296,7 @@ all_tests =                                 \
   tests/misc/false-status.sh                   \
   tests/misc/fold.pl                           \
   tests/misc/groups-dash.sh                    \
+  tests/misc/groups-process-all.sh             \
   tests/misc/groups-version.sh                 \
   tests/misc/head-c.sh                         \
   tests/misc/head-pos.sh                       \
diff --git a/tests/misc/groups-process-all.sh b/tests/misc/groups-process-all.sh
new file mode 100755 (executable)
index 0000000..a352ecc
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Ensure groups processes all arguments before exiting.
+# With coreutils-2.27 and prior, it would exit upon first failure.
+
+# Copyright (C) 2017 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ groups
+
+returns_ 1 groups :1 :2 :3 2> err || fail=1
+test $(wc -l < err) = 3 || fail=1
+
+Exit $fail