diff options
Diffstat (limited to 'selftest')
-rw-r--r-- | selftest/target/samba.py | 29 | ||||
-rw-r--r-- | selftest/tests/test_samba.py | 4 |
2 files changed, 31 insertions, 2 deletions
diff --git a/selftest/target/samba.py b/selftest/target/samba.py index 3d63fe58db..1ea156c003 100644 --- a/selftest/target/samba.py +++ b/selftest/target/samba.py @@ -5,9 +5,7 @@ import os import sys -import warnings -from selftest.target import Target def bindir_path(binary_mapping, bindir, path): """Find the executable to use. @@ -94,3 +92,30 @@ def write_krb5_conf(f, realm, dnsname, domain, kdc_ipv4, tlsdir=None, pkinit_anchors = FILE:%(tlsdir)s/ca.pem """ % {"tlsdir": tlsdir}) + + +def cleanup_child(pid, name, outf=None): + """Cleanup a child process. + + :param pid: Parent pid process to be passed to waitpid() + :param name: Name to use when referring to process + :param outf: File-like object to write to (defaults to stderr) + :return: Child pid + """ + if outf is None: + outf = sys.stderr + (childpid, status) = os.waitpid(pid, os.WNOHANG) + if childpid == 0: + pass + elif childpid < 0: + outf.write("%s child process %d isn't here any more.\n" % (name, pid)) + return childpid + elif status & 127: + if status & 128: + core_status = 'with' + else: + core_status = 'without' + outf.write("%s child process %d, died with signal %d, %s coredump.\n" % (name, childpid, (status & 127), core_status)) + else: + outf.write("%s child process %d exited with value %d.\n" % (name, childpid, status >> 8)) + return childpid diff --git a/selftest/tests/test_samba.py b/selftest/tests/test_samba.py index 6fe1efefaf..f06d846deb 100644 --- a/selftest/tests/test_samba.py +++ b/selftest/tests/test_samba.py @@ -19,12 +19,16 @@ """Tests for selftest.target.samba.""" +import os +import sys + from cStringIO import StringIO from selftest.tests import TestCase from selftest.target.samba import ( bindir_path, + cleanup_child, mk_realms_stanza, write_krb5_conf, ) |