block signals around checking for a process to die

This commit is contained in:
Isaac Connor 2017-03-31 12:25:48 -04:00
parent 7068efd581
commit d3b6792a6a
1 changed files with 19 additions and 15 deletions

View File

@ -66,6 +66,7 @@ use ZoneMinder;
use POSIX;
use Socket;
use IO::Handle;
use Time::HiRes qw(usleep);
use autouse 'Pod::Usage'=>qw(pod2usage);
#use Data::Dumper;
@ -549,22 +550,25 @@ sub send_stop {
} # end sub send_stop
sub kill_until_dead {
my ( $process ) = @_;
# Now check it has actually gone away, if not kill -9 it
my $count = 0;
while( $process and $$process{pid} and kill( 0, $$process{pid} ) )
{
if ( $count++ > 5 )
{
dPrint( ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
.". Sending KILL to pid $$process{pid}\n"
);
kill( 'KILL', $$process{pid} );
}
sleep( 1 );
my ( $process ) = @_;
# Now check it has actually gone away, if not kill -9 it
my $count = 0;
my $sigset = POSIX::SigSet->new;
my $blockset = POSIX::SigSet->new(SIGINT);
sigprocmask(SIG_BLOCK, $blockset, $sigset ) or die "dying at block...\n";
while( $process and $$process{pid} and kill( 0, $$process{pid} ) ) {
if ( $count++ > 5 ) {
dPrint( ZoneMinder::Logger::WARNING, "'$$process{command}' has not stopped at "
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
.". Sending KILL to pid $$process{pid}\n"
);
kill( 'KILL', $$process{pid} );
}
sigprocmask(SIG_UNBLOCK, $blockset) or die "dying at unblock...\n";
usleep( 1 );
sigprocmask(SIG_BLOCK, $blockset, $sigset ) or die "dying at block...\n";
}
}
sub _stop {