From f2bfbda312ac92de3656ff3ae284a7ec82e59e74 Mon Sep 17 00:00:00 2001 From: Taiju Tsuiki Date: Sat, 10 Jan 2015 07:19:11 +0900 Subject: Check pending SIGINT after ppoll/pselect ppoll/pselect prioritizes file descriptor events over a signal delivery. So a flood of events prevents ninja from reacting keyboard interruption by the user. This CL adds a check for pending keyboard interruptions after file descriptor events. --- src/subprocess-posix.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc index 743e406..40c9ae1 100644 --- a/src/subprocess-posix.cc +++ b/src/subprocess-posix.cc @@ -25,9 +25,24 @@ #include "util.h" +namespace { + +bool HasPendingInterruption() { + sigset_t pending; + sigemptyset(&pending); + if (sigpending(&pending) == -1) { + perror("ninja: sigpending"); + return false; + } + return sigismember(&pending, SIGINT); +} + +} // anonymous namespace + Subprocess::Subprocess(bool use_console) : fd_(-1), pid_(-1), use_console_(use_console) { } + Subprocess::~Subprocess() { if (fd_ >= 0) close(fd_); @@ -209,6 +224,9 @@ bool SubprocessSet::DoWork() { return interrupted_; } + if (HasPendingInterruption()) + return true; + nfds_t cur_nfd = 0; for (vector::iterator i = running_.begin(); i != running_.end(); ) { @@ -256,6 +274,9 @@ bool SubprocessSet::DoWork() { return interrupted_; } + if (HasPendingInterruption()) + return true; + for (vector::iterator i = running_.begin(); i != running_.end(); ) { int fd = (*i)->fd_; -- cgit v0.12