Don't try to handle SIGINT

It just makes things unnecessarily complicated. We can just exit
without cleaning anything up, since the only thing to do is unmark
builds and build steps as busy. But we can do that by having systemd
call "hydra-queue-runner --unlock" from ExecStopPost.
This commit is contained in:
Eelco Dolstra 2015-06-10 15:55:46 +02:00
parent a4fb93c119
commit d72a88b562

View file

@ -27,40 +27,6 @@ bool has(const C & c, const V & v)
} }
std::mutex exitRequestMutex;
std::condition_variable exitRequest;
std::atomic<bool> exitRequested(false);
static std::atomic_int _int(0);
void sigintHandler(int signo)
{
_int = 1;
}
void signalThread()
{
struct sigaction act;
act.sa_handler = sigintHandler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(SIGINT, &act, 0))
throw SysError("installing handler for SIGINT");
while (true) {
sleep(1000000);
if (_int) break;
}
{
std::lock_guard<std::mutex> lock(exitRequestMutex);
exitRequested = true;
}
exitRequest.notify_all();
}
typedef enum { typedef enum {
bsSuccess = 0, bsSuccess = 0,
bsFailed = 1, bsFailed = 1,
@ -402,7 +368,7 @@ void State::queueMonitor()
{ {
auto store = openStore(); // FIXME: pool auto store = openStore(); // FIXME: pool
while (!exitRequested) { while (true) {
getQueuedBuilds(store); getQueuedBuilds(store);
{ {
@ -685,7 +651,7 @@ void State::makeRunnable(Step::ptr step)
void State::dispatcher() void State::dispatcher()
{ {
while (!exitRequested) { while (true) {
printMsg(lvlError, "dispatcher woken up"); printMsg(lvlError, "dispatcher woken up");
{ {
@ -1003,25 +969,11 @@ void State::run()
auto queueMonitorThread = std::thread(&State::queueMonitor, this); auto queueMonitorThread = std::thread(&State::queueMonitor, this);
auto dispatcherThread = std::thread(&State::dispatcher, this); std::thread(&State::dispatcher, this).detach();
/* Wait for SIGINT. */
{
std::unique_lock<std::mutex> lock(exitRequestMutex);
while (!exitRequested)
exitRequest.wait(lock);
}
printMsg(lvlError, "exiting...");
/* Shut down the various threads. */
{ std::lock_guard<std::mutex> lock(queueMonitorMutex); } // barrier
queueMonitorWakeup.notify_all();
queueMonitorThread.join(); queueMonitorThread.join();
wakeDispatcher(); printMsg(lvlError, "exiting...");
dispatcherThread.join();
printMsg(lvlError, format("psql connections = %1%") % dbPool.count()); printMsg(lvlError, format("psql connections = %1%") % dbPool.count());
} }
@ -1031,15 +983,9 @@ int main(int argc, char * * argv)
return handleExceptions(argv[0], [&]() { return handleExceptions(argv[0], [&]() {
initNix(); initNix();
std::thread(signalThread).detach(); signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
/* Ignore signals. This is inherited by the other threads. */ signal(SIGHUP, SIG_DFL);
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGHUP);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
sigprocmask(SIG_BLOCK, &set, NULL);
settings.buildVerbosity = lvlVomit; settings.buildVerbosity = lvlVomit;
settings.useSubstitutes = false; settings.useSubstitutes = false;