While forked processes inherit from the parent, exec-ed
processes need the `-w' flag passed to them. To determine
whether or not we should pass them, we must check the `$^W'
global perlvar, first.
We'll also favor `perl -e' over `perl -E' in places where
we don't rely on the latest features, since `-E' incurs
slightly more startup time overhead from loading feature.pm
(while `perl -Mv5.12' does not).
---
lib/PublicInbox/Gcf2Client.pm | 3 ++-
lib/PublicInbox/LeiRediff.pm | 4 ++--
script/lei | 4 ++--
t/edit.t | 29 +++++++++++++++--------------
t/extsearch.t | 2 +-
t/lei-q-save.t | 4 ++--
t/mbox_reader.t | 6 +++---
t/spawn.t | 4 ++--
8 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/lib/PublicInbox/Gcf2Client.pm b/lib/PublicInbox/Gcf2Client.pm
index 8e313c84..4a0348b4 100644
--- a/lib/PublicInbox/Gcf2Client.pm
+++ b/lib/PublicInbox/Gcf2Client.pm
@@ -30,7 +30,8 @@ sub new {
socketpair(my $s1, my $s2, AF_UNIX, SOCK_STREAM, 0);
$s1->blocking(0);
$opt->{0} = $opt->{1} = $s2;
- my $cmd = [$^X, qw[-MPublicInbox::Gcf2 -e PublicInbox::Gcf2::loop]];
+ my $cmd = [$^X, $^W ? ('-w') : (),
+ qw[-MPublicInbox::Gcf2 -e PublicInbox::Gcf2::loop]];
my $pid = spawn($cmd, $env, $opt);
my $sock = PublicInbox::ProcessPipe->maybe_new($pid, $s1);
$self->{inflight} = [];
diff --git a/lib/PublicInbox/LeiRediff.pm b/lib/PublicInbox/LeiRediff.pm
index 6cc6131b..a886931c 100644
--- a/lib/PublicInbox/LeiRediff.pm
+++ b/lib/PublicInbox/LeiRediff.pm
@@ -140,7 +140,7 @@ EOM
sub wait_requote { # OnDestroy callback
my ($lei, $pid, $old_1) = @_;
- $lei->{1} = $old_1; # closes stdin of `perl -pE 's/^/> /'`
+ $lei->{1} = $old_1; # closes stdin of `perl -pe 's/^/> /'`
waitpid($pid, 0) == $pid or die "BUG(?) waitpid: \$!=$! \$?=$?";
$lei->child_error($?) if $?;
}
@@ -150,7 +150,7 @@ sub requote ($$) {
my $old_1 = $lei->{1};
my $opt = { 1 => $old_1, 2 => $lei->{2} };
# $^X (perl) is overkill, but maybe there's a weird system w/o sed
- my ($w, $pid) = popen_wr([$^X, '-pE', "s/^/$pfx/"], $lei->{env}, $opt);
+ my ($w, $pid) = popen_wr([$^X, '-pe', "s/^/$pfx/"], $lei->{env}, $opt);
$w->autoflush(1);
binmode $w, ':utf8'; # incompatible with ProcessPipe due to syswrite
$lei->{1} = $w;
diff --git a/script/lei b/script/lei
index a77ea880..1d90be0a 100755
--- a/script/lei
+++ b/script/lei
@@ -92,8 +92,8 @@ my $addr = pack_sockaddr_un($path);
socket($sock, AF_UNIX, SOCK_SEQPACKET, 0) or die "socket: $!";
unless (connect($sock, $addr)) { # start the daemon if not started
local $ENV{PERL5LIB} = join(':', @INC);
- open(my $daemon, '-|', $^X, qw[-MPublicInbox::LEI
- -E PublicInbox::LEI::lazy_start(@ARGV)],
+ open(my $daemon, '-|', $^X, $^W ? ('-w') : (),
+ qw[-MPublicInbox::LEI -e PublicInbox::LEI::lazy_start(@ARGV)],
$path, $! + 0, $narg) or die "popen: $!";
while (<$daemon>) { warn $_ } # EOF when STDERR is redirected
close($daemon) or warn <<"";
diff --git a/t/edit.t b/t/edit.t
index e6e0f9cf..1621df3b 100644
--- a/t/edit.t
+++ b/t/edit.t
@@ -1,5 +1,5 @@
#!perl -w
-# Copyright (C) 2019-2021 all contributors <[email protected]>
+# Copyright (C) all contributors <[email protected]>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# edit frontend behavior test (t/replace.t for backend)
use strict;
@@ -24,10 +24,11 @@ local $ENV{PI_CONFIG} = $cfgfile;
my ($in, $out, $err, $cmd, $cur, $t);
my $git = PublicInbox::Git->new("$ibx->{inboxdir}/git/0.git");
my $opt = { 0 => \$in, 1 => \$out, 2 => \$err };
+my $ipe = "$^X -w -i -p -e";
$t = '-F FILE'; {
$in = $out = $err = '';
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/boolean prefix/bool pfx/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/boolean prefix/bool pfx/'";
$cmd = [ '-edit', "-F$file", $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t edit OK");
$cur = PublicInbox::Eml->new($ibx->msg_by_mid($mid));
@@ -37,7 +38,7 @@ $t = '-F FILE'; {
$t = '-m MESSAGE_ID'; {
$in = $out = $err = '';
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/bool pfx/boolean prefix/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/bool pfx/boolean prefix/'";
$cmd = [ '-edit', "-m$mid", $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t edit OK");
$cur = PublicInbox::Eml->new($ibx->msg_by_mid($mid));
@@ -48,7 +49,7 @@ $t = '-m MESSAGE_ID'; {
$t = 'no-op -m MESSAGE_ID'; {
$in = $out = $err = '';
my $before = $git->qx(qw(rev-parse HEAD));
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/bool pfx/boolean prefix/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/bool pfx/boolean prefix/'";
$cmd = [ '-edit', "-m$mid", $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t succeeds");
my $prev = $cur;
@@ -64,7 +65,7 @@ $t = 'no-op -m MESSAGE_ID'; {
$t = 'no-op -m MESSAGE_ID w/Status: header'; { # because mutt does it
$in = $out = $err = '';
my $before = $git->qx(qw(rev-parse HEAD));
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/^Subject:.*/Status:
RO\\n\$&/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/^Subject:.*/Status: RO\\n\$&/'";
$cmd = [ '-edit', "-m$mid", $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t succeeds");
my $prev = $cur;
@@ -80,7 +81,7 @@ $t = 'no-op -m MESSAGE_ID w/Status: header'; { # because mutt
does it
$t = '-m MESSAGE_ID can change Received: headers'; {
$in = $out = $err = '';
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/^Subject:.*/Received:
x\\n\$&/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/^Subject:.*/Received: x\\n\$&/'";
$cmd = [ '-edit', "-m$mid", $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t succeeds");
$cur = PublicInbox::Eml->new($ibx->msg_by_mid($mid));
@@ -91,7 +92,7 @@ $t = '-m MESSAGE_ID can change Received: headers'; {
$t = '-m miss'; {
$in = $out = $err = '';
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/boolean/FAIL/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/boolean/FAIL/'";
$cmd = [ '-edit', "-m$mid-miss", $inboxdir ];
ok(!run_script($cmd, undef, $opt), "$t fails on invalid MID");
like($err, qr/No message found/, "$t shows error");
@@ -99,7 +100,7 @@ $t = '-m miss'; {
$t = 'non-interactive editor failure'; {
$in = $out = $err = '';
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 'END { exit 1 }'";
+ local $ENV{MAIL_EDITOR} = "$ipe 'END { exit 1 }'";
$cmd = [ '-edit', "-m$mid", $inboxdir ];
ok(!run_script($cmd, undef, $opt), "$t detected");
like($err, qr/END \{ exit 1 \}' failed:/, "$t shows error");
@@ -109,7 +110,7 @@ $t = 'mailEditor set in config'; {
$in = $out = $err = '';
my $rc = xsys(qw(git config), "--file=$cfgfile",
'publicinbox.maileditor',
- "$^X -i -p -e 's/boolean prefix/bool pfx/'");
+ "$ipe 's/boolean prefix/bool pfx/'");
is($rc, 0, 'set publicinbox.mailEditor');
local $ENV{MAIL_EDITOR};
delete $ENV{MAIL_EDITOR};
@@ -123,20 +124,20 @@ $t = 'mailEditor set in config'; {
$t = '--raw and mbox escaping'; {
$in = $out = $err = '';
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/^\$/\\nFrom not mbox\\n/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/^\$/\\nFrom not mbox\\n/'";
$cmd = [ '-edit', "-m$mid", '--raw', $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t succeeds");
$cur = PublicInbox::Eml->new($ibx->msg_by_mid($mid));
like($cur->body, qr/^From not mbox/sm, 'put "From " line into body');
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/^>From not/\$& an/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/^>From not/\$& an/'";
$cmd = [ '-edit', "-m$mid", $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t succeeds with mbox escaping");
$cur = PublicInbox::Eml->new($ibx->msg_by_mid($mid));
like($cur->body, qr/^From not an mbox/sm,
'changed "From " line unescaped');
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/^From not an mbox\\n//s'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/^From not an mbox\\n//s'";
$cmd = [ '-edit', "-m$mid", '--raw', $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t succeeds again");
$cur = PublicInbox::Eml->new($ibx->msg_by_mid($mid));
@@ -154,7 +155,7 @@ $t = 'reuse Message-ID'; {
$t = 'edit ambiguous Message-ID with -m'; {
$in = $out = $err = '';
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/bool pfx/boolean prefix/'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/bool pfx/boolean prefix/'";
$cmd = [ '-edit', "-m$mid", $inboxdir ];
ok(!run_script($cmd, undef, $opt), "$t fails w/o --force");
like($err, qr/Multiple messages with different content found matching/,
@@ -164,7 +165,7 @@ $t = 'edit ambiguous Message-ID with -m'; {
$t .= ' and --force'; {
$in = $out = $err = '';
- local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/^Subject:.*/Subject:x/i'";
+ local $ENV{MAIL_EDITOR} = "$ipe 's/^Subject:.*/Subject:x/i'";
$cmd = [ '-edit', "-m$mid", '--force', $inboxdir ];
ok(run_script($cmd, undef, $opt), "$t succeeds");
like($err, qr/Will edit all of them/, "$t notes all will be edited");
diff --git a/t/extsearch.t b/t/extsearch.t
index 19eaf3b5..2995cf95 100644
--- a/t/extsearch.t
+++ b/t/extsearch.t
@@ -151,7 +151,7 @@ if ('inbox edited') {
my ($in, $out, $err);
$in = $out = $err = '';
my $opt = { 0 => \$in, 1 => \$out, 2 => \$err };
- my $env = { MAIL_EDITOR => "$^X -i -p -e 's/test message/BEST MSG/'" };
+ my $env = { MAIL_EDITOR => "$^X -w -i -p -e 's/test message/BEST MSG/'"
};
my $cmd = [ qw(-edit -Ft/utf8.eml), "$home/v2test" ];
ok(run_script($cmd, $env, $opt), '-edit');
ok(run_script([qw(-extindex --all), "$home/extindex"], undef, $opt),
diff --git a/t/lei-q-save.t b/t/lei-q-save.t
index d09c8397..1d9d5a51 100644
--- a/t/lei-q-save.t
+++ b/t/lei-q-save.t
@@ -227,7 +227,7 @@ test_lei(sub {
my @lss = glob("$home/" .
'.local/share/lei/saved-searches/*/lei.saved-search');
my $out = xqx([qw(git config -f), $lss[0], 'lei.q.output']);
- xsys($^X, qw(-i -p -e), "s/\\[/\\0/", $lss[0])
+ xsys($^X, qw(-w -i -p -e), "s/\\[/\\0/", $lss[0])
and xbail "-ipe $lss[0]: $?";
lei_ok qw(ls-search);
like($lei_err, qr/bad config line.*?\Q$lss[0]\E/,
@@ -235,7 +235,7 @@ test_lei(sub {
lei_ok qw(up --all), \'up works with bad config';
like($lei_err, qr/bad config line.*?\Q$lss[0]\E/,
'git config parse error shown w/ lei up');
- xsys($^X, qw(-i -p -e), "s/\\0/\\[/", $lss[0])
+ xsys($^X, qw(-w -i -p -e), "s/\\0/\\[/", $lss[0])
and xbail "-ipe $lss[0]: $?";
lei_ok qw(ls-search);
is($lei_err, '', 'no errors w/ fixed config');
diff --git a/t/mbox_reader.t b/t/mbox_reader.t
index 87e8f397..14248a2d 100644
--- a/t/mbox_reader.t
+++ b/t/mbox_reader.t
@@ -113,10 +113,10 @@ EOM
SKIP: {
use PublicInbox::Spawn qw(popen_rd);
- my $fh = popen_rd([ $^X, '-E', <<'' ]);
-say "From x@y Fri Oct 2 00:00:00 1993";
+ my $fh = popen_rd([ $^X, qw(-w -Mv5.12 -e), <<'' ]);
+say 'From x@y Fri Oct 2 00:00:00 1993';
print "a: b\n\n", "x" x 70000, "\n\n";
-say "From x@y Fri Oct 2 00:00:00 2010";
+say 'From x@y Fri Oct 2 00:00:00 2010';
print "Final: bit\n\n", "Incomplete\n\n";
exit 1
diff --git a/t/spawn.t b/t/spawn.t
index 9ed3be36..04589437 100644
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -62,7 +62,7 @@ elsif ($pid > 0) {
}
EOF
my $oldset = PublicInbox::DS::block_signals();
- my $rd = popen_rd([$^X, '-e', $script]);
+ my $rd = popen_rd([$^X, qw(-w -e), $script]);
diag 'waiting for child to reap grandchild...';
chomp(my $line = readline($rd));
my ($rdy, $pid) = split(/ /, $line);
@@ -185,7 +185,7 @@ SKIP: {
require BSD::Resource;
defined(BSD::Resource::RLIMIT_CPU())
} or skip 'BSD::Resource::RLIMIT_CPU missing', 3;
- my $cmd = [ $^X, ($^W ? ('-w') : ()), '-e', <<'EOM' ];
+ my $cmd = [ $^X, qw(-w -e), <<'EOM' ];
use POSIX qw(:signal_h);
use BSD::Resource qw(times);
use Time::HiRes qw(time); # gettimeofday