Blob


1 #!/usr/bin/env perl
2 #
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
5 # code.
7 use open ":std", ":encoding(UTF-8)";
8 use strict;
9 use warnings;
10 use v5.32;
11 use IO::Poll qw(POLLOUT);
13 use OpenBSD::Pledge;
14 use OpenBSD::Unveil;
16 my $jobs = $ENV{'MAKE_JOBS'} // 1;
18 my $poll = IO::Poll->new();
19 for (1..$jobs) {
20 open(my $kid, '|-', './mexp') or die "can't exec ./mexp: $!";
21 $poll->mask($kid => POLLOUT);
22 }
24 sub process {
25 die "poll: $!" if $poll->poll() == -1;
26 my @handles = $poll->handles(POLLOUT) or die "no procs ready?";
27 my $handle = $handles[int(rand(@handles))];
28 print $handle $_ foreach @_;
29 }
31 unveil("./mexp", "rx") or die "unveil mexp: $!";
32 pledge("stdio proc exec") or die "pledge: $!";
34 my @thread;
35 while (<>) {
36 print; # continue the pipeline
38 my $new_thread = m/^-/;
39 if ($new_thread && @thread) {
40 process @thread;
41 @thread = ();
42 }
44 push @thread, $_;
45 }
47 process @thread if @thread;