diff options
author | Kuba Sejdak <jakub.sejdak@phoesys.com> | 2016-06-24 14:14:52 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2016-06-27 13:23:35 +0200 |
commit | 75c98c35c304421c717b6e30a9fc366ecd6eb965 (patch) | |
tree | 6ce403b1024ab5da03635e5443a4bab3c74dab6d | |
parent | 0601c031098c02beae819b04844b44f9aabcebf8 (diff) | |
download | cygnal-75c98c35c304421c717b6e30a9fc366ecd6eb965.tar.gz cygnal-75c98c35c304421c717b6e30a9fc366ecd6eb965.tar.bz2 cygnal-75c98c35c304421c717b6e30a9fc366ecd6eb965.zip |
Phoenix-RTOS: Implement daemon() function.
-rw-r--r-- | newlib/libc/sys/phoenix/fork.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/newlib/libc/sys/phoenix/fork.c b/newlib/libc/sys/phoenix/fork.c index 696ce08c6..7e8d591c2 100644 --- a/newlib/libc/sys/phoenix/fork.c +++ b/newlib/libc/sys/phoenix/fork.c @@ -25,7 +25,10 @@ #include "syscall.h" #include <errno.h> +#include <stdio.h> +#include <stdlib.h> #include <sys/types.h> +#include <unistd.h> pid_t fork() { @@ -42,3 +45,26 @@ pid_t vfork() { return fork(); } + +int daemon(int nochdir, int noclose) +{ + switch(fork()) { + case -1: + return -1; + case 0: + break; + default: + exit(0); + } + + if (setsid() == -1) + return -1; + + if (nochdir == 0) + chdir("/"); + + if (noclose == 0) + freopen("/dev/null", "a+", stdout); + + return 0; +} |