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/pathlocks.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/libstore/pathlocks.cc') diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 321e965bb..d4f980c64 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -19,11 +19,14 @@ bool lockFile(int fd, LockType lockType, bool wait) lock.l_len = 0; /* entire file */ if (wait) { - while (fcntl(fd, F_SETLKW, &lock) != 0) + while (fcntl(fd, F_SETLKW, &lock) != 0) { + checkInterrupt(); if (errno != EINTR) throw SysError(format("acquiring/releasing lock")); + } } else { while (fcntl(fd, F_SETLK, &lock) != 0) { + checkInterrupt(); if (errno == EACCES || errno == EAGAIN) return false; if (errno != EINTR) throw SysError(format("acquiring/releasing lock")); @@ -55,6 +58,7 @@ PathLocks::PathLocks(const PathSet & _paths) /* Acquire the lock for each path. */ for (Paths::iterator i = paths.begin(); i != paths.end(); i++) { + checkInterrupt(); Path path = *i; Path lockPath = path + ".lock"; @@ -87,6 +91,7 @@ PathLocks::~PathLocks() close(*i); for (Paths::iterator i = paths.begin(); i != paths.end(); i++) { + checkInterrupt(); if (deletePaths) { /* This is not safe in general! */ unlink(i->c_str()); -- cgit v1.2.3