krb5 commit: Display daemon output in Python test scripts
Greg Hudson <[email protected]>
| Newsgroups | gmane.comp.encryption.kerberos.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://github.com/krb5/krb5/commit/97b79e95e4fed3ccd825bc416e85509c0a1b3fff commit 97b79e95e4fed3ccd825bc416e85509c0a1b3fff Author: Greg Hudson <[email protected]> Date: Sat Aug 3 12:42:26 2019 -0400 Display daemon output in Python test scripts In k5test.py, if a daemon process exits before we terminate it, display the exit status. If a daemon process generates output beyond the sentinel, display the output before terminating the process. src/util/k5test.py | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/src/util/k5test.py b/src/util/k5test.py index da2782e..e4191bf 100644 --- a/src/util/k5test.py +++ b/src/util/k5test.py @@ -371,6 +371,7 @@ command-line flags. These are documented in the --help output. """ import atexit +import fcntl import optparse import os import shlex @@ -471,6 +472,7 @@ def _onexit(): sys.stdout.flush() sys.stdin.readline() for proc in _daemons: + check_daemon(proc) os.kill(proc.pid, signal.SIGTERM) if not _success: print @@ -812,7 +814,26 @@ def _start_daemon(args, env, sentinel): return proc +# Check a daemon's status prior to terminating it. Display its return +# code if it already exited, and display any output it has generated. +def check_daemon(proc): + code = proc.poll() + if code is not None: + output('*** Daemon pid %d exited with code %d\n' % (proc.pid, code)) + + flags = fcntl.fcntl(proc.stdout, fcntl.F_GETFL) + fcntl.fcntl(proc.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK) + try: + out = proc.stdout.read() + except: + return + + output('*** Daemon pid %d output:\n' % proc.pid) + output(out) + + def stop_daemon(proc): + check_daemon(proc) output('*** Terminating process %d\n' % proc.pid) os.kill(proc.pid, signal.SIGTERM) proc.wait()