Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions lib/Mojo/IOLoop/ReadWriteProcess.pm
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,34 @@
sub send_signal {
my $self = shift;
my $signal = shift // $self->_default_kill_signal;
my $pid = shift // $self->process_id;
my @pids = @_;
@pids = ($self->process_id) unless @pids;
return unless $self->kill_whole_group || $self->is_running;
$self->_diag("Sending signal '$signal' to $pid") if DEBUG;
kill $signal => $pid;
$self->_diag("Sending signal '$signal' to @pids") if DEBUG;
kill $signal => @pids;
return $self;
}

sub _waitpids {
my ($self, $flags, @pids) = @_;
my $status;
my $stopped = 0;
for my $pid (@pids) {
my $ret = waitpid($pid, $flags);
if ($ret == $pid || $ret == -1) {
$status //= $?;
$stopped += 1;
}
}
$self->_status($status);
return $stopped;
}

sub stop {
my $self = shift;

my $pid = $self->pid;
my @pids = ($self->pid);
return $self unless defined $pid;

Check failure on line 537 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl 5.30 on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 537 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl 5.30 on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 537 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl latest on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 537 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl latest on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)
return $self->_shutdown(1) unless $self->is_running;

my $ret;
Expand All @@ -527,25 +543,24 @@
my $sleep_time = $self->sleeptime_during_kill;
my $max_attempts = $self->max_kill_attempts;
my $signal = $self->_default_kill_signal;
$pid = -$pid if $self->kill_whole_group;
$self->_diag("Stopping $pid") if DEBUG;
push @pids, -$pid if $self->kill_whole_group;

Check failure on line 546 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl 5.30 on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 546 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl 5.30 on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 546 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl latest on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 546 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl latest on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)
$self->_diag("Stopping @pids") if DEBUG;

until ((defined $ret && ($ret == $pid || $ret == -1))
|| ($attempt > $max_attempts && $timeout <= 0))
my $stopped = 0;
until (($stopped == scalar(@pids)) || ($attempt > $max_attempts && $timeout <= 0))
{
my $send_signal = $attempt == 1 || $timeout <= 0;
$self->_diag(
"attempt $attempt/$max_attempts to kill process: $pid, timeout: $timeout")

Check failure on line 554 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl 5.30 on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 554 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl 5.30 on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 554 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl latest on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 554 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl latest on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)
if DEBUG && $send_signal;
$self->session->_protect(
sub {
local $?;
if ($send_signal) {
$self->send_signal($signal, $pid);
$self->send_signal($signal, @pids);
++$attempt;
}
$ret = waitpid($pid, WNOHANG);
$self->_status($?) if $ret == $pid || $ret == -1;
$stopped = $self->_waitpids(WNOHANG, @pids);
});
if ($sleep_time) {
sleep $sleep_time;
Expand All @@ -557,17 +572,16 @@
sleep $self->kill_sleeptime if $self->kill_sleeptime;

if ($self->blocking_stop) {
$self->_diag("Could not kill process id: $pid, blocking attempt") if DEBUG;
$self->_diag("Could not kill process id: @pids, blocking attempt") if DEBUG;
$self->emit('process_stuck');

### XXX: avoid to protect on blocking.
$self->send_signal($self->_default_blocking_signal, $pid);
$ret = waitpid($pid, 0);
$self->_status($?) if $ret == $pid || $ret == -1;
$self->send_signal($self->_default_blocking_signal, @pids);
$self->_waitpids(0, @pids);
return $self->_shutdown;
}
else {
$self->_diag("Could not kill process id: $pid") if DEBUG;

Check failure on line 584 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl 5.30 on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 584 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl 5.30 on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 584 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl latest on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)

Check failure on line 584 in lib/Mojo/IOLoop/ReadWriteProcess.pm

View workflow job for this annotation

GitHub Actions / 🐪 Perl latest on ubuntu-latest

Global symbol "$pid" requires explicit package name (did you forget to declare "my $pid"?)
$self->_new_err('Could not kill process');
}
return $self;
Expand Down
Loading