From: Eric Wong Date: Sun, 8 Oct 2023 05:49:34 +0000 (+0000) Subject: lei: fix implicit stdin support for pipes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e522fd43913f26db5b99f2417a0d863439634ff5;p=thirdparty%2Fpublic-inbox.git lei: fix implicit stdin support for pipes Eric Wong wrote: > +++ b/t/lei-store-fail.t > + my $cmd = [ qw(lei import -q -F mboxrd) ]; > + my $tp = start_script($cmd, undef, $opt); Of course the lack of `-' or `--stdin' only worked on Linux and NetBSD, but not other BSDs. -------8<------ Subject: [PATCH] lei: fix implicit stdin support for pipes st_mode permission bits can't be used to determine if a file or pipe we have on stdin readable or not. Writable regular files can be opened O_RDONLY, and permissions bits for pipes are inconsistent across platforms. On FreeBSD, OpenBSD, and Dragonfly, only the S_IFIFO bit is set in st_mode with none of the permission bits are set. Linux and NetBSD have both the read and write permission bits set for both ends of a the pipe, so they're just as inaccurate but allowed the feature to work before this change. For now, we'll just assume our users know that stdin is intended for input and consider any pipe or regular file to be readable. If we were to be pedantic, we'd check O_RDONLY or O_RDWR description flags via the F_GETFL fcntl(2) op to determine if a pipe or socket is readable. However, I don't think it's worth the code to do so. --- diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index f00b2465c..1ba2c2a18 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -747,7 +747,7 @@ sub optparse ($$$) { # w/o args means stdin if ($sw eq 'stdin' && !@$argv && (-p $self->{0} || - -f _) && -r _) { + -f _)) { $OPT->{stdin} //= 1; } $ok = defined($OPT->{$sw}) and last;