diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2015-07-04 17:13:50 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2015-07-04 17:13:50 +0300 |
commit | 71cd8e3a743046573744123777061b64881bf372 (patch) | |
tree | 82522befe647f4fff186a5630cad0cad33f8ef53 /src/nohup.c | |
parent | c18578632fd3c9e513e613a86ba2b7c4ebee6c45 (diff) | |
download | coreutils-upstream.tar.gz |
Imported Upstream version 8.24upstream/8.24upstream
Diffstat (limited to 'src/nohup.c')
-rw-r--r-- | src/nohup.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/src/nohup.c b/src/nohup.c index eca1f512..8cdacedb 100644 --- a/src/nohup.c +++ b/src/nohup.c @@ -1,5 +1,5 @@ /* nohup -- run a command immune to hangups, with output to a non-tty - Copyright (C) 2003-2014 Free Software Foundation, Inc. + Copyright (C) 2003-2015 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 @@ -63,14 +63,14 @@ Run COMMAND, ignoring hangup signals.\n\ fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); printf (_("\n\ -If standard input is a terminal, redirect it from /dev/null.\n\ +If standard input is a terminal, redirect it from an unreadable file.\n\ If standard output is a terminal, append output to 'nohup.out' if possible,\n\ '$HOME/nohup.out' otherwise.\n\ If standard error is a terminal, redirect it to standard output.\n\ To save output to FILE, use '%s COMMAND > FILE'.\n"), program_name); printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME); - emit_ancillary_info (); + emit_ancillary_info (PROGRAM_NAME); } exit (status); } @@ -123,10 +123,8 @@ main (int argc, char **argv) if (ignoring_input) { if (fd_reopen (STDIN_FILENO, "/dev/null", O_WRONLY, 0) < 0) - { - error (0, errno, _("failed to render standard input unusable")); - exit (exit_internal_failure); - } + error (exit_internal_failure, errno, + _("failed to render standard input unusable")); if (!redirecting_stdout && !redirecting_stderr) error (0, 0, _("ignoring input")); } @@ -164,7 +162,7 @@ main (int argc, char **argv) if (in_home) error (0, saved_errno2, _("failed to open %s"), quote (in_home)); - exit (exit_internal_failure); + return exit_internal_failure; } file = in_home; } @@ -213,28 +211,23 @@ main (int argc, char **argv) error() again, particularly since we may have just changed the underlying fd out from under stderr. */ if (ferror (stderr)) - exit (exit_internal_failure); + return exit_internal_failure; signal (SIGHUP, SIG_IGN); - { - int exit_status; - int saved_errno; - char **cmd = argv + optind; - - execvp (*cmd, cmd); - exit_status = (errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE); - saved_errno = errno; - - /* The execve failed. Output a diagnostic to stderr only if: - - stderr was initially redirected to a non-tty, or - - stderr was initially directed to a tty, and we - can dup2 it to point back to that same tty. - In other words, output the diagnostic if possible, but only if - it will go to the original stderr. */ - if (dup2 (saved_stderr_fd, STDERR_FILENO) == STDERR_FILENO) - error (0, saved_errno, _("failed to run command %s"), quote (*cmd)); - - exit (exit_status); - } + char **cmd = argv + optind; + execvp (*cmd, cmd); + int exit_status = errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE; + int saved_errno = errno; + + /* The execve failed. Output a diagnostic to stderr only if: + - stderr was initially redirected to a non-tty, or + - stderr was initially directed to a tty, and we + can dup2 it to point back to that same tty. + In other words, output the diagnostic if possible, but only if + it will go to the original stderr. */ + if (dup2 (saved_stderr_fd, STDERR_FILENO) == STDERR_FILENO) + error (0, saved_errno, _("failed to run command %s"), quote (*cmd)); + + return exit_status; } |