X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FDaemon.pm;h=b929ec2aa17e1cb83549a41d27035fd578cb8515;hb=ee8cadb3a71ab4c951642a96ba123688244de720;hp=ab0c2226e407037dd5889d0b8a3d271c01da7020;hpb=58c0333adbdd9f5f82309cb6eef3c379f0ff064e;p=public-inbox.git diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index ab0c2226..b929ec2a 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -15,9 +15,9 @@ use Cwd qw/abs_path/; STDOUT->autoflush(1); STDERR->autoflush(1); use PublicInbox::DS qw(now); -use PublicInbox::Syscall qw(SFD_NONBLOCK); +use PublicInbox::Syscall qw($SFD_NONBLOCK); require PublicInbox::Listener; -require PublicInbox::ParentPipe; +use PublicInbox::EOFpipe; use PublicInbox::Sigfd; my @CMD; my ($set_user, $oldset); @@ -75,9 +75,22 @@ sub accept_tls_opt ($) { sub daemon_prepare ($) { my ($default_listen) = @_; my $listener_names = {}; # sockname => IO::Handle - my $oldset = PublicInbox::Sigfd::block_signals(); + $oldset = PublicInbox::Sigfd::block_signals(); @CMD = ($0, @ARGV); - my %opts = ( + my ($prog) = ($CMD[0] =~ m!([^/]+)\z!g); + my $help = < \@cfg_listen, '1|stdout=s' => \$stdout, '2|stderr=s' => \$stderr, @@ -88,8 +101,10 @@ sub daemon_prepare ($) { 'D|daemonize' => \$daemonize, 'cert=s' => \$default_cert, 'key=s' => \$default_key, + 'help|h' => \(my $show_help), ); - GetOptions(%opts) or die "bad command-line args\n"; + GetOptions(%opt) or die $help; + if ($show_help) { print $help; exit 0 }; if (defined $pid_file && $pid_file =~ /\.oldbin\z/) { die "--pid-file cannot end with '.oldbin'\n"; @@ -468,8 +483,6 @@ sub master_quit ($) { sub master_loop { pipe(my ($p0, $p1)) or die "failed to create parent-pipe: $!"; - # 1031: F_SETPIPE_SZ, 4096: page size - fcntl($p1, 1031, 4096) if $^O eq 'linux'; my $set_workers = $worker_processes; reopen_logs(); my $ignore_winch; @@ -510,7 +523,7 @@ EOF }; my $sigfd = PublicInbox::Sigfd->new($sig, 0); local %SIG = (%SIG, %$sig) if !$sigfd; - PublicInbox::restore_signals($oldset) if !$sigfd; + PublicInbox::Sigfd::sig_setmask($oldset) if !$sigfd; while (1) { # main loop my $n = scalar keys %pids; unless (@listeners) { @@ -539,7 +552,7 @@ EOF $pids{$pid} = $i; } } - PubliInbox::Sigfd::set_sigmask($oldset) if !$sigfd; + PublicInbox::Sigfd::sig_setmask($oldset) if !$sigfd; } if ($sigfd) { # Linux and IO::KQueue users: @@ -603,7 +616,7 @@ sub daemon_loop ($$$$) { if ($worker_processes > 0) { $refresh->(); # preload by default my $fh = master_loop(); # returns if in child process - PublicInbox::ParentPipe->new($fh, \&worker_quit); + PublicInbox::EOFpipe->new($fh, \&worker_quit, undef); } else { reopen_logs(); $set_user->() if $set_user; @@ -622,12 +635,12 @@ sub daemon_loop ($$$$) { # this calls epoll_create: PublicInbox::Listener->new($_, $tls_cb || $post_accept) } @listeners; - my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK); + my $sigfd = PublicInbox::Sigfd->new($sig, $SFD_NONBLOCK); local %SIG = (%SIG, %$sig) if !$sigfd; if (!$sigfd) { # wake up every second to accept signals if we don't # have signalfd or IO::KQueue: - PublicInbox::Sigfd::set_sigmask($oldset); + PublicInbox::Sigfd::sig_setmask($oldset); PublicInbox::DS->SetLoopTimeout(1000); } PublicInbox::DS->EventLoop;