From d715e2c2948cf642e725bee56f1f43e2395a2025 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 4 Mar 2012 17:30:45 +1100 Subject: selftest: Use fork()/exec() rather than system() This follows the Samba3.pm model for starting child processes is to use fork()/exec(). This reduces the number of processes being created by selftest.pl, and gives us more information about the child process and the running state in the parent. Andrew Bartlett --- selftest/target/Samba.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'selftest/target/Samba.pm') diff --git a/selftest/target/Samba.pm b/selftest/target/Samba.pm index 06b6472a6c..14226036a1 100644 --- a/selftest/target/Samba.pm +++ b/selftest/target/Samba.pm @@ -8,6 +8,7 @@ package Samba; use strict; use target::Samba3; use target::Samba4; +use POSIX; sub new($$$$$) { my ($classname, $bindir, $binary_mapping,$ldap, $srcdir, $server_maxtime) = @_; @@ -172,4 +173,23 @@ sub get_interface($) return $interfaces{$netbiosname}; } + +sub cleanup_child($$) +{ + my ($pid, $name) = @_; + my $childpid = waitpid($pid, WNOHANG); + if ($childpid == 0) { + } elsif ($childpid < 0) { + printf STDERR "%s child process %d isn't here any more\n", + return $childpid; + } + elsif ($? & 127) { + printf STDERR "%s child process %d, died with signal %d, %s coredump\n", + $name, $childpid, ($? & 127), ($? & 128) ? 'with' : 'without'; + } else { + printf STDERR "%s child process %d exited with value %d\n", $name, $childpid, $? >> 8; + } + return $childpid; +} + 1; -- cgit