Commit 2f4f68be authored by unknown's avatar unknown

Change sleep_until_file_created to sleep 100 millisecond instead of sleeping 1...

Change sleep_until_file_created to sleep 100 millisecond instead of sleeping 1 seconds between each iteration.


parent 1b24bab8
...@@ -832,30 +832,36 @@ sub sleep_until_file_created ($$$) { ...@@ -832,30 +832,36 @@ sub sleep_until_file_created ($$$) {
my $pidfile= shift; my $pidfile= shift;
my $timeout= shift; my $timeout= shift;
my $pid= shift; my $pid= shift;
my $sleeptime= 100; # Milliseconds
my $loops= ($timeout * 1000) / $sleeptime;
for ( my $loop= 1; $loop <= $timeout; $loop++ ) for ( my $loop= 1; $loop <= $loops; $loop++ )
{ {
if ( -r $pidfile ) if ( -r $pidfile )
{ {
return $pid; return $pid;
} }
# Check if it died after the fork() was successful # 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; return 0;
} }
mtr_debug("Sleep 1 second waiting for creation of $pidfile"); mtr_debug("Sleep $sleeptime milliseconds waiting for ".
"creation of $pidfile");
if ( $loop % 60 == 0 ) # Print extra message every 60 seconds
my $seconds= ($loop * $sleeptime) / 1000;
if ( $seconds > 1 and $seconds % 60 == 0 )
{ {
my $left= $timeout - $loop; my $left= $timeout - $seconds;
mtr_warning("Waited $loop seconds for $pidfile to be created, " . mtr_warning("Waited $seconds seconds for $pidfile to be created, " .
"still waiting for $left seconds..."); "still waiting for $left seconds...");
} }
sleep(1); # Millisceond sleep emulated with select
select(undef, undef, undef, ($sleeptime/1000));
} }
return 0; return 0;
......
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