Subject: | minor fixes |
* init minimum_pid
* quiet some uninit warnings when given wonky args
* change CORE::kill so tests can mock kill
@@ -17,12 +17,12 @@ sub new {
$args_hr->{'ps_path'} = '';
}
- return bless { 'ps_path' => $args_hr->{'ps_path'} }, $self;
+ return bless { 'ps_path' => $args_hr->{'ps_path'}, 'minimum_pid' => $args_hr->{'minimum_pid'} }, $self;
}
sub kill {
my ( $self, $pid, $give_kill_a_chance) = @_;
- $give_kill_a_chance = int $give_kill_a_chance;
+ $give_kill_a_chance = int $give_kill_a_chance if defined $give_kill_a_chance;
$pid = int $pid;
my $min = int $self->{'minimum_pid'};
if ( $pid < $min ) {
@@ -38,10 +38,10 @@ sub kill {
# RC from CORE::kill is not a boolean of if the PID was killed or not, only that it was signaled
# so it is not an indicator of "success" in killing $pid
- CORE::kill( 15, $pid ); # TERM
- CORE::kill( 2, $pid ); # INT
- CORE::kill( 1, $pid ); # HUP
- CORE::kill( 9, $pid ); # KILL
+ kill( 15, $pid ); # TERM
+ kill( 2, $pid ); # INT
+ kill( 1, $pid ); # HUP
+ kill( 9, $pid ); # KILL
# give kill() some time to take effect?
if ($give_kill_a_chance) {
@@ -55,7 +55,10 @@ sub kill {
sub is_pid_running {
my ( $self, $check_pid ) = @_;
- return 1 if $> == 0 && CORE::kill(0, $check_pid); # if we are superuser we can avoid the the system call. For details see `perldoc -f kill`
+ $check_pid = int $check_pid;
+ return if !$check_pid || $check_pid < 0;
+
+ return 1 if $> == 0 && kill(0, $check_pid); # if we are superuser we can avoid the the system call. For details see `perldoc -f kill`
# If the proc filesystem is available, it's a good test. If not, continue on to system call
return 1 if -e "/proc/$$" && -r "/proc/$$" && -r "/proc/$check_pid";
@@ -69,6 +72,9 @@ sub is_pid_running {