X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Flei;h=5feb77515d0f4a10c9fe8b67f859f8232f11e113;hb=68046e0fff12c35d793a7ae9f164ac415c84cc21;hp=99d94b4e6618f18a84d57826676d6b6afd1caba9;hpb=88c67b2202295c73f8f682233304daf3867936df;p=public-inbox.git
diff --git a/script/lei b/script/lei
index 99d94b4e..5feb7751 100755
--- a/script/lei
+++ b/script/lei
@@ -1,14 +1,17 @@
#!perl -w
-# Copyright (C) 2020-2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
-use strict;
-use v5.10.1;
+use v5.12;
use Socket qw(AF_UNIX SOCK_SEQPACKET MSG_EOR pack_sockaddr_un);
use PublicInbox::CmdIPC4;
my $narg = 5;
my $sock;
my $recv_cmd = PublicInbox::CmdIPC4->can('recv_cmd4');
my $send_cmd = PublicInbox::CmdIPC4->can('send_cmd4') // do {
+ require PublicInbox::Syscall;
+ $recv_cmd = PublicInbox::Syscall->can('recv_cmd4');
+ PublicInbox::Syscall->can('send_cmd4');
+} // do {
my $inline_dir = $ENV{PERL_INLINE_DIRECTORY} //= (
$ENV{XDG_CACHE_HOME} //
( ($ENV{HOME} // '/nonexistent').'/.cache' )
@@ -53,6 +56,7 @@ my $exec_cmd = sub {
}
my %env = map { split(/=/, $_, 2) } splice(@argv, $argc);
@ENV{keys %env} = values %env;
+ umask 077;
exec(@argv);
warn "exec: @argv: $!\n";
POSIX::_exit(1);
@@ -105,11 +109,10 @@ open my $dh, '<', '.' or die "open(.) $!";
my $buf = join("\0", scalar(@ARGV), @ARGV);
while (my ($k, $v) = each %ENV) { $buf .= "\0$k=$v" }
$buf .= "\0\0";
-my $n = $send_cmd->($sock, [0, 1, 2, fileno($dh)], $buf, MSG_EOR);
-if (!$n) {
- die "sendmsg: $! (check RLIMIT_NOFILE)\n" if $!{ETOOMANYREFS};
- die "sendmsg: $!\n";
-}
+$send_cmd->($sock, [0, 1, 2, fileno($dh)], $buf, MSG_EOR) or die "sendmsg: $!";
+$SIG{TSTP} = sub { send($sock, 'STOP', MSG_EOR); kill 'STOP', $$ };
+$SIG{CONT} = sub { send($sock, 'CONT', MSG_EOR) };
+
my $x_it_code = 0;
while (1) {
my (@fds) = $recv_cmd->($sock, my $buf, 4096 * 33);
@@ -122,11 +125,15 @@ while (1) {
$exec_cmd->(\@fds, split(/\0/, $1));
} elsif ($buf eq '-WINCH') {
kill($buf, @parent); # for MUA
+ } elsif ($buf eq 'umask') {
+ send($sock, 'u'.pack('V', umask), MSG_EOR) or die "send: $!"
} elsif ($buf =~ /\Ax_it ([0-9]+)\z/) {
$x_it_code ||= $1 + 0;
last;
} elsif ($buf =~ /\Achild_error ([0-9]+)\z/) {
$x_it_code ||= $1 + 0;
+ } elsif ($buf eq 'wait') {
+ $sigchld->();
} else {
$sigchld->();
die $buf;
@@ -135,6 +142,6 @@ while (1) {
$sigchld->();
if (my $sig = ($x_it_code & 127)) {
kill $sig, $$;
- sleep(1) while 1;
+ sleep(1) while 1; # no self-pipe/signalfd, here, so we loop
}
exit($x_it_code >> 8);