nix repl: Fix Ctrl-C

This commit is contained in:
Eelco Dolstra 2017-04-25 19:19:15 +02:00
parent 23aa1619da
commit 6734c18c99
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -217,6 +217,13 @@ bool NixRepl::getLine(string & input, const char * prompt)
if (sigaction(SIGINT, &act, &old)) if (sigaction(SIGINT, &act, &old))
throw SysError("installing handler for SIGINT"); throw SysError("installing handler for SIGINT");
static sigset_t savedSignalMask, set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
if (sigprocmask(SIG_UNBLOCK, &set, &savedSignalMask))
throw SysError("unblocking SIGINT");
if (sigsetjmp(sigintJmpBuf, 1)) { if (sigsetjmp(sigintJmpBuf, 1)) {
input.clear(); input.clear();
} else { } else {
@ -236,6 +243,9 @@ bool NixRepl::getLine(string & input, const char * prompt)
_isInterrupted = 0; _isInterrupted = 0;
if (sigprocmask(SIG_SETMASK, &savedSignalMask, nullptr))
throw SysError("restoring signals");
if (sigaction(SIGINT, &old, 0)) if (sigaction(SIGINT, &old, 0))
throw SysError("restoring handler for SIGINT"); throw SysError("restoring handler for SIGINT");