-package PublicInboxTestProcess;
-use strict;
-
-# prevent new threads from inheriting these objects
-sub CLONE_SKIP { 1 }
-
-sub new {
- my ($klass, $pid, $tail_pid) = @_;
- bless { pid => $pid, tail_pid => $tail_pid, owner => $$ }, $klass;
-}
-
-sub kill {
- my ($self, $sig) = @_;
- CORE::kill($sig // 'TERM', $self->{pid});
-}
-
-sub join {
- my ($self, $sig) = @_;
- my $pid = delete $self->{pid} or return;
- CORE::kill($sig, $pid) if defined $sig;
- my $ret = waitpid($pid, 0) // die "waitpid($pid): $!";
- $ret == $pid or die "waitpid($pid) != $ret";
-}
-
-sub DESTROY {
- my ($self) = @_;
- return if $self->{owner} != $$;
- if (my $tail_pid = delete $self->{tail_pid}) {
- PublicInbox::TestCommon::wait_for_tail($tail_pid, -1);
- CORE::kill('TERM', $tail_pid);
- }
- $self->join('TERM');
-}
-