From f2da42aa412ab9e43f62d9781573bf6053483301 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 12 Feb 2018 09:19:53 +0100 Subject: [PATCH] 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. --- src/pipestream.cpp | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) 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"); -- 1.7.1