]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Daemon.pm
sigfd: fix typos and scoping on systems w/o epoll+kqueue
[public-inbox.git] / lib / PublicInbox / Daemon.pm
index 454751834fd20fa6f5140be152a59c0793d221b4..b929ec2aa17e1cb83549a41d27035fd578cb8515 100644 (file)
@@ -17,7 +17,7 @@ STDERR->autoflush(1);
 use PublicInbox::DS qw(now);
 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 = <<EOF;
+usage: $prog [-l ADDRESS] [--cert=FILE] [--key=FILE]
+
+options:
+
+  -l ADDRESS    address to listen on (default: $default_listen)
+  --cert=FILE   default SSL/TLS certificate
+  --key=FILE    default SSL/TLS certificate
+  -W WORKERS    number of worker processes to spawn (default: 1)
+
+See public-inbox-daemon(8) and $prog(1) man pages for more.
+EOF
+       my %opt = (
                'l|listen=s' => \@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;
@@ -627,7 +640,7 @@ sub daemon_loop ($$$$) {
        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;