diff --git a/README b/README index b1d55a3..962865f 100644 --- a/README +++ b/README @@ -50,7 +50,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support, =* mv yes none (-i) =*| nice yes none = nl no -d, -f, -h, -l, -p -=* nohup yes none +=*| nohup yes none #* paste yes none =*| printenv non-posix none #* printf yes none diff --git a/nohup.c b/nohup.c index 7543b41..b1e69e9 100644 --- a/nohup.c +++ b/nohup.c @@ -1,6 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include - #include #include #include @@ -8,8 +6,6 @@ #include "util.h" -enum { Error = 127, Found = 126 }; - static void usage(void) { @@ -19,35 +15,33 @@ usage(void) int main(int argc, char *argv[]) { - int fd; + int fd, savederrno; ARGBEGIN { default: usage(); } ARGEND; - if (argc == 0) + if (!argc) usage(); if (signal(SIGHUP, SIG_IGN) == SIG_ERR) - enprintf(Error, "signal HUP:"); + enprintf(127, "signal HUP:"); if (isatty(STDOUT_FILENO)) { - if ((fd = open("nohup.out", O_APPEND|O_CREAT, - S_IRUSR|S_IWUSR)) < 0) { - enprintf(Error, "open nohup.out:"); - } + if ((fd = open("nohup.out", O_APPEND | O_CREAT, S_IRUSR | S_IWUSR)) < 0) + enprintf(127, "open nohup.out:"); if (dup2(fd, STDOUT_FILENO) < 0) - enprintf(Error, "dup2:"); + enprintf(127, "dup2:"); close(fd); } - if (isatty(STDERR_FILENO)) - if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) - enprintf(Error, "dup2:"); + if (isatty(STDERR_FILENO) && dup2(STDOUT_FILENO, STDERR_FILENO) < 0) + enprintf(127, "dup2:"); - execvp(argv[0], &argv[0]); - enprintf(errno == ENOENT ? Error : Found, "exec %s:", argv[0]); - _exit(Error); - /* unreachable */ - return 0; + execvp(argv[0], argv); + savederrno = errno; + weprintf("exec %s:", argv[0]); + _exit(126 + (savederrno == ENOENT)); + + return 0; /* not reached */ }