1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 04:21:16 +02:00

* Catch SIGINT to terminate cleanly when the user tries to interrupt

Nix.  This is to prevent Berkeley DB from becoming wedged.

  Unfortunately it is not possible to throw C++ exceptions from a
  signal handler.  In fact, you can't do much of anything except
  change variables of type `volatile sig_atomic_t'.  So we set an
  interrupt flag in the signal handler and check it at various
  strategic locations in the code (by calling checkInterrupt()).
  Since this is unlikely to cover all cases (e.g., (semi-)infinite
  loops), sometimes SIGTERM may now be required to kill Nix.
This commit is contained in:
Eelco Dolstra 2004-01-15 20:23:55 +00:00
parent 08719c6c97
commit 447089a5f6
13 changed files with 86 additions and 4 deletions

View file

@ -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++);