From: Philipp Gesang Date: Mon, 12 Feb 2018 08:19:53 +0000 (+0100) Subject: block signals before fork()ing the pipestream child X-Git-Tag: v2.10~1^2~7 X-Git-Url: http://developer.intra2net.com/git/?p=libi2ncommon;a=commitdiff_plain;h=f2da42aa412ab9e43f62d9781573bf6053483301 block signals before fork()ing the pipestream child Block all signals until we are ready to handle them again. In particular, this saves us checking for close(2) being interrupted. --- diff --git a/src/pipestream.cpp b/src/pipestream.cpp index b9cdcf7..7a89be2 100644 --- a/src/pipestream.cpp +++ b/src/pipestream.cpp @@ -249,6 +249,7 @@ inpipebuf::init_without_shell (const char *const *argv, { FILE *pipeobj = NULL; int pipefd [2]; + sigset_t oldmask, newmask; if (!out && !err) { errno = EINVAL; @@ -260,10 +261,14 @@ inpipebuf::init_without_shell (const char *const *argv, PIPE_CTOR_FAIL("pipe"); } + sigfillset (&newmask); + sigprocmask (SIG_SETMASK, &newmask, &oldmask); + errno = 0; pid_t childpid = fork (); switch (childpid) { case -1: { + sigprocmask (SIG_SETMASK, &oldmask, NULL); PIPE_CTOR_FAIL("fork"); break; } @@ -292,6 +297,8 @@ inpipebuf::init_without_shell (const char *const *argv, close (pipefd [1]); + sigprocmask (SIG_SETMASK, &oldmask, NULL); + errno = 0; if (path) { execvpe (argv [0], const_cast (argv), environ); @@ -304,6 +311,8 @@ inpipebuf::init_without_shell (const char *const *argv, default: { close (pipefd [1]); + sigprocmask (SIG_SETMASK, &oldmask, NULL); + errno = 0; if ((pipeobj = fdopen (pipefd [0], "r")) == NULL) { PIPE_CTOR_FAIL("fdopen");