Signed-off-by: Bernhard Reutner-Fischer <[email protected]>
---
 libc/unistd/daemon.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/libc/unistd/daemon.c b/libc/unistd/daemon.c
index 628df51..27ff42d 100644
--- a/libc/unistd/daemon.c
+++ b/libc/unistd/daemon.c
@@ -69,8 +69,8 @@
 /* use clone() to get fork() like behavior here -- we just want to disassociate
  * from the controlling terminal
  */
-static inline attribute_optimize("O3")
-pid_t _fork_parent(void)
+static __always_inline attribute_optimize("O3")
+pid_t fork_parent(void)
 {
        INTERNAL_SYSCALL_DECL(err);
        register long ret = INTERNAL_SYSCALL(clone, err, 2, CLONE_VM, 0);
@@ -79,19 +79,8 @@ pid_t _fork_parent(void)
                INTERNAL_SYSCALL(exit, err, 1, 0);
        return ret;
 }
-static inline pid_t fork_parent(void)
-{
-       /* Block all signals to keep the parent from using the stack */
-       pid_t ret;
-       sigset_t new_set, old_set;
-       sigfillset(&new_set);
-       sigprocmask(SIG_BLOCK, &new_set, &old_set);
-       ret = _fork_parent();
-       sigprocmask(SIG_SETMASK, &old_set, NULL);
-       return ret;
-}
 #else
-static inline pid_t fork_parent(void)
+static __always_inline pid_t fork_parent(void)
 {
        switch (fork()) {
                case -1: return -1;
@@ -104,6 +93,18 @@ static inline pid_t fork_parent(void)
 int daemon(int nochdir, int noclose)
 {
        int fd;
+       sigset_t old_set, new_set;
+
+#ifdef __ARCH_USE_MMU__
+       /* Upon _exit of the parent we may get a HUP that we do not want.  */
+       sigemptyset(&new_set);
+       sigaddset(&new_set, SIGHUP);
+       fd = sigprocmask(SIG_BLOCK, &new_set, &old_set);
+#else
+       /* Block all signals to keep the parent from using the stack */
+       sigfillset(&new_set);
+       sigprocmask(SIG_BLOCK, &new_set, &old_set);
+#endif
 
        if (fork_parent() == -1)
                return -1;
@@ -111,6 +112,11 @@ int daemon(int nochdir, int noclose)
        if (setsid() == -1)
                return -1;
 
+#ifdef __ARCH_USE_MMU__
+       if (fd != -1)
+#endif
+               sigprocmask(SIG_SETMASK, &old_set, NULL);
+
        if (!nochdir)
                chdir("/");
 
-- 
1.7.6.3

_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to