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 +#include +#include #include +#include 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; +}