about summary refs log tree commit homepage
path: root/script
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-24 04:46:49 -0700
committerEric Wong <e@80x24.org>2021-01-24 15:45:22 -0400
commitc80fc47e280a500ff8d6c3fde53e7554272e749b (patch)
tree00a9f9027eacd57affa16a2c617a470f14556a72 /script
parent509c88ddfe0bb3bf4f00ff119eb2d847512df90c (diff)
downloadpublic-inbox-c80fc47e280a500ff8d6c3fde53e7554272e749b.tar.gz
Just open every FD as read/write.  Perl (or any non-broken
runtime) won't care and won't attempt to use F_SETFL to alter
file description flags; as attempting to change those would
lead to unpleasant side effects if the file description is
shared with another process.
Diffstat (limited to 'script')
-rwxr-xr-xscript/lei11
1 files changed, 5 insertions, 6 deletions
diff --git a/script/lei b/script/lei
index 8c40bf12..006c1180 100755
--- a/script/lei
+++ b/script/lei
@@ -23,20 +23,19 @@ sub sigchld {
 
 sub exec_cmd {
         my ($fds, $argc, @argv) = @_;
-        my @m = (*STDIN{IO}, '<&=',  *STDOUT{IO}, '>&=', *STDERR{IO}, '>&=');
+        my @old = (*STDIN{IO}, *STDOUT{IO}, *STDERR{IO});
         my @rdr;
         for my $fd (@$fds) {
-                my ($old_io, $mode) = splice(@m, 0, 2);
-                open(my $tmpfh, $mode, $fd) or die "open $mode$fd: $!";
-                push @rdr, $old_io, $mode, $tmpfh;
+                open(my $tmpfh, '+<&=', $fd) or die "open +<&=$fd: $!";
+                push @rdr, shift(@old), $tmpfh;
         }
         require POSIX; # WNOHANG
         $SIG{CHLD} = \&sigchld;
         my $pid = fork // die "fork: $!";
         if ($pid == 0) {
                 my %env = map { split(/=/, $_, 2) } splice(@argv, $argc);
-                while (my ($old_io, $mode, $tmpfh) = splice(@rdr, 0, 3)) {
-                        open $old_io, $mode, $tmpfh or die "open $mode: $!";
+                while (my ($old_io, $tmpfh) = splice(@rdr, 0, 2)) {
+                        open $old_io, '+<&', $tmpfh or die "open +<&=: $!";
                 }
                 %ENV = (%ENV, %env);
                 exec(@argv);