about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-04-28 19:37:29 +0000
committerEric Wong <e@80x24.org>2021-04-28 19:47:29 +0000
commit08b649735a94af6a5385df3b78092e5818408df1 (patch)
tree5e7c9784b25d13a7fa8a8dbec5e3397ef2ff7a69 /lib
parent8e82fad7b32ab5a985a3ea4b5fbd01fd32ef0153 (diff)
downloadpublic-inbox-08b649735a94af6a5385df3b78092e5818408df1.tar.gz
This seems to fix the occasional "make check-run" failures I've
been chasing.

Some parts of our code assumes we can close($lei->{1})
and similar, which causes IO::Handle::autoflush to behave
badly when STDOUT is the "select"-ed FH of the Perl process.
Since oneshot mode is (hopefully) the uncommon case, we'll
just accept the cost of extra FDs and minimize differences
between lei in oneshot vs daemon mode.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/LEI.pm18
1 files changed, 4 insertions, 14 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 7ffcf163..1ea7c9ca 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -487,19 +487,14 @@ sub _lei_atfork_child {
         # we need to explicitly close things which are on stack
         if ($persist) {
                 chdir '/' or die "chdir(/): $!";
-                my @io = delete @$self{qw(0 1 2 sock)};
-                unless ($self->{oneshot}) {
-                        close($_) for @io;
-                }
+                close($_) for (grep(defined, delete @$self{qw(0 1 2 sock)}));
                 if (my $cfg = $self->{cfg}) {
                         delete $cfg->{-lei_store};
                 }
         } else { # worker, Net::NNTP (Net::Cmd) uses STDERR directly
                 open STDERR, '+>&='.fileno($self->{2}) or warn "open $!";
         }
-        for (delete @$self{qw(3 old_1 au_done)}) {
-                close($_) if defined($_);
-        }
+        close($_) for (grep(defined, delete @$self{qw(3 old_1 au_done)}));
         if (my $op_c = delete $self->{pkt_op_c}) {
                 close(delete $op_c->{sock});
         }
@@ -1213,13 +1208,8 @@ sub oneshot {
         local $quit = $exit if $exit;
         local %PATH2CFG;
         umask(077) // die("umask(077): $!");
-        my $self = bless {
-                oneshot => 1,
-                0 => *STDIN{GLOB},
-                1 => *STDOUT{GLOB},
-                2 => *STDERR{GLOB},
-                env => \%ENV
-        }, __PACKAGE__;
+        my $self = bless { oneshot => 1, env => \%ENV }, __PACKAGE__;
+        for (0..2) { open($self->{$_}, '+<&=', $_) or die "open fd=$_: $!" }
         dispatch($self, @ARGV);
         x_it($self, $self->{child_error}) if $self->{child_error};
 }