in fork() do sys.exit() so parent knows about failures

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-03-07 11:48:41 +01:00
parent d3b9aa6769
commit 531ad2966f

View file

@ -177,28 +177,25 @@ def configinstall_onehost(host, args, mode, parallel):
context.cleanup() context.cleanup()
except cdist.Error as e: except cdist.Error as e:
log.error(e) if parallel:
return False log.error(e)
except KeyboardInterrupt: sys.exit(1)
# Do not care in sequential mode, catch in parallel mode
if not parallel:
raise
else: else:
# Catch here, above does not need to know about our errors raise
return False
return True except KeyboardInterrupt:
# Ignore in parallel mode, we are existing anyway
if parallel:
sys.exit(0)
# Pass back to controlling code in sequential mode
else:
raise
def emulator(): def emulator():
"""Prepare and run emulator""" """Prepare and run emulator"""
try: import cdist.emulator
import cdist.emulator emulator = cdist.emulator.Emulator(sys.argv)
emulator = cdist.emulator.Emulator(sys.argv) return emulator.run()
emulator.run()
except cdist.Error as e:
log.error(e)
sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":
# Sys is needed for sys.exit() # Sys is needed for sys.exit()
@ -213,9 +210,8 @@ if __name__ == "__main__":
cdistpythonversion = '3.2' cdistpythonversion = '3.2'
if sys.version < cdistpythonversion: if sys.version < cdistpythonversion:
print('Cdist requires Python >= ' + cdistpythonversion + raise cdist.Error('Cdist requires Python >= ' + cdistpythonversion +
' on the source host.') ' on the source host.')
sys.exit(1)
# Ensure our /lib/ is included into PYTHON_PATH # Ensure our /lib/ is included into PYTHON_PATH
sys.path.insert(0, os.path.abspath( sys.path.insert(0, os.path.abspath(
@ -236,6 +232,10 @@ if __name__ == "__main__":
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
except cdist.Error as e:
log.error(e)
exit_code = 1
# Determine exit code by return value of function # Determine exit code by return value of function
if not run: if not run:
exit_code = 1 exit_code = 1