svn commit: [26002] trunk/uClibc: include libc/unistd
vapier at uclibc.org
vapier at uclibc.org
Tue Apr 7 05:52:49 UTC 2009
Author: vapier
Date: 2009-04-07 05:52:48 +0000 (Tue, 07 Apr 2009)
New Revision: 26002
Log:
implement daemon() using clone() on no-mmu systems as suggested by Jamie Lokier
Modified:
trunk/uClibc/include/unistd.h
trunk/uClibc/libc/unistd/Makefile.in
trunk/uClibc/libc/unistd/daemon.c
Changeset:
Modified: trunk/uClibc/include/unistd.h
===================================================================
--- trunk/uClibc/include/unistd.h 2009-04-07 02:29:51 UTC (rev 26001)
+++ trunk/uClibc/include/unistd.h 2009-04-07 05:52:48 UTC (rev 26002)
@@ -956,12 +956,10 @@
extern void setusershell (void) __THROW; /* Rewind and re-read the file. */
-#ifdef __ARCH_USE_MMU__
/* Put the program in the background, and dissociate from the controlling
terminal. If NOCHDIR is zero, do `chdir ("/")'. If NOCLOSE is zero,
redirects stdin, stdout, and stderr to /dev/null. */
extern int daemon (int __nochdir, int __noclose) __THROW __wur;
-#endif
#endif /* Use BSD || X/Open. */
Modified: trunk/uClibc/libc/unistd/Makefile.in
===================================================================
--- trunk/uClibc/libc/unistd/Makefile.in 2009-04-07 02:29:51 UTC (rev 26001)
+++ trunk/uClibc/libc/unistd/Makefile.in 2009-04-07 05:52:48 UTC (rev 26002)
@@ -14,8 +14,6 @@
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)
Modified: trunk/uClibc/libc/unistd/daemon.c
===================================================================
--- trunk/uClibc/libc/unistd/daemon.c 2009-04-07 02:29:51 UTC (rev 26001)
+++ trunk/uClibc/libc/unistd/daemon.c 2009-04-07 05:52:48 UTC (rev 26002)
@@ -56,27 +56,40 @@
/* 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);
- /* Make certain we are not a session leader, or else we
- * might reacquire a controlling terminal */
- if (fork())
- _exit(0);
-
if (!nochdir)
chdir("/");
More information about the uClibc-cvs
mailing list