diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2012-03-24 00:40:49 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2012-03-24 04:52:59 +0100 |
commit | ae9b5add1e4c64b578915f35fc23110b686262fb (patch) | |
tree | 3506a3b5fecfaf77e17ae594417bb048a810f6c3 | |
parent | 99b4d52633a9c099c31254b6ed59122261414a67 (diff) | |
download | samba-ae9b5add1e4c64b578915f35fc23110b686262fb.tar.gz samba-ae9b5add1e4c64b578915f35fc23110b686262fb.tar.bz2 samba-ae9b5add1e4c64b578915f35fc23110b686262fb.zip |
selftest.py: Add cleanup_pid.
Autobuild-User: Jelmer Vernooij <jelmer@samba.org>
Autobuild-Date: Sat Mar 24 04:52:59 CET 2012 on sn-devel-104
-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, ) |