diff options
Diffstat (limited to 'src/libmain')
-rw-r--r-- | src/libmain/shared.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 24bedb3fb63b..17d4dda6703a 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -12,6 +12,12 @@ extern "C" { #include "config.h" +void sigintHandler(int signo) +{ + _isInterrupted = 1; +} + + /* Initialize and reorder arguments, then call the actual argument processor. */ static void initAndRun(int argc, char * * argv) @@ -23,6 +29,15 @@ static void initAndRun(int argc, char * * argv) nixStateDir = (string) NIX_STATE_DIR; nixDBPath = (string) NIX_STATE_DIR + "/db"; + /* Catch SIGINT. */ + struct sigaction act, oact; + act.sa_handler = sigintHandler; + sigfillset(&act.sa_mask); + act.sa_flags = 0; + if (sigaction(SIGINT, &act, &oact)) + throw SysError("installing handler for SIGINT"); + printMsg(lvlError, "SIG HANDLER INSTALLED"); + /* Put the arguments in a vector. */ Strings args, remaining; while (argc--) args.push_back(*argv++); |