aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2020-03-26 14:14:24 -0400
committerJake Hunsaker <jhunsake@redhat.com>2020-04-08 09:27:16 -0400
commit5b7717775ca8b26a1fde76a163d604f40d724721 (patch)
treef21ce4d7e1466d08d66f83cc1b9bc9030cb6a0ce
parent6dabc82e085e418e69db8cd03fc56fd9c8759351 (diff)
downloadsos-5b7717775ca8b26a1fde76a163d604f40d724721.tar.gz
[soscomponent] Add exit handling to SoSComponent
Adds the exit handling from SoSReport() directly into SoSComponent() Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/__init__.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/sos/__init__.py b/sos/__init__.py
index 49a753be..10f67b93 100644
--- a/sos/__init__.py
+++ b/sos/__init__.py
@@ -62,6 +62,14 @@ class SoSComponent():
self.parser = parser
self.args = parsed_args
self.cmdline = cmdline_args
+ self.exit_process = False
+
+ try:
+ import signal
+ signal.signal(signal.SIGTERM, self.get_exit_handler())
+ except Exception:
+ pass
+
# update args from component's arg_defaults defintion
self._arg_defaults.update(self.arg_defaults)
self.opts = self.load_options()
@@ -71,6 +79,15 @@ class SoSComponent():
self.tempfile_util = TempFileUtil(self.tmpdir)
self._setup_logging()
+ def get_exit_handler(self):
+ def exit_handler(signum, frame):
+ self.exit_process = True
+ self._exit()
+ return exit_handler
+
+ def _exit(self, error=0):
+ raise SystemExit(error)
+
@classmethod
def add_parser_options(cls, parser):
"""This should be overridden by each subcommand to add its own unique