From 71b3a63b641716165f664cf112be0673a122cea0 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Wed, 22 Nov 2017 21:30:24 +0100 Subject: librt: fix broken posix_spawn Fix iteration over signals, synced with GNU C library code and pending patches. Issues found when running dhcpcd with hook scripts. (exit status 127) Reported-By: kapeka --- librt/spawn.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'librt') diff --git a/librt/spawn.c b/librt/spawn.c index 25e3994e1..a2b8e061b 100644 --- a/librt/spawn.c +++ b/librt/spawn.c @@ -25,6 +25,7 @@ #include #include +#include #include #include "spawn_int.h" @@ -153,13 +154,32 @@ __spawni(pid_t *pid, const char *file, int sig; memset(&sa, 0, sizeof(sa)); - sa.sa_handler = SIG_DFL; - for (sig = 1; sig <= _NSIG; ++sig) { - if (sigismember(&attrp->__sd, sig)) { - if (sigaction(sig, &sa, NULL) != 0) - goto error; - } + sigset_t hset; + sigprocmask (SIG_BLOCK, 0, &hset); + + for (int sig = 1; sig < _NSIG; ++sig) { + if ((flags & POSIX_SPAWN_SETSIGDEF) + && sigismember (&attrp->__sd, sig)) + { + sa.sa_handler = SIG_DFL; + } + else if (sigismember (&hset, sig)) + { + if (__is_internal_signal (sig)) + sa.sa_handler = SIG_IGN; + else + { + __libc_sigaction (sig, 0, &sa); + if (sa.sa_handler == SIG_IGN) + continue; + sa.sa_handler = SIG_DFL; + } + } + else + continue; + + __libc_sigaction (sig, &sa, 0); } } -- cgit v1.2.3