diff options
author | Eric Wong <e@80x24.org> | 2020-12-15 09:03:34 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2020-12-19 09:32:08 +0000 |
commit | 504774acd5236653cdeafb536be95fbfb147258f (patch) | |
tree | 8dd27060a8710f6aa6175c740bda5662f068adbb /lib | |
parent | d42172638f5479f76e73470ad48a679100c3e0d5 (diff) | |
download | public-inbox-504774acd5236653cdeafb536be95fbfb147258f.tar.gz |
This allows us to rely on FD_CLOEXEC being set on pipes from prove(1), so forgetting `daemon-stop' won't cause tests to hang. Unfortunately, daemon tests will be slower with this.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/LeiDaemon.pm | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/PublicInbox/LeiDaemon.pm b/lib/PublicInbox/LeiDaemon.pm index b4b1ac59..fd4d00d4 100644 --- a/lib/PublicInbox/LeiDaemon.pm +++ b/lib/PublicInbox/LeiDaemon.pm @@ -324,29 +324,27 @@ sub accept_dispatch { # Listener {post_accept} callback sub noop {} # lei(1) calls this when it can't connect -sub lazy_start ($$) { +sub lazy_start { my ($path, $err) = @_; if ($err == ECONNREFUSED) { unlink($path) or die "unlink($path): $!"; } elsif ($err != ENOENT) { die "connect($path): $!"; } + require IO::FDPass; my $umask = umask(077) // die("umask(077): $!"); my $l = IO::Socket::UNIX->new(Local => $path, Listen => 1024, Type => SOCK_STREAM) or $err = $!; umask($umask) or die("umask(restore): $!"); - $l or return $err; + $l or return die "bind($path): $err"; my @st = stat($path) or die "stat($path): $!"; my $dev_ino_expect = pack('dd', $st[0], $st[1]); # dev+ino pipe(my ($eof_r, $eof_w)) or die "pipe: $!"; my $oldset = PublicInbox::Sigfd::block_signals(); my $pid = fork // die "fork: $!"; - if ($pid) { - PublicInbox::Sigfd::sig_setmask($oldset); - return; # client will connect to $path - } + return if $pid; openlog($path, 'pid', 'user'); local $SIG{__DIE__} = sub { syslog('crit', "@_"); @@ -360,7 +358,7 @@ sub lazy_start ($$) { open STDERR, '>&STDIN' or die "redirect stderr failed: $!\n"; setsid(); $pid = fork // die "fork: $!"; - exit if $pid; + return if $pid; $0 = "lei-daemon $path"; require PublicInbox::Listener; require PublicInbox::EOFpipe; |