aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-04 00:30:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-04 00:30:06 +0000
commitf8157cafcb04a2c37b33bb68272cce1367a14777 (patch)
tree69222bac1e6f60809a073bf4744ab2811c7bf07c /coreutils
parent32d49bc70fa544c45421ae475b38b412e610e278 (diff)
downloadbusybox-w32-f8157cafcb04a2c37b33bb68272cce1367a14777.tar.gz
busybox-w32-f8157cafcb04a2c37b33bb68272cce1367a14777.tar.bz2
busybox-w32-f8157cafcb04a2c37b33bb68272cce1367a14777.zip
nohup: compat patch by Christoph Gysin <mailinglist.cache at gmail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/nohup.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/coreutils/nohup.c b/coreutils/nohup.c
index da8f58c72..7d6a51ae9 100644
--- a/coreutils/nohup.c
+++ b/coreutils/nohup.c
@@ -12,21 +12,41 @@
12 12
13#include "libbb.h" 13#include "libbb.h"
14 14
15/* Compat info: nohup (GNU coreutils 6.8) does this:
16# nohup true
17nohup: ignoring input and appending output to `nohup.out'
18# nohup true 1>/dev/null
19nohup: ignoring input and redirecting stderr to stdout
20# nohup true 2>zz
21# cat zz
22nohup: ignoring input and appending output to `nohup.out'
23# nohup true 2>zz 1>/dev/null
24# cat zz
25nohup: ignoring input
26# nohup true </dev/null 1>/dev/null
27nohup: redirecting stderr to stdout
28# nohup true </dev/null 2>zz 1>/dev/null
29# cat zz
30 (nothing)
31#
32*/
33
15int nohup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 34int nohup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16int nohup_main(int argc, char **argv) 35int nohup_main(int argc, char **argv)
17{ 36{
18 int nullfd;
19 const char *nohupout; 37 const char *nohupout;
20 char *home = NULL; 38 char *home;
21 39
22 xfunc_error_retval = 127; 40 xfunc_error_retval = 127;
23 41
24 if (argc < 2) bb_show_usage(); 42 if (argc < 2) bb_show_usage();
25 43
26 nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
27 /* If stdin is a tty, detach from it. */ 44 /* If stdin is a tty, detach from it. */
28 if (isatty(STDIN_FILENO)) 45 if (isatty(STDIN_FILENO)) {
29 dup2(nullfd, STDIN_FILENO); 46 /* bb_error_msg("ignoring input"); */
47 close(STDIN_FILENO);
48 xopen(bb_dev_null, O_RDONLY); /* will be fd 0 (STDIN_FILENO) */
49 }
30 50
31 nohupout = "nohup.out"; 51 nohupout = "nohup.out";
32 /* Redirect stdout to nohup.out, either in "." or in "$HOME". */ 52 /* Redirect stdout to nohup.out, either in "." or in "$HOME". */
@@ -37,24 +57,22 @@ int nohup_main(int argc, char **argv)
37 if (home) { 57 if (home) {
38 nohupout = concat_path_file(home, nohupout); 58 nohupout = concat_path_file(home, nohupout);
39 xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR); 59 xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
60 } else {
61 xopen(bb_dev_null, O_RDONLY); /* will be fd 1 */
40 } 62 }
41 } 63 }
42 } else dup2(nullfd, STDOUT_FILENO); 64 bb_error_msg("appending output to %s", nohupout);
65 }
43 66
44 /* If we have a tty on stderr, announce filename and redirect to stdout. 67 /* If we have a tty on stderr, redirect to stdout. */
45 * Else redirect to /dev/null.
46 */
47 if (isatty(STDERR_FILENO)) { 68 if (isatty(STDERR_FILENO)) {
48 bb_error_msg("appending to %s", nohupout); 69 /* if (stdout_wasnt_a_tty)
70 bb_error_msg("redirecting stderr to stdout"); */
49 dup2(STDOUT_FILENO, STDERR_FILENO); 71 dup2(STDOUT_FILENO, STDERR_FILENO);
50 } else dup2(nullfd, STDERR_FILENO); 72 }
51 73
52 if (nullfd > 2)
53 close(nullfd);
54 signal(SIGHUP, SIG_IGN); 74 signal(SIGHUP, SIG_IGN);
55 75
56 BB_EXECVP(argv[1], argv+1); 76 BB_EXECVP(argv[1], argv+1);
57 if (ENABLE_FEATURE_CLEAN_UP && home)
58 free((char*)nohupout);
59 bb_simple_perror_msg_and_die(argv[1]); 77 bb_simple_perror_msg_and_die(argv[1]);
60} 78}