]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
nohup: use EXIT_CANCELED if not POSIXLY_CORRECT
authorEric Blake <ebb9@byu.net>
Fri, 23 Oct 2009 12:59:23 +0000 (06:59 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 23 Oct 2009 22:24:08 +0000 (16:24 -0600)
* 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
doc/coreutils.texi
src/nohup.c
tests/misc/help-version
tests/misc/invalid-opt
tests/misc/nohup

diff --git a/NEWS b/NEWS
index f359133093712bc582581c200e1586982b4fd68f..1ed577f7f370cd7721c6f8c0b5bb9f5eebee3918 100644 (file)
--- 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
 
index 31c3d5c1b903f686e678b770d59b49e799bf6116..c54ffb88f9ee9e173a7d07bf9ad5fb0e9145377c 100644 (file)
@@ -14634,11 +14634,15 @@ options}.  Options must precede operands.
 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
index 99bb86547c3998f5ec52977faf501e7bdfd8189b..880cc74925d78faed4c9452f56f9d81f8e1c8622 100644 (file)
@@ -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);
index 57cc1e7d36341516b2bd0e43cadd2ecd627b5941..da559070f263d50a8a6b9da6853496418c38a6c1 100755 (executable)
@@ -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
index 155ac6e12a0c4ee656aa230b1d3b58a59edd8922..2e5c099da6a6820b5f2d72119336ab8ad8537547 100755 (executable)
@@ -33,7 +33,7 @@ my %exit_status =
     env => 125,
     expr => 0,
     nice => 125,
-    nohup => 127,
+    nohup => 125,
     sort => 2,
     stdbuf => 125,
     su => 125,
index 25a7ca4dac60ffc830a91212573449be5b0d4281..ad04a1cb037ce3b928903be8d761636b7627fc77 100755 (executable)
@@ -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