Commit d6687526 authored by Paul Winkler's avatar Paul Winkler

Merge branches/slinkp-zopectl-exitcode-143813: Fixes bug 143813, zopectl...

Merge branches/slinkp-zopectl-exitcode-143813: Fixes bug 143813, zopectl should exit non-zero if child processes fail.
parent 8962125f
...@@ -147,6 +147,8 @@ class ZopeCtlOptions(ZDOptions): ...@@ -147,6 +147,8 @@ class ZopeCtlOptions(ZDOptions):
class ZopeCmd(ZDCmd): class ZopeCmd(ZDCmd):
_exitstatus = 0
def _get_override(self, opt, name, svalue=None, flag=0): def _get_override(self, opt, name, svalue=None, flag=0):
# Suppress the config file, and pass all configuration via the # Suppress the config file, and pass all configuration via the
# command line. This avoids needing to specialize the zdrun # command line. This avoids needing to specialize the zdrun
...@@ -265,7 +267,7 @@ class ZopeCmd(ZDCmd): ...@@ -265,7 +267,7 @@ class ZopeCmd(ZDCmd):
cmd += '[sys.argv.append(x) for x in %s];' % argv cmd += '[sys.argv.append(x) for x in %s];' % argv
cmd += 'import Zope2; app=Zope2.app(); execfile(\'%s\')' % script cmd += 'import Zope2; app=Zope2.app(); execfile(\'%s\')' % script
cmdline = self.get_startup_cmd(self.options.python, cmd) cmdline = self.get_startup_cmd(self.options.python, cmd)
os.system(cmdline) self._exitstatus = os.system(cmdline)
def help_run(self): def help_run(self):
print "run <script> [args] -- run a Python script with the Zope " print "run <script> [args] -- run a Python script with the Zope "
...@@ -335,10 +337,11 @@ class ZopeCmd(ZDCmd): ...@@ -335,10 +337,11 @@ class ZopeCmd(ZDCmd):
# Parent process running (execv replaces process in child # Parent process running (execv replaces process in child
while True: while True:
try: try:
os.waitpid(pid, 0) pid, status = os.waitpid(pid, 0)
except (OSError, KeyboardInterrupt): except (OSError, KeyboardInterrupt):
continue continue
else: else:
self._exitstatus = status
break break
def help_test(self): def help_test(self):
...@@ -364,6 +367,8 @@ def main(args=None): ...@@ -364,6 +367,8 @@ def main(args=None):
print "program:", " ".join(options.program) print "program:", " ".join(options.program)
c.do_status() c.do_status()
c.cmdloop() c.cmdloop()
else:
return min(c._exitstatus, 1)
def _ignoreSIGCHLD(*unused): def _ignoreSIGCHLD(*unused):
while 1: while 1:
...@@ -393,4 +398,5 @@ if __name__ == "__main__": ...@@ -393,4 +398,5 @@ if __name__ == "__main__":
# SIGCHILD is unset, just don't bother registering a SIGCHILD # SIGCHILD is unset, just don't bother registering a SIGCHILD
# signal handler at all. # signal handler at all.
signal.signal(signal.SIGCHLD, _ignoreSIGCHLD) signal.signal(signal.SIGCHLD, _ignoreSIGCHLD)
main() exitstatus = main()
sys.exit(exitstatus)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment