3 # pe was written by Omar Polo <op@openbsd.org> and is placed in the
4 # public domain. The author hereby disclaims copyright to this source
7 use open ":std", ":encoding(UTF-8)";
13 use Encode qw(encode);
14 use IO::Poll qw(POLLOUT);
20 use GotMArc qw(parse);
22 my $jobs = $ENV{'MAKE_JOBS'} // 1;
24 my $csumdir = $ENV{'CSUMDIR'};
25 die '$CSUMDIR undefined' unless defined $csumdir;
27 my $poll = IO::Poll->new();
29 open(my $kid, '|-', './mexp') or die "can't exec ./mexp: $!";
30 $poll->mask($kid => POLLOUT);
33 # get current thread checksum
35 my $sha = Digest::SHA->new(256);
36 $sha->add(encode('UTF-8', $_)) for @_;
37 return $sha->hexdigest;
40 # get stored thread checksum
43 open my $fh, '<', "$csumdir/$tid" or return "";
49 # save thread checksum
52 open my $fh, '>', "$csumdir/$tid"
53 or die "can't open checksum file $csumdir/$tid: $!";
61 return unless @entries;
63 local $_ = $entries[0];
65 die "wtf?" if $mail->{level} != 0;
67 my $tid = $mail->{mid};
68 my $thrsum = thrsum @_;
69 my $oldsum = oldsum $tid;
70 return if $thrsum eq $oldsum;
72 die "poll: $!" if $poll->poll() == -1;
73 my @handles = $poll->handles(POLLOUT) or die "no procs ready?";
74 my $handle = $handles[int(rand(@handles))];
75 print $handle $_ foreach @entries;
77 savesum($tid, $thrsum);
80 unveil($csumdir, "rwc") or die "unveil $csumdir: $!";
81 pledge("stdio rpath wpath cpath") or die "pledge: $!";
85 print; # continue the pipeline
87 my $new_thread = m/^-/;
88 if ($new_thread && @thread) {
96 process @thread if @thread;