summaryrefslogtreecommitdiff
path: root/regress/usr.sbin/syslogd/Proc.pm
diff options
context:
space:
mode:
Diffstat (limited to 'regress/usr.sbin/syslogd/Proc.pm')
-rw-r--r--regress/usr.sbin/syslogd/Proc.pm22
1 files changed, 21 insertions, 1 deletions
diff --git a/regress/usr.sbin/syslogd/Proc.pm b/regress/usr.sbin/syslogd/Proc.pm
index ca4081b5186..a3d0976d58c 100644
--- a/regress/usr.sbin/syslogd/Proc.pm
+++ b/regress/usr.sbin/syslogd/Proc.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Proc.pm,v 1.1 2014/08/20 20:52:14 bluhm Exp $
+# $OpenBSD: Proc.pm,v 1.2 2014/09/02 00:26:30 bluhm Exp $
# Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org>
# Copyright (c) 2014 Florian Riehm <mail@friehm.de>
@@ -72,6 +72,7 @@ sub new {
or die "$class log file $self->{logfile} create failed: $!";
$fh->autoflush;
$self->{log} = $fh;
+ $self->{ppid} = $$;
return bless $self, $class;
}
@@ -125,6 +126,9 @@ sub wait {
my $self = shift;
my $flags = shift;
+ # if we a not the parent process, assume the child is still running
+ return 0 unless $self->{ppid} == $$;
+
my $pid = $self->{pid}
or croak ref($self), " no child pid";
my $kid = waitpid($pid, $flags);
@@ -194,4 +198,20 @@ sub kill_child {
return $self;
}
+sub kill {
+ my $self = shift;
+ my $sig = shift // 'TERM';
+ my $pid = shift // $self->{pid};
+
+ if (kill($sig => $pid) != 1) {
+ my $sudo = $ENV{SUDO};
+ $sudo && $!{EPERM}
+ or die ref($self), " kill $pid failed: $!";
+ my @cmd = ($sudo, '/bin/kill', "-$sig", $pid);
+ system(@cmd)
+ and die ref($self), " sudo kill $pid failed: $?";
+ }
+ return $self;
+}
+
1;