mirror of
https://github.com/NixOS/nix
synced 2025-06-27 00:11:17 +02:00
Restore default signal handling in child processes
In particular, this fixes Ctrl-C in nix-shell sessions.
This commit is contained in:
parent
583ff4ec46
commit
7a65b2470e
7 changed files with 33 additions and 35 deletions
|
@ -860,6 +860,8 @@ string runProgram(Path program, bool searchPath, const Strings & args,
|
|||
Strings args_(args);
|
||||
args_.push_front(program);
|
||||
|
||||
restoreSignals();
|
||||
|
||||
if (searchPath)
|
||||
execvp(program.c_str(), stringsToCharPtrs(args_).data());
|
||||
else
|
||||
|
@ -909,16 +911,6 @@ void closeOnExec(int fd)
|
|||
}
|
||||
|
||||
|
||||
void restoreSIGPIPE()
|
||||
{
|
||||
struct sigaction act;
|
||||
act.sa_handler = SIG_DFL;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
if (sigaction(SIGPIPE, &act, 0)) throw SysError("resetting SIGPIPE");
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
@ -1218,19 +1210,31 @@ void triggerInterrupt()
|
|||
}
|
||||
}
|
||||
|
||||
static sigset_t savedSignalMask;
|
||||
|
||||
void startSignalHandlerThread()
|
||||
{
|
||||
if (sigprocmask(SIG_BLOCK, nullptr, &savedSignalMask))
|
||||
throw SysError("quering signal mask");
|
||||
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGINT);
|
||||
sigaddset(&set, SIGTERM);
|
||||
sigaddset(&set, SIGHUP);
|
||||
sigaddset(&set, SIGPIPE);
|
||||
if (pthread_sigmask(SIG_BLOCK, &set, nullptr))
|
||||
throw SysError("blocking signals");
|
||||
|
||||
std::thread(signalHandlerThread, set).detach();
|
||||
}
|
||||
|
||||
void restoreSignals()
|
||||
{
|
||||
if (sigprocmask(SIG_SETMASK, &savedSignalMask, nullptr))
|
||||
throw SysError("restoring signals");
|
||||
}
|
||||
|
||||
/* RAII helper to automatically deregister a callback. */
|
||||
struct InterruptCallbackImpl : InterruptCallback
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue