[PATCH] daemon: ignore SIGHUP
Bernhard Reutner-Fischer
rep.dot.nop at gmail.com
Wed Nov 16 19:38:17 UTC 2011
even with MMU (and only ignore HUP on !MMU to re-unify them).
+~98b
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
libc/unistd/daemon.c | 26 ++++++++++++--------------
1 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/libc/unistd/daemon.c b/libc/unistd/daemon.c
index 628df51..3dc4441 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
+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,12 +93,21 @@ static inline pid_t fork_parent(void)
int daemon(int nochdir, int noclose)
{
int fd;
+ struct sigaction old_sa, new_sa;
+
+ /* Upon _exit of the parent, we may get a HUP that we do not want. */
+ __sigemptyset(&new_sa.sa_mask);
+ new_sa.sa_handler = SIG_IGN;
+ new_sa.sa_flags = 0;
+ fd = sigaction(SIGHUP, &new_sa, &old_sa);
if (fork_parent() == -1)
return -1;
if (setsid() == -1)
return -1;
+ if (fd != -1)
+ sigaction(SIGHUP, &old_sa, NULL);
if (!nochdir)
chdir("/");
--
1.7.6.3
More information about the uClibc
mailing list