diff options
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 | } |
