diff options
author | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-14 13:47:49 +0000 |
---|---|---|
committer | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-14 13:47:49 +0000 |
commit | f15aa3a552022743398a652165d76bf912c715e5 (patch) | |
tree | b58f8b4c47fc571fbb498d83a4bd4fca226ac6c4 /mdk-stage1/dietlibc/libugly/daemon.c | |
parent | 189b01c358a1181ddc951adba97a0258d5fc2cf1 (diff) | |
download | drakx-f15aa3a552022743398a652165d76bf912c715e5.tar drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.gz drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.bz2 drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.xz drakx-f15aa3a552022743398a652165d76bf912c715e5.zip |
Initial revision
Diffstat (limited to 'mdk-stage1/dietlibc/libugly/daemon.c')
-rw-r--r-- | mdk-stage1/dietlibc/libugly/daemon.c | 35 |
1 files changed, 35 insertions, 0 deletions
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 <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <paths.h> + +#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); +} + |