mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Cleanup mtr_timer
Add verbose printouts making it possible to see what happens. Make it an error if trying to stop a non existing timer Print warning if fork fails.
This commit is contained in:
@ -4,23 +4,22 @@
|
|||||||
# and is part of the translation of the Bourne shell script with the
|
# and is part of the translation of the Bourne shell script with the
|
||||||
# same name.
|
# same name.
|
||||||
|
|
||||||
use Carp qw(cluck);
|
|
||||||
use Socket;
|
use Socket;
|
||||||
use Errno;
|
use Errno;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
#use POSIX ":sys_wait_h";
|
#use POSIX ":sys_wait_h";
|
||||||
use POSIX 'WNOHANG';
|
#use POSIX 'WNOHANG';
|
||||||
|
|
||||||
sub mtr_init_timers ();
|
sub mtr_init_timers ();
|
||||||
sub mtr_timer_start($$$);
|
sub mtr_timer_start($$$);
|
||||||
sub mtr_timer_stop($$);
|
sub mtr_timer_stop($$);
|
||||||
sub mtr_timer_stop_all($);
|
sub mtr_timer_stop_all($);
|
||||||
sub mtr_timer_waitpid($$$);
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Initiate a structure shared by all timers
|
# Initiate the structure shared by all timers
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
@ -35,17 +34,19 @@ sub mtr_init_timers () {
|
|||||||
# Start, stop and poll a timer
|
# Start, stop and poll a timer
|
||||||
#
|
#
|
||||||
# As alarm() isn't portable to Windows, we use separate processes to
|
# As alarm() isn't portable to Windows, we use separate processes to
|
||||||
# implement timers. That is why there is a mtr_timer_waitpid(), as this
|
# implement timers.
|
||||||
# is where we catch a timeout.
|
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
sub mtr_timer_start($$$) {
|
sub mtr_timer_start($$$) {
|
||||||
my ($timers,$name,$duration)= @_;
|
my ($timers,$name,$duration)= @_;
|
||||||
|
|
||||||
|
mtr_verbose("mtr_timer_start: $name, $duration");
|
||||||
|
|
||||||
if ( exists $timers->{'timers'}->{$name} )
|
if ( exists $timers->{'timers'}->{$name} )
|
||||||
{
|
{
|
||||||
# We have an old running timer, kill it
|
# We have an old running timer, kill it
|
||||||
|
mtr_verbose("There is an old timer running");
|
||||||
mtr_timer_stop($timers,$name);
|
mtr_timer_stop($timers,$name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ sub mtr_timer_start($$$) {
|
|||||||
{
|
{
|
||||||
if ( $! == $!{EAGAIN} ) # See "perldoc Errno"
|
if ( $! == $!{EAGAIN} ) # See "perldoc Errno"
|
||||||
{
|
{
|
||||||
mtr_debug("Got EAGAIN from fork(), sleep 1 second and redo");
|
mtr_warning("Got EAGAIN from fork(), sleep 1 second and redo");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
redo FORK;
|
redo FORK;
|
||||||
}
|
}
|
||||||
@ -70,6 +71,7 @@ sub mtr_timer_start($$$) {
|
|||||||
if ( $tpid )
|
if ( $tpid )
|
||||||
{
|
{
|
||||||
# Parent, record the information
|
# Parent, record the information
|
||||||
|
mtr_verbose("timer parent, record info($name, $tpid, $duration)");
|
||||||
$timers->{'timers'}->{$name}->{'pid'}= $tpid;
|
$timers->{'timers'}->{$name}->{'pid'}= $tpid;
|
||||||
$timers->{'timers'}->{$name}->{'duration'}= $duration;
|
$timers->{'timers'}->{$name}->{'duration'}= $duration;
|
||||||
$timers->{'pids'}->{$tpid}= $name;
|
$timers->{'pids'}->{$tpid}= $name;
|
||||||
@ -85,6 +87,7 @@ sub mtr_timer_start($$$) {
|
|||||||
$SIG{INT}= 'DEFAULT';
|
$SIG{INT}= 'DEFAULT';
|
||||||
|
|
||||||
$0= "mtr_timer(timers,$name,$duration)";
|
$0= "mtr_timer(timers,$name,$duration)";
|
||||||
|
mtr_verbose("timer child $name, sleep $duration");
|
||||||
sleep($duration);
|
sleep($duration);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -95,9 +98,12 @@ sub mtr_timer_start($$$) {
|
|||||||
sub mtr_timer_stop ($$) {
|
sub mtr_timer_stop ($$) {
|
||||||
my ($timers,$name)= @_;
|
my ($timers,$name)= @_;
|
||||||
|
|
||||||
|
mtr_verbose("mtr_timer_stop: $name");
|
||||||
|
|
||||||
if ( exists $timers->{'timers'}->{$name} )
|
if ( exists $timers->{'timers'}->{$name} )
|
||||||
{
|
{
|
||||||
my $tpid= $timers->{'timers'}->{$name}->{'pid'};
|
my $tpid= $timers->{'timers'}->{$name}->{'pid'};
|
||||||
|
mtr_verbose("Stopping timer with pid $tpid");
|
||||||
|
|
||||||
# FIXME as Cygwin reuses pids fast, maybe check that is
|
# FIXME as Cygwin reuses pids fast, maybe check that is
|
||||||
# the expected process somehow?!
|
# the expected process somehow?!
|
||||||
@ -114,7 +120,7 @@ sub mtr_timer_stop ($$) {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mtr_debug("Asked to stop timer \"$name\" not started");
|
mtr_error("Asked to stop timer \"$name\" not started");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user