From efd02682c7cfb054490308443f7f9facf83363b5 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 13 Nov 2012 13:24:37 -0500 Subject: clean up exit to single function call --- cloudinit/config/cc_power_state_change.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'cloudinit/config/cc_power_state_change.py') diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py index 7f6e780d..22f1aade 100644 --- a/cloudinit/config/cc_power_state_change.py +++ b/cloudinit/config/cc_power_state_change.py @@ -28,6 +28,8 @@ import time frequency = PER_INSTANCE +EXIT_FAIL = 254 + def handle(_name, cfg, _cloud, log, _args): @@ -90,14 +92,19 @@ def load_power_state(cfg): return (args, timeout) +def doexit(sysexit): + os._exit(sysexit) # pylint: disable=W0212 + + def execmd(exe_args, output=None, data_in=None): try: proc = subprocess.Popen(exe_args, stdin=subprocess.PIPE, stdout=output, stderr=subprocess.STDOUT) proc.communicate(data_in) + ret = proc.returncode except Exception: - sys.exit(254) - sys.exit(proc.returncode()) + doexit(EXIT_FAIL) + doexit(ret) def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args): @@ -112,7 +119,7 @@ def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args): def fatal(msg): if log: log.warn(msg) - sys.exit(254) + doexit(EXIT_FAIL) while True: if time.time() > end_time: -- cgit v1.2.3