diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-27 22:21:12 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-27 22:21:12 +0000 |
commit | e06bed30cfcde7b9e320aff8a4c878c72416c4c4 (patch) | |
tree | da3276ab5bc224a64fb9f7d7d2a8a046816ec533 /coreutils | |
parent | cd75a96f0f9d446028cad7e4b9b9224e009752e1 (diff) | |
download | busybox-w32-e06bed30cfcde7b9e320aff8a4c878c72416c4c4.tar.gz busybox-w32-e06bed30cfcde7b9e320aff8a4c878c72416c4c4.tar.bz2 busybox-w32-e06bed30cfcde7b9e320aff8a4c878c72416c4c4.zip |
use bb_sanitize_stdio() where appropriate
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/nohup.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/coreutils/nohup.c b/coreutils/nohup.c index 21adfc1c3..317d2a8ae 100644 --- a/coreutils/nohup.c +++ b/coreutils/nohup.c | |||
@@ -14,16 +14,18 @@ | |||
14 | 14 | ||
15 | int nohup_main(int argc, char **argv) | 15 | int nohup_main(int argc, char **argv) |
16 | { | 16 | { |
17 | int temp, nullfd; | 17 | int nullfd; |
18 | char *nohupout, *home = NULL; | 18 | const char *nohupout; |
19 | char *home = NULL; | ||
19 | 20 | ||
20 | xfunc_error_retval = 127; | 21 | xfunc_error_retval = 127; |
21 | 22 | ||
22 | if (argc<2) bb_show_usage(); | 23 | if (argc < 2) bb_show_usage(); |
23 | 24 | ||
24 | nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND); | 25 | nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND); |
25 | /* If stdin is a tty, detach from it. */ | 26 | /* If stdin is a tty, detach from it. */ |
26 | if (isatty(STDIN_FILENO)) dup2(nullfd, STDIN_FILENO); | 27 | if (isatty(STDIN_FILENO)) |
28 | dup2(nullfd, STDIN_FILENO); | ||
27 | 29 | ||
28 | nohupout = "nohup.out"; | 30 | nohupout = "nohup.out"; |
29 | /* Redirect stdout to nohup.out, either in "." or in "$HOME". */ | 31 | /* Redirect stdout to nohup.out, either in "." or in "$HOME". */ |
@@ -38,16 +40,20 @@ int nohup_main(int argc, char **argv) | |||
38 | } | 40 | } |
39 | } else dup2(nullfd, STDOUT_FILENO); | 41 | } else dup2(nullfd, STDOUT_FILENO); |
40 | 42 | ||
41 | /* If we have a tty on strderr, announce filename and redirect to stdout. | 43 | /* If we have a tty on stderr, announce filename and redirect to stdout. |
42 | * Else redirect to /dev/null. | 44 | * Else redirect to /dev/null. |
43 | */ | 45 | */ |
44 | temp = isatty(STDERR_FILENO); | 46 | if (isatty(STDERR_FILENO)) { |
45 | if (temp) bb_error_msg("appending to %s", nohupout); | 47 | bb_error_msg("appending to %s", nohupout); |
46 | dup2(temp ? STDOUT_FILENO : nullfd, STDERR_FILENO); | 48 | dup2(STDOUT_FILENO, STDERR_FILENO); |
47 | close(nullfd); | 49 | } else dup2(nullfd, STDERR_FILENO); |
48 | signal (SIGHUP, SIG_IGN); | 50 | |
49 | 51 | if (nullfd > 2) | |
50 | execvp(argv[1],argv+1); | 52 | close(nullfd); |
51 | if (00 && ENABLE_FEATURE_CLEAN_UP && home) free(nohupout); | 53 | signal(SIGHUP, SIG_IGN); |
54 | |||
55 | execvp(argv[1], argv+1); | ||
56 | if (ENABLE_FEATURE_CLEAN_UP && home) | ||
57 | free((char*)nohupout); | ||
52 | bb_perror_msg_and_die("%s", argv[1]); | 58 | bb_perror_msg_and_die("%s", argv[1]); |
53 | } | 59 | } |