Skip to content

Commit

Permalink
Display daemon output in Python test scripts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greghudson committed Aug 5, 2019
1 parent dd402f9 commit 97b79e9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/util/k5test.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@
"""

import atexit
import fcntl
import optparse
import os
import shlex
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 97b79e9

Please sign in to comment.