unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [RFC] treewide: handle multi-bit O_RDWR and O_APPEND flags
@ 2023-02-14 11:35 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-02-14 11:35 UTC (permalink / raw)
  To: meta

I'm not sure if this is necessary for some odd platforms, but
there could be some OS which uses a multi-bit O_RDWR and/or
O_APPEND flag and we'd need to check all the bits are set,
not just one bit.

This patch is not necessary on Linux nor FreeBSD.  I assume
what goes for well-established flags on FreeBSD also applies
to NetBSD and OpenBSD, too.

Only found via random code reading.
---
 lib/PublicInbox/LeiOverview.pm | 4 ++--
 lib/PublicInbox/WwwCoderepo.pm | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm
index 066c40bd..a3b41b64 100644
--- a/lib/PublicInbox/LeiOverview.pm
+++ b/lib/PublicInbox/LeiOverview.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # per-mitem/smsg iterators for search results
@@ -90,7 +90,7 @@ sub new {
 		if (!$isatty && -f _) {
 			my $fl = fcntl($lei->{$devfd}, F_GETFL, 0) //
 					die("fcntl(/dev/fd/$devfd): $!\n");
-			ovv_out_lk_init($self) unless ($fl & O_APPEND);
+			ovv_out_lk_init($self) if ($fl & O_APPEND) != O_APPEND;
 		} else {
 			ovv_out_lk_init($self);
 		}
diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm
index 7a2cb80b..44840cb5 100644
--- a/lib/PublicInbox/WwwCoderepo.pm
+++ b/lib/PublicInbox/WwwCoderepo.pm
@@ -82,7 +82,7 @@ sub new {
 	my @s = stat(STDIN) or die "stat(STDIN): $!";
 	if ("@l[0, 1]" eq "@s[0, 1]") {
 		my $f = fcntl(STDIN, F_GETFL, 0) // die "F_GETFL: $!";
-		$self->{log_fh} = *STDIN{IO} if $f & O_RDWR;
+		$self->{log_fh} = *STDIN{IO} if ($f & O_RDWR) == O_RDWR;
 	}
 	$self;
 }

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-14 11:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 11:35 [RFC] treewide: handle multi-bit O_RDWR and O_APPEND flags Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).