1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

selftest: Move fork cmd args up a level

This is a fairly simple move of code and is the first step in a larger
refactor.

It doesn't matter if we build up the command args prior to the fork (we
only use them in the forked child). But moving the code means the code
to handle the fork-and-exec becomes common code that is repeated in
several places throughout Samba3.pm and Samba4.pm.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Tim Beale 2019-05-23 12:12:44 +12:00 committed by Andrew Bartlett
parent 0fd3685cfd
commit ba9323abde
2 changed files with 91 additions and 73 deletions

View File

@ -1242,6 +1242,23 @@ sub check_or_start($$$$$) {
# exit when the test script exits
pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
my $binary = Samba::bindir_path($self, "nmbd");
my @optargs = ("-d0");
if (defined($ENV{NMBD_OPTIONS})) {
@optargs = split(/ /, $ENV{NMBD_OPTIONS});
}
my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
if(defined($ENV{NMBD_VALGRIND})) {
@preargs = split(/ /, $ENV{NMBD_VALGRIND});
}
my @args = ("-F", "--no-process-group",
"-s", $env_vars->{SERVERCONFFILE},
"-l", $env_vars->{LOGDIR});
if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
push(@args, "--log-stdout");
}
my @full_cmd = (@preargs, $binary, @args, @optargs);
unlink($env_vars->{NMBD_TEST_LOG});
print "STARTING NMBD...";
my $pid = fork();
@ -1264,32 +1281,35 @@ sub check_or_start($$$$$) {
exit 0;
}
$ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
my @optargs = ("-d0");
if (defined($ENV{NMBD_OPTIONS})) {
@optargs = split(/ /, $ENV{NMBD_OPTIONS});
}
my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
if(defined($ENV{NMBD_VALGRIND})) {
@preargs = split(/ /, $ENV{NMBD_VALGRIND});
}
my @args = ("-F", "--no-process-group",
"-s", $env_vars->{SERVERCONFFILE},
"-l", $env_vars->{LOGDIR});
if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
push(@args, "--log-stdout");
}
$ENV{MAKE_TEST_BINARY} = $binary;
close($env_vars->{STDIN_PIPE});
open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
exec(@full_cmd)
or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
}
$env_vars->{NMBD_TL_PID} = $pid;
write_pid($env_vars, "nmbd", $pid);
print "DONE\n";
$binary = Samba::bindir_path($self, "winbindd");
@optargs = ("-d0");
if (defined($ENV{WINBINDD_OPTIONS})) {
@optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
}
@preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
if(defined($ENV{WINBINDD_VALGRIND})) {
@preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
}
@args = ("-F", "--no-process-group",
"-s", $env_vars->{SERVERCONFFILE},
"-l", $env_vars->{LOGDIR});
if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
push(@args, "--stdout");
}
@full_cmd = (@preargs, $binary, @args, @optargs);
unlink($env_vars->{WINBINDD_TEST_LOG});
print "STARTING WINBINDD...";
$pid = fork();
@ -1311,32 +1331,35 @@ sub check_or_start($$$$$) {
exit 0;
}
$ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
my @optargs = ("-d0");
if (defined($ENV{WINBINDD_OPTIONS})) {
@optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
}
my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
if(defined($ENV{WINBINDD_VALGRIND})) {
@preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
}
my @args = ("-F", "--no-process-group",
"-s", $env_vars->{SERVERCONFFILE},
"-l", $env_vars->{LOGDIR});
if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
push(@args, "--stdout");
}
$ENV{MAKE_TEST_BINARY} = $binary;
close($env_vars->{STDIN_PIPE});
open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
exec(@full_cmd)
or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
}
$env_vars->{WINBINDD_TL_PID} = $pid;
write_pid($env_vars, "winbindd", $pid);
print "DONE\n";
$binary = Samba::bindir_path($self, "smbd");
@optargs = ("-d0");
if (defined($ENV{SMBD_OPTIONS})) {
@optargs = split(/ /, $ENV{SMBD_OPTIONS});
}
@preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
if(defined($ENV{SMBD_VALGRIND})) {
@preargs = split(/ /,$ENV{SMBD_VALGRIND});
}
@args = ("-F", "--no-process-group",
"-s", $env_vars->{SERVERCONFFILE},
"-l", $env_vars->{LOGDIR});
if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
push(@args, "--log-stdout");
}
@full_cmd = (@preargs, $binary, @args, @optargs);
unlink($env_vars->{SMBD_TEST_LOG});
print "STARTING SMBD...";
$pid = fork();
@ -1358,26 +1381,12 @@ sub check_or_start($$$$$) {
exit 0;
}
$ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
my @optargs = ("-d0");
if (defined($ENV{SMBD_OPTIONS})) {
@optargs = split(/ /, $ENV{SMBD_OPTIONS});
}
my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
if(defined($ENV{SMBD_VALGRIND})) {
@preargs = split(/ /,$ENV{SMBD_VALGRIND});
}
my @args = ("-F", "--no-process-group",
"-s", $env_vars->{SERVERCONFFILE},
"-l", $env_vars->{LOGDIR});
if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
push(@args, "--log-stdout");
}
$ENV{MAKE_TEST_BINARY} = $binary;
close($env_vars->{STDIN_PIPE});
open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
exec(@full_cmd)
or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
}
$env_vars->{SMBD_TL_PID} = $pid;

