From cc3b93c991e04aff49a44dbced53f070a06f426e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 17 Jan 2017 18:21:02 +0100 Subject: 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. --- src/libmain/shared.cc | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'src/libmain/shared.cc') diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 0c6e3fb76d64..44579a236774 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -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)) -- cgit 1.4.1