summaryrefslogtreecommitdiff
path: root/src/nohup.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2014-09-08 16:31:14 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2014-09-08 20:48:44 -0700
commit8defcee49be881f8c7b8327f07b988fbe5c7171d (patch)
tree1ff1094a2d7fb53222831670d211ce60a408b866 /src/nohup.c
parent72e470b9b5af77bcfd90ac175ed285877837ba20 (diff)
downloadcoreutils-8defcee49be881f8c7b8327f07b988fbe5c7171d.tar.xz
maint: prefer 'return status;' to 'exit (status);' in 'main'
* build-aux/gen-single-binary.sh: Don't use ATTRIBUTE_NORETURN for main functions. * src/base64.c, src/basename.c, src/cat.c, src/chcon.c, src/chgrp.c: * src/chmod.c, src/chown.c, src/chroot.c, src/cksum.c, src/comm.c: * src/cp.c, src/csplit.c, src/cut.c, src/date.c, src/dd.c, src/df.c: * src/dircolors.c, src/dirname.c, src/du.c, src/echo.c, src/env.c: * src/expand.c, src/expr.c, src/factor.c, src/fmt.c, src/fold.c: * src/getlimits.c, src/groups.c, src/head.c, src/hostid.c: * src/hostname.c, src/id.c, src/install.c, src/join.c, src/kill.c: * src/link.c, src/ln.c, src/logname.c, src/ls.c, src/make-prime-list.c: * src/md5sum.c, src/mkdir.c, src/mkfifo.c, src/mknod.c, src/mktemp.c: * src/mv.c, src/nice.c, src/nl.c, src/nohup.c, src/nproc.c: * src/numfmt.c, src/od.c, src/paste.c, src/pathchk.c, src/pinky.c: * src/pr.c, src/printenv.c, src/printf.c, src/ptx.c, src/pwd.c: * src/readlink.c, src/realpath.c, src/rm.c, src/rmdir.c, src/runcon.c: * src/seq.c, src/shred.c, src/shuf.c, src/sleep.c, src/sort.c: * src/split.c, src/stat.c, src/stdbuf.c, src/stty.c, src/sum.c: * src/sync.c, src/tac.c, src/tail.c, src/tee.c, src/timeout.c: * src/touch.c, src/tr.c, src/true.c, src/truncate.c, src/tsort.c: * src/tty.c, src/uname.c, src/unexpand.c, src/uniq.c, src/unlink.c: * src/uptime.c, src/users.c, src/wc.c, src/who.c, src/whoami.c: In 'main' functions, Prefer 'return status;' to 'exit (status);'. * src/coreutils-arch.c (_single_binary_main_uname) (_single_binary_main_arch): * src/coreutils-dir.c, src/coreutils-vdir.c (_single_binary_main_ls) (_single_binary_main_dir, _single_binary_main_vdir): Omit ATTRIBUTE_NORETURN. Return a value. * src/coreutils.c (SINGLE_BINARY_PROGRAM): Omit ATTRIBUTE_NORETURN. (launch_program): Now static. * src/dd.c (finish_up): New function. (quit, main): Use it. * src/getlimits.c (main): Return a proper exit status. * src/test.c (test_main_return): New macro. (main): Use it. * src/logname.c, src/nohup.c, src/whoami.c: Use 'error' to simplify exit status in 'main' function. * src/yes.c (main): Use 'return' rather than 'error' to exit, so that GCC doesn't suggest ATTRIBUTE_NORETURN.
Diffstat (limited to 'src/nohup.c')
-rw-r--r--src/nohup.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/nohup.c b/src/nohup.c
index eca1f5124..13bb04531 100644
--- a/src/nohup.c
+++ b/src/nohup.c
@@ -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;
}