-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Jim Meyering on 10/23/2009 7:48 AM: >> So, how about this patch series? (I guess I should check whether this >> change causes any testsuite failures, and if not, add some tests.)
Yes, there were some test failures that I had to fix. Even some unrelated failures (invalid-opt failed on cygwin 1.7, now that getopt-gnu allows cygwin's getopt rather than forcing gnulib's replacement). There was also some missing test coverage. > > Both look fine. > Adding tests would make them perfect ;-) Here's what I pushed (including the addition of two FIXMEs in tests/misc/env, waiting for us to decide what to do there): - -- Don't work too hard, make some time for fun as well! Eric Blake e...@byu.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkriMBoACgkQ84KuGfSFAYAH/gCdF71PNloIMwM64s+gurm92OVG 8BUAoIdwFBqTCzSBipnOebYmtpDYl/95 =m2x8 -----END PGP SIGNATURE-----
>From 97777f559a80a0de11429402f7dba186eabf5bcd Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Fri, 23 Oct 2009 15:35:41 -0600 Subject: [PATCH 1/6] tests: accommodate BSD getopt * tests/misc/invalid-opt (err_subst): Support alternate spelling. --- tests/misc/invalid-opt | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/tests/misc/invalid-opt b/tests/misc/invalid-opt index d251cb8..23142bb 100755 --- a/tests/misc/invalid-opt +++ b/tests/misc/invalid-opt @@ -76,7 +76,8 @@ foreach my $prog (@built_programs) # Accommodate different syntax in glibc's getopt # diagnostics by filtering out single quotes. - my $err_subst = "s,'/',/,"; + # Also accommodate BSD getopt. + my $err_subst = "s,'/',/,; s,unknown,invalid,"; # Depending on how this script is run, stty emits different # diagnostics. Don't bother checking them. -- 1.6.5.rc1 >From b6540b96ba6510af7b2acc6e81bd9d9583f7c96b Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Fri, 23 Oct 2009 06:59:02 -0600 Subject: [PATCH 2/6] chroot, env, nice, su: use EXIT_CANCELED for internal failure * src/chroot.c (main): Use EXIT_CANCELED, not EXIT_FAILURE. * src/env.c (main): Likewise. * src/nice.c (main): Likewise. * src/su.c (change_identity, main): Likewise. * doc/coreutils.texi (chroot invocation, env invocation) (nice invocation, su invocation): Document this. * NEWS: Likewise. * tests/misc/invalid-opt (exit_status): Adjust expected results. * tests/misc/help-version (expected_failure_status): Likewise. --- NEWS | 7 +++++++ doc/coreutils.texi | 8 ++++---- src/chroot.c | 14 +++++++------- src/env.c | 4 ++-- src/nice.c | 14 +++++++------- src/su.c | 14 +++++++------- tests/misc/help-version | 4 ++++ tests/misc/invalid-opt | 4 ++++ 8 files changed, 42 insertions(+), 27 deletions(-) diff --git a/NEWS b/NEWS index 7057d87..f359133 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,13 @@ GNU coreutils NEWS -*- outline -*- were first renamed or unlinked or never modified. [The race was introduced in coreutils-7.5] +** Changes in behavior + + chroot, env, nice, and su fail with status 125, rather than 1, on + internal error such as failure to parse command line arguments; this + is for consistency with stdbuf and timeout, and avoids ambiguity + with the invoked command failing with status 1. + ** New features md5sum --check now also accepts openssl-style checksums. diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 64e0e95..31c3d5c 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -14363,7 +14363,7 @@ chroot invocation Exit status: @display -1 if @command{chroot} itself fails +125 if @command{chroot} itself fails 126 if @var{command} is found but cannot be invoked 127 if @var{command} cannot be found the exit status of @var{command} otherwise @@ -14441,7 +14441,7 @@ env invocation @display 0 if no @var{command} is specified and the environment is output -1 if @command{env} itself fails +125 if @command{env} itself fails 126 if @var{command} is found but cannot be invoked 127 if @var{command} cannot be found the exit status of @var{command} otherwise @@ -14516,7 +14516,7 @@ nice invocation @display 0 if no @var{command} is specified and the niceness is output -1 if @command{nice} itself fails +125 if @command{nice} itself fails 126 if @var{command} is found but cannot be invoked 127 if @var{command} cannot be found the exit status of @var{command} otherwise @@ -14843,7 +14843,7 @@ su invocation Exit status: @display -1 if @command{su} itself fails +125 if @command{su} itself fails 126 if subshell is found but cannot be invoked 127 if subshell cannot be found the exit status of the subshell otherwise diff --git a/src/chroot.c b/src/chroot.c index 9269f1b..e4765ba 100644 --- a/src/chroot.c +++ b/src/chroot.c @@ -160,7 +160,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - initialize_exit_failure (EXIT_FAILURE); + initialize_exit_failure (EXIT_CANCELED); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, @@ -177,22 +177,22 @@ main (int argc, char **argv) groups = optarg; break; default: - usage (EXIT_FAILURE); + usage (EXIT_CANCELED); } } if (argc <= optind) { error (0, 0, _("missing operand")); - usage (EXIT_FAILURE); + usage (EXIT_CANCELED); } if (chroot (argv[optind]) != 0) - error (EXIT_FAILURE, errno, _("cannot change root directory to %s"), + error (EXIT_CANCELED, errno, _("cannot change root directory to %s"), argv[optind]); if (chdir ("/")) - error (EXIT_FAILURE, errno, _("cannot chdir to root directory")); + error (EXIT_CANCELED, errno, _("cannot chdir to root directory")); if (argc == optind + 1) { @@ -223,7 +223,7 @@ main (int argc, char **argv) char const *err = parse_user_spec (userspec, &uid, &gid, &user, &group); if (err) - error (EXIT_FAILURE, errno, "%s", err); + error (EXIT_CANCELED, errno, "%s", err); free (user); free (group); @@ -254,7 +254,7 @@ main (int argc, char **argv) } if (fail) - exit (EXIT_FAILURE); + exit (EXIT_CANCELED); /* Execute the given command. */ execvp (argv[0], argv); diff --git a/src/env.c b/src/env.c index 90edc5a..b69a29a 100644 --- a/src/env.c +++ b/src/env.c @@ -142,7 +142,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - initialize_exit_failure (EXIT_FAILURE); + initialize_exit_failure (EXIT_CANCELED); atexit (close_stdout); while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1) @@ -157,7 +157,7 @@ main (int argc, char **argv) case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); default: - usage (EXIT_FAILURE); + usage (EXIT_CANCELED); } } diff --git a/src/nice.c b/src/nice.c index 6cd5f31..b04f675 100644 --- a/src/nice.c +++ b/src/nice.c @@ -101,7 +101,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - initialize_exit_failure (EXIT_FAILURE); + initialize_exit_failure (EXIT_CANCELED); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, @@ -132,7 +132,7 @@ main (int argc, char **argv) i += optind - 1; if (optc == '?') - usage (EXIT_FAILURE); + usage (EXIT_CANCELED); else if (optc == 'n') adjustment_given = optarg; else /* optc == -1 */ @@ -148,7 +148,7 @@ main (int argc, char **argv) enum { MIN_ADJUSTMENT = 1 - 2 * NZERO, MAX_ADJUSTMENT = 2 * NZERO - 1 }; long int tmp; if (LONGINT_OVERFLOW < xstrtol (adjustment_given, NULL, 10, &tmp, "")) - error (EXIT_FAILURE, 0, _("invalid adjustment %s"), + error (EXIT_CANCELED, 0, _("invalid adjustment %s"), quote (adjustment_given)); adjustment = MAX (MIN_ADJUSTMENT, MIN (tmp, MAX_ADJUSTMENT)); } @@ -158,13 +158,13 @@ main (int argc, char **argv) if (adjustment_given) { error (0, 0, _("a command must be given with an adjustment")); - usage (EXIT_FAILURE); + usage (EXIT_CANCELED); } /* No command given; print the niceness. */ errno = 0; current_niceness = GET_NICENESS (); if (current_niceness == -1 && errno != 0) - error (EXIT_FAILURE, errno, _("cannot get niceness")); + error (EXIT_CANCELED, errno, _("cannot get niceness")); printf ("%d\n", current_niceness); exit (EXIT_SUCCESS); } @@ -175,11 +175,11 @@ main (int argc, char **argv) #else current_niceness = GET_NICENESS (); if (current_niceness == -1 && errno != 0) - error (EXIT_FAILURE, errno, _("cannot get niceness")); + error (EXIT_CANCELED, errno, _("cannot get niceness")); ok = (setpriority (PRIO_PROCESS, 0, current_niceness + adjustment) == 0); #endif if (!ok) - error (errno == EPERM ? 0 : EXIT_FAILURE, errno, _("cannot set niceness")); + error (errno == EPERM ? 0 : EXIT_CANCELED, errno, _("cannot set niceness")); execvp (argv[i], &argv[i]); diff --git a/src/su.c b/src/su.c index 25b8838..0de67c9 100644 --- a/src/su.c +++ b/src/su.c @@ -286,13 +286,13 @@ change_identity (const struct passwd *pw) #ifdef HAVE_INITGROUPS errno = 0; if (initgroups (pw->pw_name, pw->pw_gid) == -1) - error (EXIT_FAILURE, errno, _("cannot set groups")); + error (EXIT_CANCELED, errno, _("cannot set groups")); endgrent (); #endif if (setgid (pw->pw_gid)) - error (EXIT_FAILURE, errno, _("cannot set group id")); + error (EXIT_CANCELED, errno, _("cannot set group id")); if (setuid (pw->pw_uid)) - error (EXIT_FAILURE, errno, _("cannot set user id")); + error (EXIT_CANCELED, errno, _("cannot set user id")); } /* Run SHELL, or DEFAULT_SHELL if SHELL is empty. @@ -406,7 +406,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - initialize_exit_failure (EXIT_FAILURE); + initialize_exit_failure (EXIT_CANCELED); atexit (close_stdout); fast_startup = false; @@ -443,7 +443,7 @@ main (int argc, char **argv) case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); default: - usage (EXIT_FAILURE); + usage (EXIT_CANCELED); } } @@ -458,7 +458,7 @@ main (int argc, char **argv) pw = getpwnam (new_user); if (! (pw && pw->pw_name && pw->pw_name[0] && pw->pw_dir && pw->pw_dir[0] && pw->pw_passwd)) - error (EXIT_FAILURE, 0, _("user %s does not exist"), new_user); + error (EXIT_CANCELED, 0, _("user %s does not exist"), new_user); /* Make a copy of the password information and point pw at the local copy instead. Otherwise, some systems (e.g. GNU/Linux) would clobber @@ -481,7 +481,7 @@ main (int argc, char **argv) #ifdef SYSLOG_FAILURE log_su (pw, false); #endif - error (EXIT_FAILURE, 0, _("incorrect password")); + error (EXIT_CANCELED, 0, _("incorrect password")); } #ifdef SYSLOG_SUCCESS else diff --git a/tests/misc/help-version b/tests/misc/help-version index 9afe8af..57cc1e7 100755 --- a/tests/misc/help-version +++ b/tests/misc/help-version @@ -27,8 +27,12 @@ export SHELL . $srcdir/test-lib.sh +expected_failure_status_chroot=125 +expected_failure_status_env=125 +expected_failure_status_nice=125 expected_failure_status_nohup=127 expected_failure_status_stdbuf=125 +expected_failure_status_su=125 expected_failure_status_timeout=125 expected_failure_status_printenv=2 expected_failure_status_tty=3 diff --git a/tests/misc/invalid-opt b/tests/misc/invalid-opt index 23142bb..155ac6e 100755 --- a/tests/misc/invalid-opt +++ b/tests/misc/invalid-opt @@ -28,11 +28,15 @@ my %exit_status = dir => 2, vdir => 2, test => 2, + chroot => 125, echo => 0, + env => 125, expr => 0, + nice => 125, nohup => 127, sort => 2, stdbuf => 125, + su => 125, test => 0, timeout => 125, true => 0, -- 1.6.5.rc1 >From 1ce9e1e5ca1e7491bccedeeced15470d856c9a22 Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Fri, 23 Oct 2009 06:59:23 -0600 Subject: [PATCH 3/6] nohup: use EXIT_CANCELED if not POSIXLY_CORRECT * src/nohup.c (NOHUP_FAILURE): Rename... (POSIX_NOHUP_FAILURE): ...to this. (main): Pay attention to POSIXLY_CORRECT, to determine whether to use status 125 or 127. * doc/coreutils.texi (nohup invocation): Document this. * NEWS: Likewise. * tests/misc/invalid-opt (exit_status): Adjust expected results. * tests/misc/help-version (expected_failure_status): Likewise. * tests/misc/nohup: Likewise. --- NEWS | 3 ++- doc/coreutils.texi | 6 +++++- src/nohup.c | 22 +++++++++++++++------- tests/misc/help-version | 2 +- tests/misc/invalid-opt | 2 +- tests/misc/nohup | 5 ++++- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index f359133..1ed577f 100644 --- a/NEWS +++ b/NEWS @@ -29,7 +29,8 @@ GNU coreutils NEWS -*- outline -*- chroot, env, nice, and su fail with status 125, rather than 1, on internal error such as failure to parse command line arguments; this is for consistency with stdbuf and timeout, and avoids ambiguity - with the invoked command failing with status 1. + with the invoked command failing with status 1. Likewise, nohup + fails with status 125 instead of 127. ** New features diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 31c3d5c..c54ffb8 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -14634,11 +14634,15 @@ nohup invocation Exit status: @display +125 if @command{nohup} itself fails, and @env{POSIXLY_CORRECT} is not set 126 if @var{command} is found but cannot be invoked -127 if @command{nohup} itself fails or if @var{command} cannot be found +127 if @var{command} cannot be found the exit status of @var{command} otherwise @end display +If @env{POSIXLY_CORRECT} is set, internal failures give status 127 +instead of 125. + @node stdbuf invocation @section @command{stdbuf}: Run a command with modified I/O stream buffering diff --git a/src/nohup.c b/src/nohup.c index 99bb865..880cc74 100644 --- a/src/nohup.c +++ b/src/nohup.c @@ -40,7 +40,7 @@ enum { /* `nohup' itself failed. */ - NOHUP_FAILURE = 127 + POSIX_NOHUP_FAILURE = 127 }; void @@ -85,6 +85,7 @@ main (int argc, char **argv) bool redirecting_stdout; bool stdout_is_closed; bool redirecting_stderr; + int exit_internal_failure; initialize_main (&argc, &argv); set_program_name (argv[0]); @@ -92,18 +93,24 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - initialize_exit_failure (NOHUP_FAILURE); + /* POSIX 2008 requires that internal failure give status 127; unlike + for env, exec, nice, time, and xargs where it requires internal + failure give something in the range 1-125. For consistency with + other tools, fail with EXIT_CANCELED unless POSIXLY_CORRECT. */ + exit_internal_failure = (getenv ("POSIXLY_CORRECT") + ? POSIX_NOHUP_FAILURE : EXIT_CANCELED); + initialize_exit_failure (exit_internal_failure); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "+", NULL, NULL) != -1) - usage (NOHUP_FAILURE); + usage (exit_internal_failure); if (argc <= optind) { error (0, 0, _("missing operand")); - usage (NOHUP_FAILURE); + usage (exit_internal_failure); } ignoring_input = isatty (STDIN_FILENO); @@ -154,7 +161,7 @@ main (int argc, char **argv) if (in_home) error (0, saved_errno2, _("failed to open %s"), quote (in_home)); - exit (NOHUP_FAILURE); + exit (exit_internal_failure); } file = in_home; } @@ -179,7 +186,7 @@ main (int argc, char **argv) if (0 <= saved_stderr_fd && set_cloexec_flag (saved_stderr_fd, true) != 0) - error (NOHUP_FAILURE, errno, + error (exit_internal_failure, errno, _("failed to set the copy of stderr to close on exec")); if (!redirecting_stdout) @@ -189,7 +196,8 @@ main (int argc, char **argv) : N_("redirecting stderr to stdout"))); if (dup2 (out_fd, STDERR_FILENO) < 0) - error (NOHUP_FAILURE, errno, _("failed to redirect standard error")); + error (exit_internal_failure, errno, + _("failed to redirect standard error")); if (stdout_is_closed) close (out_fd); diff --git a/tests/misc/help-version b/tests/misc/help-version index 57cc1e7..da55907 100755 --- a/tests/misc/help-version +++ b/tests/misc/help-version @@ -30,7 +30,7 @@ export SHELL expected_failure_status_chroot=125 expected_failure_status_env=125 expected_failure_status_nice=125 -expected_failure_status_nohup=127 +expected_failure_status_nohup=125 expected_failure_status_stdbuf=125 expected_failure_status_su=125 expected_failure_status_timeout=125 diff --git a/tests/misc/invalid-opt b/tests/misc/invalid-opt index 155ac6e..2e5c099 100755 --- a/tests/misc/invalid-opt +++ b/tests/misc/invalid-opt @@ -33,7 +33,7 @@ my %exit_status = env => 125, expr => 0, nice => 125, - nohup => 127, + nohup => 125, sort => 2, stdbuf => 125, su => 125, diff --git a/tests/misc/nohup b/tests/misc/nohup index 25a7ca4..ad04a1c 100755 --- a/tests/misc/nohup +++ b/tests/misc/nohup @@ -101,8 +101,11 @@ EOF # Disable these comparisons. Too much variation in 2nd line. # compare exp err || fail=1 -# Make sure it fails with exit status of 127 when given too few arguments. +# Make sure it fails with exit status of 125 when given too few arguments, +# except that POSIX requires 127 in this case. nohup >/dev/null 2>&1 +test $? = 125 || fail=1 +POSIXLY_CORRECT=1 nohup >/dev/null 2>&1 test $? = 127 || fail=1 Exit $fail -- 1.6.5.rc1 >From bd933c125073bf5b071d8ea0631de8aac3a8c3e9 Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Fri, 23 Oct 2009 08:54:53 -0600 Subject: [PATCH 4/6] tests: enhance stdbuf and timeout tests * tests/misc/timeout-parameters: Validate exact exit status. * tests/misc/stdbuf: Likewise. * tests/misc/timeout: Likewise. Use require_built_. * tests/misc/arch: Likewise. --- tests/misc/arch | 7 +------ tests/misc/stdbuf | 26 ++++++++++++++------------ tests/misc/timeout | 2 ++ tests/misc/timeout-parameters | 28 +++++++++++++++++++--------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/tests/misc/arch b/tests/misc/arch index 9a43756..04bce0e 100755 --- a/tests/misc/arch +++ b/tests/misc/arch @@ -17,12 +17,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . $srcdir/test-lib.sh - -# skip this test if arch isn't being built. -case " $built_programs " in - *" arch "*) ;; - *) skip_test_ 'not building arch';; -esac +require_built_ arch if test "$VERBOSE" = yes; then set -x diff --git a/tests/misc/stdbuf b/tests/misc/stdbuf index 3375040..33bc658 100755 --- a/tests/misc/stdbuf +++ b/tests/misc/stdbuf @@ -16,20 +16,15 @@ # 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/test-lib.sh +getlimits_ +require_built_ stdbuf + if test "$VERBOSE" = yes; then set -x stdbuf --version fi -. $srcdir/test-lib.sh -getlimits_ - -# skip this test if stdbuf isn't being built. -case " $built_programs " in - *" stdbuf "*) ;; - *) skip_test_ 'stdbuf not built';; -esac - # stdbuf fails when the absolute top build dir name contains e.g., space, TAB, NL lf=' ' @@ -52,10 +47,17 @@ stdbuf -o1 true || fail=1 # verify size syntax stdbuf -oK true || fail=1 # verify size syntax stdbuf -o0 true || fail=1 # verify unbuffered syntax stdbuf -oL true || fail=1 # verify line buffered syntax -stdbuf -ol true && fail=1 # Capital 'L' required -stdbuf -o$SIZE_OFLOW true && fail=1 # size too large -stdbuf -iL true && fail=1 # line buffering stdin disallowed +stdbuf -ol true # Capital 'L' required +test $? = 125 || fail=1 # Internal error is a particular status +stdbuf -o$SIZE_OFLOW true # size too large +test $? = 125 || fail=1 +stdbuf -iL true # line buffering stdin disallowed +test $? = 125 || fail=1 stdbuf -i0 -o0 -e0 true || fail=1 #check all files +stdbuf -o1 . # invalid command +test $? = 126 || fail=1 +stdbuf -o1 ... # no such command +test $? = 127 || fail=1 # Ensure line buffering stdout takes effect printf '1\n' > exp diff --git a/tests/misc/timeout b/tests/misc/timeout index 36fdb73..08734e6 100755 --- a/tests/misc/timeout +++ b/tests/misc/timeout @@ -36,6 +36,8 @@ timeout 0 true || fail=1 # exit status propagation timeout 1 false && fail=1 +timeout 1 sh -c 'exit 2' +test $? = 2 || fail=1 # timeout timeout 1 sleep 2 diff --git a/tests/misc/timeout-parameters b/tests/misc/timeout-parameters index cf344b9..52d4c8a 100755 --- a/tests/misc/timeout-parameters +++ b/tests/misc/timeout-parameters @@ -26,28 +26,38 @@ getlimits_ fail=0 +# internal errors are 125, distinct from execution failure + # --help and --version must be specified alone -timeout --help --version && fail=1 +timeout --help --version +test $? = 125 || fail=1 # invalid timeout -timeout invalid sleep 0 && fail=1 +timeout invalid sleep 0 +test $? = 125 || fail=1 # invalid timeout suffix -timeout 42D sleep 0 && fail=1 +timeout 42D sleep 0 +test $? = 125 || fail=1 # timeout overflow -timeout $UINT_OFLOW sleep 0 && fail=1 +timeout $UINT_OFLOW sleep 0 +test $? = 125 || fail=1 # timeout overflow -timeout $(expr $UINT_MAX / 86400 + 1)d sleep 0 && fail=1 +timeout $(expr $UINT_MAX / 86400 + 1)d sleep 0 +test $? = 125 || fail=1 # invalid signal spec -timeout --signal=invalid 1 sleep 0 && fail=1 +timeout --signal=invalid 1 sleep 0 +test $? = 125 || fail=1 # invalid command -timeout 1 . && fail=1 +timeout 1 . +test $? = 126 || fail=1 -# non existant command -timeout 1 ... && fail=1 +# no such command +timeout 1 ... +test $? = 127 || fail=1 Exit $fail -- 1.6.5.rc1 >From 2122247acae6672e2dcfba095dc84cf84bc8ef41 Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Fri, 23 Oct 2009 08:12:29 -0600 Subject: [PATCH 5/6] maint: move chroot test * tests/chroot/credentials: Move... * tests/misc/chroot-credentials: ...here, to reduce number of directories. * tests/Makefile.am (root_tests): Reflect rename. --- tests/Makefile.am | 2 +- .../credentials => misc/chroot-credentials} | 0 2 files changed, 1 insertions(+), 1 deletions(-) rename tests/{chroot/credentials => misc/chroot-credentials} (100%) diff --git a/tests/Makefile.am b/tests/Makefile.am index ae17e9f..be92fba 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,12 +24,12 @@ root_tests = \ cp/preserve-gid \ cp/special-bits \ cp/cp-mv-enotsup-xattr \ - chroot/credentials \ dd/skip-seek-past-dev \ install/install-C-root \ ls/capability \ ls/nameless-uid \ misc/chcon \ + misc/chroot-credentials \ misc/selinux \ misc/truncate-owned-by-other \ mkdir/writable-under-readonly \ diff --git a/tests/chroot/credentials b/tests/misc/chroot-credentials similarity index 100% rename from tests/chroot/credentials rename to tests/misc/chroot-credentials -- 1.6.5.rc1 >From 30e4b6e84b7e478121a645515ce891d29cc75105 Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Fri, 23 Oct 2009 11:01:25 -0600 Subject: [PATCH 6/6] tests: test recent status changes * tests/misc/nice: Enhance test. * tests/misc/chroot-fail: New test. * tests/misc/env: Likewise. * tests/misc/nice-fail: Likewise. * tests/misc/su-fail: Likewise. * tests/Makefile.am (TESTS): Run new tests. --- tests/Makefile.am | 6 ++- tests/misc/chroot-fail | 50 +++++++++++++++++++++ tests/misc/env | 116 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/misc/nice | 22 +++++++--- tests/misc/nice-fail | 45 ++++++++++++++++++ tests/misc/su-fail | 33 ++++++++++++++ 6 files changed, 265 insertions(+), 7 deletions(-) create mode 100755 tests/misc/chroot-fail create mode 100755 tests/misc/env create mode 100755 tests/misc/nice-fail create mode 100755 tests/misc/su-fail diff --git a/tests/Makefile.am b/tests/Makefile.am index be92fba..03fe6f1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -74,7 +74,7 @@ EXTRA_DIST += $(TESTS) TESTS = \ misc/help-version \ - tail-2/inotify-race \ + tail-2/inotify-race \ misc/invalid-opt \ rm/ext3-perf \ rm/cycle \ @@ -126,6 +126,7 @@ TESTS = \ chgrp/no-x \ chgrp/posix-H \ chgrp/recurse \ + misc/env \ misc/ptx \ misc/test \ misc/seq \ @@ -158,6 +159,7 @@ TESTS = \ misc/base64 \ misc/basename \ misc/close-stdout \ + misc/chroot-fail \ misc/comm \ misc/csplit \ misc/date-sec \ @@ -182,6 +184,7 @@ TESTS = \ misc/md5sum-parallel \ misc/mknod \ misc/nice \ + misc/nice-fail \ misc/nl \ misc/nohup \ misc/od-N \ @@ -225,6 +228,7 @@ TESTS = \ misc/stty \ misc/stty-invalid \ misc/stty-row-col \ + misc/su-fail \ misc/sum \ misc/sum-sysv \ misc/tac \ diff --git a/tests/misc/chroot-fail b/tests/misc/chroot-fail new file mode 100755 index 0000000..5b58293 --- /dev/null +++ b/tests/misc/chroot-fail @@ -0,0 +1,50 @@ +#!/bin/sh +# Verify that internal failure in chroot gives exact status. + +# Copyright (C) 2009 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/>. + + +if test "$VERBOSE" = yes; then + set -x + chroot --version +fi + +. $srcdir/test-lib.sh + +fail=0 + +# These tests verify exact status of internal failure; since none of +# them actually run a command, we don't need root privileges +chroot # missing argument +test $? = 125 || fail=1 +chroot --help --version # too many options +test $? = 125 || fail=1 +chroot --- / true # unknown option +test $? = 125 || fail=1 + +# chroot("/") succeeds for non-root users on some systems, but not all. +if chroot / true ; then + chroot / sh -c 'exit 2' # exit status propagation + test $? = 2 || fail=1 + chroot / . # invalid command + test $? = 126 || fail=1 + chroot / ... # no such command + test $? = 127 || fail=1 +else + test $? = 125 || fail=1 +fi + +Exit $fail diff --git a/tests/misc/env b/tests/misc/env new file mode 100755 index 0000000..a3d435b --- /dev/null +++ b/tests/misc/env @@ -0,0 +1,116 @@ +#!/bin/sh +# Verify behavior of env. + +# Copyright (C) 2009 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/>. + + +if test "$VERBOSE" = yes; then + set -x + env --version +fi + +. $srcdir/test-lib.sh + +fail=0 + +# Verify clearing the environment +a=1 +export a +env - > out || fail=1 +test -s out && fail=1 +env -i > out || fail=1 +test -s out && fail=1 +env -u a -i -u a -- > out || fail=1 +test -s out && fail=1 +env -i -- a=b > out || fail=1 +echo a=b > exp || framework_failure +compare exp out || fail=1 + +# These tests verify exact status of internal failure. +env --- # unknown option +test $? = 125 || fail=1 +env -u # missing option argument +test $? = 125 || fail=1 +env sh -c 'exit 2' # exit status propagation +test $? = 2 || fail=2 +env . # invalid command +test $? = 126 || fail=1 +env ... # no such command +test $? = 127 || fail=1 + +# Cygwin requires a minimal environment to launch new processes, so a +# subsequent env will show more than just what we set. Hence, it is +# more portable to grep that our desired changes took place. +if env | grep '^ENV_TEST' >/dev/null ; then + skip_test_ "environment has potential interference from ENV_TEST*" +fi + +ENV_TEST1=a +export ENV_TEST1 +: >out || framework_failure +env ENV_TEST2= > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure +env -u ENV_TEST1 ENV_TEST3=c > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure +env ENV_TEST1=b > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure +env ENV_TEST2= env > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure +env -u ENV_TEST1 ENV_TEST3=c env > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure +env ENV_TEST1=b env > all || fail=1 +grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure +cat <<EOF >exp || framework_failure +ENV_TEST1=a +ENV_TEST2= +ENV_TEST3=c +ENV_TEST1=b +ENV_TEST1=a +ENV_TEST2= +ENV_TEST3=c +ENV_TEST1=b +EOF +compare exp out || fail=1 + +# Use -- to end arguments. +cat <<EOF >./-i || framework_failure +#!/bin/sh +echo pass +EOF +chmod +x ./-i || framework_failure +case `env -i PATH="$PATH" echo good` in + good) ;; + *) fail=1 ;; +esac +case `env -- -i PATH="$PATH" echo fail` in + pass) ;; + *) fail=1 ;; +esac + +# FIXME - POSIX does not allow this; decide what we want to do +# cat <<EOF >./c=d || framework_failure +# #!/bin/sh +# echo pass +# EOF +# chmod +x c=d || framework_failure +# test "x`env c=d echo fail`" = xfail || fail=1 +# test "x`env -- c=d echo fail`" = xpass || fail=1 + +# FIXME - decide whether we like this behavior +# test `env -i -u a=b` = a=b || fail=1 +# env -u '' true || fail=1 + +Exit $fail diff --git a/tests/misc/nice b/tests/misc/nice index 1cdd56a..f271eb4 100755 --- a/tests/misc/nice +++ b/tests/misc/nice @@ -48,11 +48,6 @@ NA LAST NA ' set $tests -if test "$VERBOSE" = yes; then - nice --version - set -x -fi - # Require that this test be run at `nice' level 0. niceness=`nice` if test "$niceness" = 0; then @@ -76,8 +71,23 @@ while :; do test x`nice $args nice 2> /dev/null` = x$expected_result \ && ok=ok || ok=FAIL fail=1 test "$VERBOSE" = yes && echo $ok - test x`nice $args nice 2> /dev/null` = x$expected_result || fail=1 shift; shift; shift done +# Test negative niceness - command must be run whether or not change happens. +if test `nice -n -1 nice 2> /dev/null` = 0 ; then + # unprivileged user - warn about failure to change + nice -n -1 true 2> err || fail=1 + test -s err || fail=1 + mv err exp || framework_failure + nice --1 true 2> err || fail=1 + compare exp err || fail=1 +else + # superuser - change succeeds + nice -n -1 nice 2> err || fail=1 + test -s err && fail=1 + test `nice -n -1 nice` = -1 || fail=1 + test `nice --1 nice` = -1 || fail=1 +fi + Exit $fail diff --git a/tests/misc/nice-fail b/tests/misc/nice-fail new file mode 100755 index 0000000..da85eb2 --- /dev/null +++ b/tests/misc/nice-fail @@ -0,0 +1,45 @@ +#!/bin/sh +# Verify that internal failure in nice gives exact status. + +# Copyright (C) 2009 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/>. + + +if test "$VERBOSE" = yes; then + set -x + nice --version +fi + +. $srcdir/test-lib.sh + +fail=0 + +# These tests verify exact status of internal failure. +nice -n 1 # missing command +test $? = 125 || fail=1 +nice --help --version # too many options +test $? = 125 || fail=1 +nice --- # unknown option +test $? = 125 || fail=1 +nice -n 1a # invalid adjustment +test $? = 125 || fail=1 +nice sh -c 'exit 2' # exit status propagation +test $? = 2 || fail=2 +nice . # invalid command +test $? = 126 || fail=1 +nice ... # no such command +test $? = 127 || fail=1 + +Exit $fail diff --git a/tests/misc/su-fail b/tests/misc/su-fail new file mode 100755 index 0000000..bba7d1f --- /dev/null +++ b/tests/misc/su-fail @@ -0,0 +1,33 @@ +#!/bin/sh +# Test su failure cases + +# Copyright (C) 2009 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/test-lib.sh +require_built_ su + +if test "$VERBOSE" = yes; then + set -x + su --version +fi + +# Very little that we can test without a root password +su --- / true # unknown option +test $? = 125 || fail=1 +su no_such_user +test $? = 125 || fail=1 + +Exit $fail -- 1.6.5.rc1