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";

Reply via email to