This is the mail archive of the
newlib-cvs@sourceware.org
mailing list for the newlib project.
[newlib-cygwin] Phoenix-RTOS: Implement daemon() function.
- From: Corinna Vinschen <corinna at sourceware dot org>
- To: newlib-cvs at sourceware dot org
- Date: 27 Jun 2016 11:24:32 -0000
- Subject: [newlib-cygwin] Phoenix-RTOS: Implement daemon() function.
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=75c98c35c304421c717b6e30a9fc366ecd6eb965
commit 75c98c35c304421c717b6e30a9fc366ecd6eb965
Author: Kuba Sejdak <jakub.sejdak@phoesys.com>
Date: Fri Jun 24 14:14:52 2016 +0200
Phoenix-RTOS: Implement daemon() function.
Diff:
---
newlib/libc/sys/phoenix/fork.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/newlib/libc/sys/phoenix/fork.c b/newlib/libc/sys/phoenix/fork.c
index 696ce08..7e8d591 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;
+}