diff options
Diffstat (limited to 'bin/nohup')
| -rw-r--r-- | bin/nohup/Kbuild | 3 | ||||
| -rw-r--r-- | bin/nohup/nohup.c | 47 |
2 files changed, 50 insertions, 0 deletions
diff --git a/bin/nohup/Kbuild b/bin/nohup/Kbuild new file mode 100644 index 00000000..2214faf1 --- /dev/null +++ b/bin/nohup/Kbuild @@ -0,0 +1,3 @@ +bin-y := nohup +obj-y += nohup.o +libs-y += $(srctree)/lib/libc/libc.a diff --git a/bin/nohup/nohup.c b/bin/nohup/nohup.c new file mode 100644 index 00000000..8a6171eb --- /dev/null +++ b/bin/nohup/nohup.c @@ -0,0 +1,47 @@ +#include <errno.h> +#include <fcntl.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int main(int argc, char **argv) +{ + int fildes; + + if (argc < 2) { + write(STDOUT_FILENO, "nohup utility [argument...]\n", 29); + return 1; + } + + if (signal(SIGHUP, SIG_IGN) == SIG_ERR) { + perror("nohup: signal"); + return 1; + } + + if (isatty(STDOUT_FILENO)) { + fildes = open("nohup.out", O_WRONLY | O_APPEND | O_CREAT); + if (fildes < 0) { + perror("nohup: open"); + return 1; + } + + if (dup2(fildes, STDOUT_FILENO) < 0) { + perror("nohup: dup2"); + return 1; + } + + close(fildes); + } + + if (isatty(STDERR_FILENO)) { + if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { + perror("nohup: dup2"); + return 1; + } + } + + execvp(argv[0], argv); + perror("nohup: execvp"); + return 127 + (errno == ENOENT); +} |