View File

@ -115,6 +115,22 @@ sub check_or_start($$$)
}
}
my @preargs = ();
my @optargs = ();
if (defined($ENV{SAMBA_OPTIONS})) {
@optargs = split(/ /, $ENV{SAMBA_OPTIONS});
}
if(defined($ENV{SAMBA_VALGRIND})) {
@preargs = split(/ /,$ENV{SAMBA_VALGRIND});
}
if (defined($process_model)) {
push @optargs, ("-M", $process_model);
}
my @full_cmd = (@preargs, Samba::bindir_path($self, "samba"), "-i",
"--no-process-group", "--maximum-runtime=$self->{server_maxtime}",
$env_vars->{CONFIGURATION}, @optargs);
print "STARTING SAMBA...\n";
my $pid = fork();
if ($pid == 0) {
@ -138,22 +154,11 @@ sub check_or_start($$$)
}
$ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
my @preargs = ();
my @optargs = ();
if (defined($ENV{SAMBA_OPTIONS})) {
@optargs = split(/ /, $ENV{SAMBA_OPTIONS});
}
if(defined($ENV{SAMBA_VALGRIND})) {
@preargs = split(/ /,$ENV{SAMBA_VALGRIND});
}
if (defined($process_model)) {
push @optargs, ("-M", $process_model);
}
close($env_vars->{STDIN_PIPE});
open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
exec(@preargs, Samba::bindir_path($self, "samba"), "-i", "--no-process-group", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
exec(@full_cmd) or die("Unable to start samba: $!");
}
$env_vars->{SAMBA_PID} = $pid;
print "DONE ($pid)\n";
@ -387,6 +392,20 @@ sub setup_dns_hub_internal($$$)
print RESOLV_CONF "nameserver $env->{SERVER_IPV6}\n";
close(RESOLV_CONF);
my @preargs = ();
my @args = ();
if (!defined($ENV{PYTHON})) {
push (@preargs, "env");
push (@preargs, "python");
} else {
push (@preargs, $ENV{PYTHON});
}
my $binary = "$self->{srcdir}/selftest/target/dns_hub.py";
push (@args, "$self->{server_maxtime}");
push (@args, "$env->{SERVER_IP}");
push (@args, Samba::realm_to_ip_mappings());
my @full_cmd = (@preargs, $binary, @args);
# use a pipe for stdin in the child processes. This allows
# those processes to monitor the pipe for EOF to ensure they
# exit when the test script exits
@ -406,22 +425,12 @@ sub setup_dns_hub_internal($$$)
my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/env-$hostname$.pcap";
SocketWrapper::setup_pcap($pcap_file);
my @preargs = ();
my @args = ();
if (!defined($ENV{PYTHON})) {
push (@preargs, "env");
push (@preargs, "python");
} else {
push (@preargs, $ENV{PYTHON});
}
$ENV{MAKE_TEST_BINARY} = "$self->{srcdir}/selftest/target/dns_hub.py";
push (@args, "$self->{server_maxtime}");
push (@args, "$env->{SERVER_IP}");
push (@args, Samba::realm_to_ip_mappings());
$ENV{MAKE_TEST_BINARY} = $binary;
close($env->{STDIN_PIPE});
open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args)
exec(@full_cmd)
or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
}
$env->{SAMBA_PID} = $pid;