Phoenix-RTOS: Implement daemon() function.

This commit is contained in:
Kuba Sejdak 2016-06-24 14:14:52 +02:00 committed by Corinna Vinschen
parent 0601c03109
commit 75c98c35c3
1 changed files with 26 additions and 0 deletions

View File

@ -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;
}