diff options
author | Eric Wong <e@80x24.org> | 2021-03-26 09:51:25 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-03-26 23:08:18 +0000 |
commit | 65ec1f78464ce8cf4f6379aca7bbae38743c50f0 (patch) | |
tree | 0eb594c491282fdec01b7aafc39a45485a39c287 /lib/PublicInbox/LeiOverview.pm | |
parent | d69102cfff67e4308c560c5e8daa8f8a486ff24d (diff) | |
download | public-inbox-65ec1f78464ce8cf4f6379aca7bbae38743c50f0.tar.gz |
Since lei-daemon won't have the same FDs as the client, we need to special-case thse mappings and won't be able to open arbitrary, non-standard FDs. We also won't attempt to support /proc/self/fd/[0-2] since that's a Linux-ism. /dev/fd/[0-2] and /dev/std{in,out,err} are portable to FreeBSD, at least. mawk(1) also supports /dev/std{out,err}, as does gawk(1) (which supports everything we can support, and arbitrary /dev/fd/$FD).
Diffstat (limited to 'lib/PublicInbox/LeiOverview.pm')
-rw-r--r-- | lib/PublicInbox/LeiOverview.pm | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm index 96bfff24..8e26cba4 100644 --- a/lib/PublicInbox/LeiOverview.pm +++ b/lib/PublicInbox/LeiOverview.pm @@ -71,8 +71,9 @@ sub new { --$ofmt_key=$fmt and --output=$ofmt conflict } - $fmt //= 'json' if $dst eq '/dev/stdout'; - $fmt //= detect_fmt($lei, $dst) or return; + + my $devfd = $lei->path_to_fd($dst) // return; + $fmt //= $devfd >= 0 ? 'json' : (detect_fmt($lei, $dst) or return); if (index($dst, '://') < 0) { # not a URL, so assume path $dst = File::Spec->canonpath($dst); @@ -84,11 +85,11 @@ sub new { if ($fmt =~ /\A($JSONL|(?:concat)?json)\z/) { $json = $self->{json} = ref(PublicInbox::Config->json); } - if ($dst eq '/dev/stdout') { - my $isatty = $lei->{need_pager} = -t $lei->{1}; + if ($devfd >= 0) { + my $isatty = $lei->{need_pager} = -t $lei->{$devfd}; $opt->{pretty} //= $isatty; if (!$isatty && -f _) { - my $fl = fcntl($lei->{1}, F_GETFL, 0) // + my $fl = fcntl($lei->{$devfd}, F_GETFL, 0) // return $lei->fail("fcntl(stdout): $!"); ovv_out_lk_init($self) unless ($fl & O_APPEND); } else { @@ -101,7 +102,7 @@ sub new { $lei->{dedupe} //= PublicInbox::LeiDedupe->new($lei); } else { # default to the cheapest sort since MUA usually resorts - $opt->{'sort'} //= 'docid' if $dst ne '/dev/stdout'; + $opt->{'sort'} //= 'docid' if $devfd < 0; $lei->{l2m} = eval { PublicInbox::LeiToMail->new($lei) }; return $lei->fail($@) if $@; if ($opt->{mua} && $lei->{l2m}->lock_free) { |