]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: don't bother checking for existing FD flags
authorEric Wong <e@80x24.org>
Tue, 3 Jan 2023 00:05:06 +0000 (00:05 +0000)
committerEric Wong <e@80x24.org>
Tue, 3 Jan 2023 00:20:45 +0000 (00:20 +0000)
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
lib/PublicInbox/Daemon.pm

index a6c43b22d960ae9c01765e126677f3521c44e115..e4629e97acc461aaa2debbe1687db8f0aecab796 100644 (file)
@@ -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;
index 16bae23106e746cd4dd53c7cfb99dcc83693eb79..ee746f057d66b5a1df5daa196671026323d72bab 100644 (file)
@@ -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";