diff options
author | Khem Raj <kraj@mvista.com> | 2009-04-07 06:23:17 +0000 |
---|---|---|
committer | Khem Raj <kraj@mvista.com> | 2009-04-07 06:23:17 +0000 |
commit | 6e9282175daabf0803bc6f63273fc3a4920de4fc (patch) | |
tree | d198cffd22d179b9b8ca8d4633474570c943efea /libc | |
parent | 8058fb1efc594a771ae7c356c33abbf4bac28ff6 (diff) | |
download | uClibc-alpine-6e9282175daabf0803bc6f63273fc3a4920de4fc.tar.bz2 uClibc-alpine-6e9282175daabf0803bc6f63273fc3a4920de4fc.tar.xz |
Merged revisions 25971,26002 via svnmerge from
svn+ssh://svn.uclibc.org/svn/trunk/uClibc
........
r25971 | vapier | 2009-04-05 23:40:57 -0700 (Sun, 05 Apr 2009) | 1 line
apply getline() fix from linux kernel
........
r26002 | vapier | 2009-04-06 22:52:48 -0700 (Mon, 06 Apr 2009) | 1 line
implement daemon() using clone() on no-mmu systems as suggested by Jamie Lokier
........
Diffstat (limited to 'libc')
-rw-r--r-- | libc/unistd/Makefile.in | 2 | ||||
-rw-r--r-- | libc/unistd/daemon.c | 34 |
2 files changed, 26 insertions, 10 deletions
diff --git a/libc/unistd/Makefile.in b/libc/unistd/Makefile.in index f6ef98cf0..b4c5130a9 100644 --- a/libc/unistd/Makefile.in +++ b/libc/unistd/Makefile.in @@ -14,8 +14,6 @@ CSRC := $(filter-out exec.c,$(CSRC)) ifeq ($(ARCH_USE_MMU),y) CSRC := $(filter-out __exec_alloc.c,$(CSRC)) -else -CSRC := $(filter-out daemon.c,$(CSRC)) endif ifeq ($(UCLIBC_HAS_GNU_GETOPT),y) diff --git a/libc/unistd/daemon.c b/libc/unistd/daemon.c index f5b9f44f6..0e439d1ba 100644 --- a/libc/unistd/daemon.c +++ b/libc/unistd/daemon.c @@ -61,18 +61,36 @@ /* libc_hidden_proto(chdir) */ /* libc_hidden_proto(fork) */ +#ifndef __ARCH_USE_MMU__ +#include <sys/syscall.h> +/* use clone() to get fork() like behavior here -- we just want to disassociate + * from the controlling terminal + */ +static inline pid_t fork_parent(void) +{ + register unsigned long ret = INTERNAL_SYSCALL(clone, wtf, 2, CLONE_VM, 0); + if (ret != -1 && ret != 0) + /* parent needs to die now w/out touching stack */ + INTERNAL_SYSCALL(exit, wtf, 0); + return ret; +} +#else +static inline pid_t fork_parent(void) +{ + switch (fork()) { + case -1: return -1; + case 0: return 0; + default: _exit(0); + } +} +#endif + int daemon( int nochdir, int noclose ) { int fd; - switch (fork()) { - case -1: - return(-1); - case 0: - break; - default: - _exit(0); - } + if (fork_parent() == -1) + return -1; if (setsid() == -1) return(-1); |