summaryrefslogtreecommitdiff
path: root/src/buildstream
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-11-08 14:27:57 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-11-13 16:01:32 +0000
commit928d66b094eb528f98666c15f4ee37c5c5863244 (patch)
treeb42ccaa234aee722717763cca03d4bed29a22c45 /src/buildstream
parenteae8bd1e40ed11b09a01b8a53d92de01176df37a (diff)
downloadbuildstream-928d66b094eb528f98666c15f4ee37c5c5863244.tar.gz
job.py: handle SIGTERM gracefully
This allows showing a nice info to the user and stop showing that the return code was an unexpected 255.
Diffstat (limited to 'src/buildstream')
-rw-r--r--src/buildstream/_scheduler/jobs/job.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/buildstream/_scheduler/jobs/job.py b/src/buildstream/_scheduler/jobs/job.py
index 00de9053c..9570fea62 100644
--- a/src/buildstream/_scheduler/jobs/job.py
+++ b/src/buildstream/_scheduler/jobs/job.py
@@ -45,6 +45,7 @@ class _ReturnCode(FastEnum):
FAIL = 1
PERM_FAIL = 2
SKIPPED = 3
+ TERMINATED = 4
# JobStatus:
@@ -455,6 +456,13 @@ class Job():
status = JobStatus.SKIPPED
elif returncode in (_ReturnCode.FAIL, _ReturnCode.PERM_FAIL):
status = JobStatus.FAIL
+ elif returncode == _ReturnCode.TERMINATED:
+ if self._terminated:
+ self.message(MessageType.INFO, "Process was terminated")
+ else:
+ self.message(MessageType.ERROR, "Process was terminated unexpectedly")
+
+ status = JobStatus.FAIL
else:
status = JobStatus.FAIL
@@ -714,6 +722,12 @@ class ChildJob():
with _signals.suspendable(stop_time, resume_time), \
self._messenger.recorded_messages(self._logfile, self._logdir) as filename:
+ # Graciously handle sigterms.
+ def handle_sigterm(_signum, _sigframe):
+ self._child_shutdown(_ReturnCode.TERMINATED)
+
+ signal.signal(signal.SIGTERM, handle_sigterm)
+
self.message(MessageType.START, self.action_name, logfile=filename)
try: