summaryrefslogtreecommitdiffstats
path: root/libc/unistd
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-04-13 00:06:40 +0000
committerMike Frysinger <vapier@gentoo.org>2009-04-13 00:06:40 +0000
commitd83d5f98e1c6be6d363abf208d7f304fc356a285 (patch)
tree72b699908c9cb9e633eae9f49bff8a5d644abb52 /libc/unistd
parent35b1cd3d25d1d4f6e8fc0a90263b5d98dfa66073 (diff)
downloaduClibc-alpine-d83d5f98e1c6be6d363abf208d7f304fc356a285.tar.bz2
uClibc-alpine-d83d5f98e1c6be6d363abf208d7f304fc356a285.tar.xz
make sure to block all signals when calling daemon() to prevent delivery while the parent is sharing the stack
Diffstat (limited to 'libc/unistd')
-rw-r--r--libc/unistd/daemon.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libc/unistd/daemon.c b/libc/unistd/daemon.c
index 19332cca1..789488967 100644
--- a/libc/unistd/daemon.c
+++ b/libc/unistd/daemon.c
@@ -44,6 +44,7 @@
#include <features.h>
#include <fcntl.h>
#include <paths.h>
+#include <signal.h>
#include <unistd.h>
#if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
@@ -61,7 +62,7 @@
/* use clone() to get fork() like behavior here -- we just want to disassociate
* from the controlling terminal
*/
-static inline pid_t fork_parent(void)
+static inline pid_t _fork_parent(void)
{
register unsigned long ret = INTERNAL_SYSCALL(clone, wtf, 2, CLONE_VM, 0);
if (ret != -1 && ret != 0)
@@ -69,6 +70,17 @@ static inline pid_t fork_parent(void)
INTERNAL_SYSCALL(exit, wtf, 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)
{