From 6018e17637264a9561b37be699c3d53b6661de23 Mon Sep 17 00:00:00 2001 From: Kacper Fiedorowicz Date: Sat, 3 Jan 2026 18:44:51 +0100 Subject: Add docs and nohup/unlink utitilies --- bin/nohup/nohup.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 bin/nohup/nohup.c (limited to 'bin/nohup/nohup.c') 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 +#include +#include +#include +#include +#include + +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); +} -- cgit v1.2.3