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/libstore/normalise.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/libstore/normalise.cc') diff --git a/src/libstore/normalise.cc b/src/libstore/normalise.cc index 7ef45e292352..51f90207ead3 100644 --- a/src/libstore/normalise.cc +++ b/src/libstore/normalise.cc @@ -96,6 +96,7 @@ Path normaliseStoreExpr(const Path & _nePath, PathSet pending) for (PathSet::iterator i = ne.derivation.inputs.begin(); i != ne.derivation.inputs.end(); i++) { + checkInterrupt(); Path nfPath = normaliseStoreExpr(*i, pending); realiseClosure(nfPath, pending); /* !!! nfPath should be a root of the garbage collector while @@ -193,6 +194,7 @@ Path normaliseStoreExpr(const Path & _nePath, PathSet pending) for (Paths::iterator j = refPaths.begin(); j != refPaths.end(); j++) { + checkInterrupt(); Path path = *j; elem.refs.insert(path); if (inClosures.find(path) != inClosures.end()) @@ -209,6 +211,7 @@ Path normaliseStoreExpr(const Path & _nePath, PathSet pending) PathSet donePaths; while (!usedPaths.empty()) { + checkInterrupt(); PathSet::iterator i = usedPaths.begin(); Path path = *i; usedPaths.erase(i); @@ -291,6 +294,7 @@ void ensurePath(const Path & path, PathSet pending) for (Paths::iterator i = subPaths.begin(); i != subPaths.end(); i++) { + checkInterrupt(); try { normaliseStoreExpr(*i, pending); if (isValidPath(path)) return; @@ -337,6 +341,8 @@ static void requisitesWorker(const Path & nePath, bool includeExprs, bool includeSuccessors, PathSet & paths, PathSet & doneSet) { + checkInterrupt(); + if (doneSet.find(nePath) != doneSet.end()) return; doneSet.insert(nePath); -- cgit 1.4.1