]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
chroot, env, nice, su: use EXIT_CANCELED for internal failure
authorEric Blake <ebb9@byu.net>
Fri, 23 Oct 2009 12:59:02 +0000 (06:59 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 23 Oct 2009 22:24:05 +0000 (16:24 -0600)
* 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
doc/coreutils.texi
src/chroot.c
src/env.c
src/nice.c
src/su.c
tests/misc/help-version
tests/misc/invalid-opt

diff --git a/NEWS b/NEWS
index 7057d87074ae7a4597b619dea5751d299ca5f3f0..f359133093712bc582581c200e1586982b4fd68f 100644 (file)
--- 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.
index 64e0e954cede50759f06e48364551075cfa06640..31c3d5c1b903f686e678b770d59b49e799bf6116 100644 (file)
@@ -14363,7 +14363,7 @@ device files), copy them into place, too.
 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 @@ Exit status:
 
 @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 @@ Exit status:
 
 @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 @@ shell is restricted (see @option{-m} just above).
 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
index 9269f1b0ea575ed70b7116e5e1dd5a46e5c09840..e4765babbf28dafc8090f798a81119b936d0a769 100644 (file)
@@ -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);
index 90edc5a3364651a5d69afb131aa26f5fa0f073ac..b69a29a1bcdbc26228eed1fbb15dbe9534c9bc79 100644 (file)
--- 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);
         }
     }
 
index 6cd5f31333b30aa8565bf89a30574d77b41489bc..b04f675fbc574865cec76db787d7552391e147d4 100644 (file)
@@ -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]);
 
index 25b883814ff66bf7d0e49466a95075c35da2df1e..0de67c95a1cbc08b2f37f5e132f52db9b75359fb 100644 (file)
--- 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
index 9afe8af8bef2d1826204c2f4a49bf0be96f5a363..57cc1e7d36341516b2bd0e43cadd2ecd627b5941 100755 (executable)
@@ -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
index 23142bb0b4e50ca989b58a5a267b7040689ea2b1..155ac6e12a0c4ee656aa230b1d3b58a59edd8922 100755 (executable)
@@ -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,