summaryrefslogtreecommitdiffstats
path: root/src/subprocess-posix.cc
diff options
context:
space:
mode:
authorNicolas Despres <nicolas.despres@gmail.com>2014-04-16 08:05:25 (GMT)
committerNicolas Despres <nicolas.despres@gmail.com>2015-04-24 14:40:03 (GMT)
commitb4bc5cf7c924be251a5c8abdfca58f47c3f5c185 (patch)
treead8fd16c3285fb8582734148663b8ce18d7cc77c /src/subprocess-posix.cc
parentb2b8f3a12d3323c4273aa63460f482d6f7f03211 (diff)
downloadNinja-b4bc5cf7c924be251a5c8abdfca58f47c3f5c185.zip
Ninja-b4bc5cf7c924be251a5c8abdfca58f47c3f5c185.tar.gz
Ninja-b4bc5cf7c924be251a5c8abdfca58f47c3f5c185.tar.bz2
Allow SIGTERM for interruption.
Default signal sent by many other programs (mainly kill(1)) to gently terminates another one is SIGTERM.
Diffstat (limited to 'src/subprocess-posix.cc')
-rw-r--r--src/subprocess-posix.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc
index cc8bff6..c784a39 100644
--- a/src/subprocess-posix.cc
+++ b/src/subprocess-posix.cc
@@ -74,7 +74,9 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
// Track which fd we use to report errors on.
int error_pipe = output_pipe[1];
do {
- if (sigaction(SIGINT, &set->old_act_, 0) < 0)
+ if (sigaction(SIGINT, &set->old_int_act_, 0) < 0)
+ break;
+ if (sigaction(SIGTERM, &set->old_term_act_, 0) < 0)
break;
if (sigprocmask(SIG_SETMASK, &set->old_mask_, 0) < 0)
break;
@@ -148,7 +150,7 @@ ExitStatus Subprocess::Finish() {
if (exit == 0)
return ExitSuccess;
} else if (WIFSIGNALED(status)) {
- if (WTERMSIG(status) == SIGINT)
+ if (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGTERM)
return ExitInterrupted;
}
return ExitFailure;
@@ -173,20 +175,25 @@ SubprocessSet::SubprocessSet() {
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
+ sigaddset(&set, SIGTERM);
if (sigprocmask(SIG_BLOCK, &set, &old_mask_) < 0)
Fatal("sigprocmask: %s", strerror(errno));
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = SetInterruptedFlag;
- if (sigaction(SIGINT, &act, &old_act_) < 0)
+ if (sigaction(SIGINT, &act, &old_int_act_) < 0)
+ Fatal("sigaction: %s", strerror(errno));
+ if (sigaction(SIGTERM, &act, &old_term_act_) < 0)
Fatal("sigaction: %s", strerror(errno));
}
SubprocessSet::~SubprocessSet() {
Clear();
- if (sigaction(SIGINT, &old_act_, 0) < 0)
+ if (sigaction(SIGINT, &old_int_act_, 0) < 0)
+ Fatal("sigaction: %s", strerror(errno));
+ if (sigaction(SIGTERM, &old_term_act_, 0) < 0)
Fatal("sigaction: %s", strerror(errno));
if (sigprocmask(SIG_SETMASK, &old_mask_, 0) < 0)
Fatal("sigprocmask: %s", strerror(errno));