From 83ed6619479710d5979108f85b6bae648bb75061 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 8 Jul 2017 13:01:55 +0200 Subject: [PATCH] groups: do not exit early 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 | 4 ++++ src/groups.c | 11 +++++++---- tests/local.mk | 1 + tests/misc/groups-process-all.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100755 tests/misc/groups-process-all.sh diff --git a/NEWS b/NEWS index 35ba311971..110229bd8e 100644 --- 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] diff --git a/src/groups.c b/src/groups.c index 0a5c5be88c..ccfe8a2d53 100644 --- a/src/groups.c +++ b/src/groups.c @@ -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'); } diff --git a/tests/local.mk b/tests/local.mk index 235bcbe65d..8fc48c4892 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -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 index 0000000000..a352ecc10e --- /dev/null +++ b/tests/misc/groups-process-all.sh @@ -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 . + +. "${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 -- 2.47.2