From 447089a5f699f085661287dec4b3d88219f67068 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 15 Jan 2004 20:23:55 +0000 Subject: * 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. --- src/libexpr/eval.cc | 2 ++ src/libexpr/nixexpr.cc | 4 ++++ src/libexpr/parser.cc | 2 ++ 3 files changed, 8 insertions(+) (limited to 'src/libexpr') diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index f6634e892..0470deee9 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -227,6 +227,8 @@ Expr evalExpr2(EvalState & state, Expr e) Expr evalExpr(EvalState & state, Expr e) { + checkInterrupt(); + startNest(nest, lvlVomit, format("evaluating expression: %1%") % e); diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 816b39dc1..dd0f5d58a 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -87,6 +87,8 @@ string aterm2String(ATerm t) ATerm bottomupRewrite(TermFun & f, ATerm e) { + checkInterrupt(); + if (ATgetType(e) == AT_APPL) { AFun fun = ATgetAFun(e); int arity = ATgetArity(fun); @@ -149,6 +151,8 @@ Expr makeAttrs(const ATermMap & attrs) Expr substitute(const ATermMap & subs, Expr e) { + checkInterrupt(); + ATMatcher m; string s; diff --git a/src/libexpr/parser.cc b/src/libexpr/parser.cc index b9e79e13d..83b656342 100644 --- a/src/libexpr/parser.cc +++ b/src/libexpr/parser.cc @@ -26,6 +26,8 @@ struct Cleanup : TermFun virtual ATerm operator () (ATerm e) { + checkInterrupt(); + ATMatcher m; string s; -- cgit v1.2.3