user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
23ecce7721867242cbe6327373fd8896ace7d212 blob 790 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# automatically kill + reap children when this goes out-of-scope
package PublicInbox::AutoReap;
use v5.10.1;
use strict;

sub new {
	my (undef, $pid, $cb) = @_;
	bless { pid => $pid, cb => $cb, owner => $$ }, __PACKAGE__
}

sub kill {
	my ($self, $sig) = @_;
	CORE::kill($sig // 'TERM', $self->{pid});
}

sub join {
	my ($self, $sig) = @_;
	my $pid = delete $self->{pid} or return;
	$self->{cb}->() if defined $self->{cb};
	CORE::kill($sig, $pid) if defined $sig;
	my $ret = waitpid($pid, 0) // die "waitpid($pid): $!";
	$ret == $pid or die "BUG: waitpid($pid) != $ret";
}

sub DESTROY {
	my ($self) = @_;
	return if $self->{owner} != $$;
	$self->join('TERM');
}

1;
debug log:

solving 23ecce772186 ...
found 23ecce772186 in https://80x24.org/public-inbox.git

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).