From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 90E201F454 for ; Sun, 8 Oct 2023 05:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696744231; bh=gKp4XvD1ofRPMPfkBEtdBwYrJHffqypJA1i8emcZg4I=; h=Date:From:To:Subject:References:In-Reply-To:From; b=pG54JEj7Zb/gJOt8Tp4Uddic5O/uqVFokL4HywHSTKPLGdUWrh8xkbyUITPD5+y5k aHwniYLyOcEkWjYbICvNyK/whP6CdROyOnpf76HO/iKqfkOnb2FOl0KSQtMLlJKa9W UFGr6Rsd4SH37A2pBimCyrbn7P+/nUaAgsUBVqUU= Date: Sun, 8 Oct 2023 05:49:34 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2.5/9] lei: fix implicit stdin support for pipes Message-ID: <20231008054934.M408319@dcvr> References: <20231007212410.297785-1-e@80x24.org> <20231007212410.297785-4-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231007212410.297785-4-e@80x24.org> List-Id: 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. --- lib/PublicInbox/LEI.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index f00b2465..1ba2c2a1 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;