Handle SIGINT etc. via a sigwait() signal handler thread

This allows other threads to install callbacks that run in a regular,
non-signal context. In particular, we can use this to signal the
downloader thread to quit.

Closes #1183.
This commit is contained in:
Eelco Dolstra 2017-01-17 18:21:02 +01:00
parent c0d55f9183
commit cc3b93c991
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
4 changed files with 101 additions and 28 deletions

View file

@ -24,12 +24,6 @@
namespace nix {
static void sigintHandler(int signo)
{
_isInterrupted = 1;
}
static bool gcWarning = true;
void printGCWarning()
@ -120,19 +114,11 @@ void initNix()
settings.processEnvironment();
settings.loadConfFile();
/* Catch SIGINT. */
struct sigaction act;
act.sa_handler = sigintHandler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(SIGINT, &act, 0))
throw SysError("installing handler for SIGINT");
if (sigaction(SIGTERM, &act, 0))
throw SysError("installing handler for SIGTERM");
if (sigaction(SIGHUP, &act, 0))
throw SysError("installing handler for SIGHUP");
startSignalHandlerThread();
/* Ignore SIGPIPE. */
struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_handler = SIG_IGN;
act.sa_flags = 0;
if (sigaction(SIGPIPE, &act, 0))