From 9e29bd9e59dc17b6505f72303fd37d15c95d1b02 Mon Sep 17 00:00:00 2001 From: Petr Skocik Date: Wed, 18 Oct 2017 11:46:42 +0200 Subject: [PATCH 3/3] posix_spawn: unmask signals before potentially long-blocking calls --- src/process/posix_spawn.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/process/posix_spawn.c b/src/process/posix_spawn.c index 137898d8..72a95a45 100644 --- a/src/process/posix_spawn.c +++ b/src/process/posix_spawn.c @@ -10,15 +10,9 @@ #include "fdop.h" #include "libc.h" -/* - the user may wish to adddup2 a CLOEXEC filedescriptor - this should remove the CLOEXEC flag and the user shouldn't be expected to do it - because if the CLOEXEC flag is on, it probably needs to be on, because the parent - is multithreaded -*/ static int dup3_or_set_cloexec(int SrcFd, int DestFd, int Flg) { - rt (DestFd!=SrcFd) ? dup3(SrcFd,DestFd,Flg) : fcntl(DestFd,F_SETFD,Flg); + return (DestFd!=SrcFd) ? dup3(SrcFd,DestFd,Flg) : fcntl(DestFd,F_SETFD,Flg); } struct args { @@ -81,6 +75,7 @@ static int child(void *args_vp) } __libc_sigaction(i, &sa, 0); } + if (attr->__flags & POSIX_SPAWN_SETSID) if ((ret=__syscall(SYS_setsid)) < 0) @@ -98,6 +93,12 @@ static int child(void *args_vp) (ret=__syscall(SYS_setuid, __syscall(SYS_getuid))) ) goto fail; + /*file actions (opens) are potentially long-blocking, so the process should + become interruptible before they're invoked */ + pthread_sigmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK) + ? &attr->__mask : &args->oldmask, 0); + + if (fa && fa->__actions) { struct fdop *op; int fd; @@ -124,9 +125,6 @@ static int child(void *args_vp) } } - pthread_sigmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK) - ? &attr->__mask : &args->oldmask, 0); - args->exec(args->path, args->argv, args->envp); ret = -errno; -- 2.14.2