From d8e484ae25145b9a98e45b649b0ee5b81b43aee0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 9 Dec 2025 11:08:09 +0000 Subject: [PATCH] daemon: set FD_CLOEXEC on per-port out= and err= paths Neither xap_helper nor git(1) subprocesses we spawn use the the per-port log files we can assign to the daemon processes. So ensure these per-port standard err= and out= log files do not stay open and run servers out-of-space. Furthermore, we can rely on autodie::fnctl throughout Daemon.pm to detect errors and remove explicit error checking. --- lib/PublicInbox/Daemon.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 5b43375b3..682796977 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -6,13 +6,13 @@ # and/or lossy connections. package PublicInbox::Daemon; use v5.12; -use autodie qw(chdir open pipe setsockopt); +use autodie qw(chdir fcntl open pipe setsockopt); use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev); use IO::Handle; # ->autoflush use IO::Socket; use File::Spec; use IO::Poll qw(POLLERR POLLIN POLLHUP); -use POSIX qw(WNOHANG :signal_h F_SETFD); +use POSIX qw(WNOHANG :signal_h F_SETFD FD_CLOEXEC); use Socket qw(IPPROTO_TCP SOL_SOCKET); STDOUT->autoflush(1); STDERR->autoflush(1); @@ -113,6 +113,7 @@ sub open_log_path ($$) { # my ($fh, $path) = @_; # $_[0] is modified if (defined $_[0]) { open my $tmp_fh, '>>', $_[1]; POSIX::dup2(fileno($tmp_fh), fileno($_[0])) or die "dup2: $!"; + fcntl($_[0], F_SETFD, FD_CLOEXEC) if fileno($_[0]) > 2; } else { open $_[0], '>>', $_[1]; } @@ -540,7 +541,7 @@ sub upgrade { # $_[0] = signal name or number (unused) foreach my $s (@listeners) { # @listeners are globs with workers, PI::L w/o workers $s = $s->{sock} if ref($s) eq 'PublicInbox::Listener'; - fcntl($s, F_SETFD, 0) // die "F_SETFD: $!"; + fcntl $s, F_SETFD, 0; } exec @CMD; die "Failed to exec: $!\n"; -- 2.47.3