From f15aa3a552022743398a652165d76bf912c715e5 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Mon, 14 May 2001 13:47:49 +0000 Subject: Initial revision --- mdk-stage1/dietlibc/libugly/daemon.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 mdk-stage1/dietlibc/libugly/daemon.c (limited to 'mdk-stage1/dietlibc/libugly/daemon.c') diff --git a/mdk-stage1/dietlibc/libugly/daemon.c b/mdk-stage1/dietlibc/libugly/daemon.c new file mode 100644 index 000000000..6748cc3c9 --- /dev/null +++ b/mdk-stage1/dietlibc/libugly/daemon.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +#include "daemon.h" + +int daemon (int nochdir,int noclose) +{ + int fd; + switch (fork ()) + { + case -1: + return (-1); + case 0: + break; + default: + _exit (0); + } + if (setsid () == -1) + return (-1); + if (!nochdir) chdir ("/"); + if (!noclose) + { + fd = open (_PATH_DEVNULL,O_RDWR,0); + if (fd == -1) return (-1); + dup2 (fd,STDIN_FILENO); + dup2 (fd,STDOUT_FILENO); + dup2 (fd,STDERR_FILENO); + close (fd); + } + return (0); +} + -- cgit v1.2.1