summaryrefslogtreecommitdiffstats
path: root/src/subprocess-posix.cc
diff options
context:
space:
mode:
authorNicolas Despres <nicolas.despres@gmail.com>2015-04-29 07:33:37 (GMT)
committerNicolas Despres <nicolas.despres@gmail.com>2015-09-20 13:04:42 (GMT)
commit23de4b25e9285d24cfa21fbed5acd105492866d8 (patch)
treeb5e45ec170acfe31e030573def3b4094f22dd113 /src/subprocess-posix.cc
parenta48434493d69085aa6fc0c002180ace555cad592 (diff)
downloadNinja-23de4b25e9285d24cfa21fbed5acd105492866d8.zip
Ninja-23de4b25e9285d24cfa21fbed5acd105492866d8.tar.gz
Ninja-23de4b25e9285d24cfa21fbed5acd105492866d8.tar.bz2
Cleanup build on SIGHUP.
SIGHUP is sent when the connection hang up (i.e. when the terminal window is closed or the ssh connection is closed).
Diffstat (limited to 'src/subprocess-posix.cc')
-rw-r--r--src/subprocess-posix.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc
index f3baec2..2ddc709 100644
--- a/src/subprocess-posix.cc
+++ b/src/subprocess-posix.cc
@@ -64,6 +64,8 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
break;
if (sigaction(SIGTERM, &set->old_term_act_, 0) < 0)
break;
+ if (sigaction(SIGHUP, &set->old_hup_act_, 0) < 0)
+ break;
if (sigprocmask(SIG_SETMASK, &set->old_mask_, 0) < 0)
break;
@@ -136,7 +138,8 @@ ExitStatus Subprocess::Finish() {
if (exit == 0)
return ExitSuccess;
} else if (WIFSIGNALED(status)) {
- if (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGTERM)
+ if (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGTERM
+ || WTERMSIG(status) == SIGHUP)
return ExitInterrupted;
}
return ExitFailure;
@@ -167,6 +170,8 @@ void SubprocessSet::HandlePendingInterruption() {
interrupted_ = SIGINT;
else if (sigismember(&pending, SIGTERM))
interrupted_ = SIGTERM;
+ else if (sigismember(&pending, SIGHUP))
+ interrupted_ = SIGHUP;
}
SubprocessSet::SubprocessSet() {
@@ -174,6 +179,7 @@ SubprocessSet::SubprocessSet() {
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
+ sigaddset(&set, SIGHUP);
if (sigprocmask(SIG_BLOCK, &set, &old_mask_) < 0)
Fatal("sigprocmask: %s", strerror(errno));
@@ -184,6 +190,8 @@ SubprocessSet::SubprocessSet() {
Fatal("sigaction: %s", strerror(errno));
if (sigaction(SIGTERM, &act, &old_term_act_) < 0)
Fatal("sigaction: %s", strerror(errno));
+ if (sigaction(SIGHUP, &act, &old_hup_act_) < 0)
+ Fatal("sigaction: %s", strerror(errno));
}
SubprocessSet::~SubprocessSet() {
@@ -193,6 +201,8 @@ SubprocessSet::~SubprocessSet() {
Fatal("sigaction: %s", strerror(errno));
if (sigaction(SIGTERM, &old_term_act_, 0) < 0)
Fatal("sigaction: %s", strerror(errno));
+ if (sigaction(SIGHUP, &old_hup_act_, 0) < 0)
+ Fatal("sigaction: %s", strerror(errno));
if (sigprocmask(SIG_SETMASK, &old_mask_, 0) < 0)
Fatal("sigprocmask: %s", strerror(errno));
}