user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] daemon: don't bother checking for existing FD flags
@ 2023-01-03  0:05 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-01-03  0:05 UTC (permalink / raw)
  To: meta

FD_CLOEXEC is the only currently defined FD flag, and has been
the case for decades at this point.  I highly doubt any default
FD flag will ever be forced on us by the kernel, init system, or
Perl.  So save ourselves a syscall and just call F_SETFD with
the assumption FD_CLOEXEC is the only FD flag that we'd ever
care for.
---
 lib/PublicInbox/DS.pm     | 3 +--
 lib/PublicInbox/Daemon.pm | 7 ++-----
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index a6c43b22..e4629e97 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -130,8 +130,7 @@ sub _InitPoller () {
 		my $fd = epoll_create();
 		die "epoll_create: $!" if $fd < 0;
 		open($ep_io, '+<&=', $fd) or return;
-		my $fl = fcntl($ep_io, F_GETFD, 0);
-		fcntl($ep_io, F_SETFD, $fl | FD_CLOEXEC);
+		fcntl($ep_io, F_SETFD, FD_CLOEXEC);
 		$fd;
 	} else {
 		my $cls;
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 16bae231..ee746f05 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -11,7 +11,7 @@ use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 use IO::Handle; # ->autoflush
 use IO::Socket;
 use File::Spec;
-use POSIX qw(WNOHANG :signal_h);
+use POSIX qw(WNOHANG :signal_h F_SETFD);
 use Socket qw(IPPROTO_TCP SOL_SOCKET);
 STDOUT->autoflush(1);
 STDERR->autoflush(1);
@@ -478,15 +478,12 @@ sub upgrade { # $_[0] = signal name or number (unused)
 		return;
 	}
 	if ($pid == 0) {
-		use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
 		$ENV{LISTEN_FDS} = scalar @listeners;
 		$ENV{LISTEN_PID} = $$;
 		foreach my $s (@listeners) {
 			# @listeners are globs with workers, PI::L w/o workers
 			$s = $s->{sock} if ref($s) eq 'PublicInbox::Listener';
-
-			my $fl = fcntl($s, F_GETFD, 0);
-			fcntl($s, F_SETFD, $fl &= ~FD_CLOEXEC);
+			fcntl($s, F_SETFD, 0) // die "F_SETFD: $!";
 		}
 		exec @CMD;
 		die "Failed to exec: $!\n";

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

only message in thread, other threads:[~2023-01-03  0:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03  0:05 [PATCH] daemon: don't bother checking for existing FD flags Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).