Commit ecd75b76 authored by unknown's avatar unknown

Bug#18415 mysql-test-run.pl does not run on ActiveState perl

 - Part 1, better handling of subprocess and stdout to be done


mysql-test/lib/mtr_process.pl:
  - Dont redirect stdout if ActiveState perl since fork creates a new thread and not another process.
  - Change waitpid to allow for negative pid as we get on Windows, strange but 
    that is how it is. It should never create a process with pid -1 though.
  - Remove an "if" for cygwin that does not do anything.
  - Add "print" in the potentially hanging while loop in "start_reap_all"
  - Dont use "getpgrp" on windows.
  - Remove "sleep 2" in mtr_exit
  - Remove the initial ping of mysqld's in 'mysql_admin_shutdown', instead just start one 
    mysqladmin for each expected mysqld server and wait for them to return.
    Then perform the ping of the mysqld server's. Those ping's normally return immediately.
parent 29d7a2be
......@@ -144,17 +144,6 @@ sub spawn_impl ($$$$$$$$) {
$SIG{INT}= 'DEFAULT'; # Parent do some stuff, we don't
if ( $::glob_cygwin_shell and $mode eq 'test' )
{
# Programs started from mysqltest under Cygwin, are to
# execute them within Cygwin. Else simple things in test
# files like
# --system "echo 1 > file"
# will fail.
# FIXME not working :-(
# $ENV{'COMSPEC'}= "$::glob_cygwin_shell -c";
}
my $log_file_open_mode = '>';
if ($spawn_opts and $spawn_opts->{'append_log_file'})
......@@ -164,7 +153,15 @@ sub spawn_impl ($$$$$$$$) {
if ( $output )
{
if ( ! open(STDOUT,$log_file_open_mode,$output) )
if ( $::glob_win32_perl )
{
# Don't redirect stdout on ActiveState perl since this is
# just another thread in the same process.
# Should be fixed so that the thread that is created with fork
# executes the exe in another process and wait's for it to return.
# In the meanwhile, we get all the output from mysqld's to screen
}
elsif ( ! open(STDOUT,$log_file_open_mode,$output) )
{
mtr_child_error("can't redirect STDOUT to \"$output\": $!");
}
......@@ -216,8 +213,7 @@ sub spawn_parent_impl {
{
# Simple run of command, we wait for it to return
my $ret_pid= waitpid($pid,0);
if ( $ret_pid <= 0 )
if ( $ret_pid != $pid )
{
mtr_error("$path ($pid) got lost somehow");
}
......@@ -245,7 +241,6 @@ sub spawn_parent_impl {
# Someone terminated, don't know who. Collect
# status info first before $? is lost,
# but not $exit_value, this is flagged from
#
my $timer_name= mtr_timer_timeout($::glob_timers, $ret_pid);
if ( $timer_name )
......@@ -310,7 +305,7 @@ sub spawn_parent_impl {
$ret_pid= waitpid($pid,0);
if ( $ret_pid == -1 )
if ( $ret_pid != $pid )
{
mtr_error("$path ($pid) got lost somehow");
}
......@@ -361,7 +356,6 @@ sub mtr_kill_leftovers () {
# First, kill all masters and slaves that would conflict with
# this run. Make sure to remove the PID file, if any.
# FIXME kill IM manager first, else it will restart the servers, how?!
my @args;
for ( my $idx; $idx < 2; $idx++ )
......@@ -651,22 +645,10 @@ sub mtr_mysqladmin_shutdown {
my $adm_shutdown_tmo= shift;
my %mysql_admin_pids;
my @to_kill_specs;
# Start one "mysqladmin shutdown" for each server
foreach my $srv ( @$spec )
{
if ( mtr_ping_mysqld_server($srv->{'port'}, $srv->{'sockfile'}) )
{
push(@to_kill_specs, $srv);
}
}
foreach my $srv ( @to_kill_specs )
{
# FIXME wrong log.....
# FIXME, stderr.....
# Shutdown time must be high as slave may be in reconnect
my $args;
mtr_init_args(\$args);
......@@ -674,6 +656,7 @@ sub mtr_mysqladmin_shutdown {
mtr_add_arg($args, "--no-defaults");
mtr_add_arg($args, "--user=%s", $::opt_user);
mtr_add_arg($args, "--password=");
mtr_add_arg($args, "--silent");
if ( -e $srv->{'sockfile'} )
{
mtr_add_arg($args, "--socket=%s", $srv->{'sockfile'});
......@@ -687,26 +670,27 @@ sub mtr_mysqladmin_shutdown {
mtr_add_arg($args, "--protocol=tcp"); # Needed if no --socket
}
mtr_add_arg($args, "--connect_timeout=5");
# Shutdown time must be high as slave may be in reconnect
mtr_add_arg($args, "--shutdown_timeout=$adm_shutdown_tmo");
mtr_add_arg($args, "shutdown");
# We don't wait for termination of mysqladmin
# Start mysqladmin in paralell and wait for termination later
my $pid= mtr_spawn($::exe_mysqladmin, $args,
"", $::path_manager_log, $::path_manager_log, "",
{ append_log_file => 1 });
# Save the pid of the mysqladmin process
$mysql_admin_pids{$pid}= 1;
}
# Wait for all the started mysqladmin to exit
# As mysqladmin is such a simple program, we trust it to terminate.
# I.e. we wait blocking, and wait wait for them all before we go on.
while (keys %mysql_admin_pids)
foreach my $pid (keys %mysql_admin_pids)
{
foreach my $pid (keys %mysql_admin_pids)
{
if ( waitpid($pid,0) > 0 )
{
delete $mysql_admin_pids{$pid};
}
}
my $ret_pid= waitpid($pid,0);
# If this was any of the mysqladmin's we waited for, delete its
# pid from list
delete $mysql_admin_pids{$ret_pid} if exists $mysql_admin_pids{$ret_pid};
}
# If we trusted "mysqladmin --shutdown_timeout= ..." we could just
......@@ -721,7 +705,7 @@ sub mtr_mysqladmin_shutdown {
TIME:
while ( $timeout-- )
{
foreach my $srv ( @to_kill_specs )
foreach my $srv ( @$spec )
{
$res= 1; # We are optimistic
if ( mtr_ping_mysqld_server($srv->{'port'}, $srv->{'sockfile'}) )
......@@ -754,9 +738,9 @@ sub mtr_record_dead_children () {
my $ret_pid;
# FIXME the man page says to wait for -1 to terminate,
# but on OS X we get '0' all the time...
while ( ($ret_pid= waitpid(-1,&WNOHANG)) > 0 )
# Wait without blockinng to see if any processes had died
# -1 or 0 means there are no more procesess to wait for
while ( ($ret_pid= waitpid(-1,&WNOHANG)) != 0 and $ret_pid != -1)
{
mtr_debug("waitpid() catched exit of child $ret_pid");
foreach my $idx (0..1)
......@@ -789,7 +773,11 @@ sub start_reap_all {
# here. If a process terminated before setting $SIG{CHLD} (but after
# any attempt to waitpid() it), it will still be a zombie. So we
# have to handle any such process here.
while(waitpid(-1, &WNOHANG) > 0) { };
my $pid;
while(($pid= waitpid(-1, &WNOHANG)) != 0 and $pid != -1)
{
print "start_reap_all: pid: $pid.\n";
};
}
sub stop_reap_all {
......@@ -843,7 +831,7 @@ sub sleep_until_file_created ($$$) {
}
# Check if it died after the fork() was successful
if ( $pid > 0 && waitpid($pid,&WNOHANG) == $pid )
if ( $pid != 0 && waitpid($pid,&WNOHANG) == $pid )
{
return 0;
}
......@@ -905,8 +893,8 @@ sub mtr_exit ($) {
# set ourselves as the group leader at startup (with
# POSIX::setpgrp(0,0)), but then care must be needed to always do
# proper child process cleanup.
kill('HUP', -$$) if $$ == getpgrp();
sleep 2;
kill('HUP', -$$) if !$::glob_win32_perl and $$ == getpgrp();
exit($code);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment