diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-02-01T12·00+0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-02-01T12·00+0100 |
commit | 7a65b2470eb53a320749d76746fbf65790183d9d (patch) | |
tree | 696a327d3a17a676d9ab9b723e8abcd7a7cef3ed /src/libmain | |
parent | 583ff4ec46fe1fa758f0fa4df1d8b37d9192736c (diff) |
Restore default signal handling in child processes
In particular, this fixes Ctrl-C in nix-shell sessions.
Diffstat (limited to 'src/libmain')
-rw-r--r-- | src/libmain/shared.cc | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index d564e03853e0..52cb2312826b 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -119,15 +119,9 @@ void initNix() startSignalHandlerThread(); - /* Ignore SIGPIPE. */ + /* Reset SIGCHLD to its default. */ struct sigaction act; sigemptyset(&act.sa_mask); - act.sa_handler = SIG_IGN; - act.sa_flags = 0; - if (sigaction(SIGPIPE, &act, 0)) - throw SysError("ignoring SIGPIPE"); - - /* Reset SIGCHLD to its default. */ act.sa_handler = SIG_DFL; act.sa_flags = 0; if (sigaction(SIGCHLD, &act, 0)) @@ -252,7 +246,7 @@ void printVersion(const string & programName) void showManPage(const string & name) { - restoreSIGPIPE(); + restoreSignals(); execlp("man", "man", name.c_str(), NULL); throw SysError(format("command ‘man %1%’ failed") % name.c_str()); } @@ -305,16 +299,6 @@ RunPager::RunPager() if (!pager) pager = getenv("PAGER"); if (pager && ((string) pager == "" || (string) pager == "cat")) return; - /* Ignore SIGINT. The pager will handle it (and we'll get - SIGPIPE). */ - struct sigaction act; - act.sa_handler = SIG_IGN; - act.sa_flags = 0; - sigemptyset(&act.sa_mask); - if (sigaction(SIGINT, &act, 0)) throw SysError("ignoring SIGINT"); - - restoreSIGPIPE(); - Pipe toPager; toPager.create(); @@ -323,6 +307,7 @@ RunPager::RunPager() throw SysError("dupping stdin"); if (!getenv("LESS")) setenv("LESS", "FRSXMK", 1); + restoreSignals(); if (pager) execl("/bin/sh", "sh", "-c", pager, NULL); execlp("pager", "pager", NULL); @@ -331,6 +316,8 @@ RunPager::RunPager() throw SysError(format("executing ‘%1%’") % pager); }); + pid.setKillSignal(SIGINT); + if (dup2(toPager.writeSide.get(), STDOUT_FILENO) == -1) throw SysError("dupping stdout"); } @@ -345,7 +332,11 @@ RunPager::~RunPager() pid.wait(); } } catch (...) { - ignoreException(); + try { + pid.kill(true); + } catch (...) { + ignoreException(); + } } } |