]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Watch.pm
use defined-or in a few more places
[public-inbox.git] / lib / PublicInbox / Watch.pm
index e1246096dc7b70fd0e1fadfa3e93ccc4df7a7bfc..2b44ba430cfb957692da367a0550431f1809ebc6 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # ref: https://cr.yp.to/proto/maildir.html
@@ -217,7 +217,7 @@ sub _try_path {
                warn "unmappable dir: $1\n";
                return;
        }
-       my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+       my $warn_cb = $SIG{__WARN__} || \&CORE::warn;
        local $SIG{__WARN__} = sub {
                my $pfx = ($_[0] // '') =~ /^([A-Z]: )/g ? $1 : '';
                $warn_cb->($pfx, "path: $path\n", @_);
@@ -467,7 +467,7 @@ sub imap_fetch_all ($$$) {
        my $key = $req;
        $key =~ s/\.PEEK//;
        my ($uids, $batch);
-       my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+       my $warn_cb = $SIG{__WARN__} || \&CORE::warn;
        local $SIG{__WARN__} = sub {
                my $pfx = ($_[0] // '') =~ /^([A-Z]: )/g ? $1 : '';
                $batch //= '?';
@@ -583,13 +583,13 @@ sub watch_atfork_child ($) {
        delete $self->{opendirs};
        PublicInbox::DS->Reset;
        %SIG = (%SIG, %{$self->{sig}}, CHLD => 'DEFAULT');
-       PublicInbox::Sigfd::sig_setmask($self->{oldset});
+       PublicInbox::DS::sig_setmask($self->{oldset});
 }
 
 sub watch_atfork_parent ($) {
        my ($self) = @_;
        _done_for_now($self);
-       PublicInbox::Sigfd::block_signals();
+       PublicInbox::DS::block_signals();
 }
 
 sub imap_idle_requeue ($) { # DS::add_timer callback
@@ -625,8 +625,11 @@ sub imap_idle_fork ($$) {
        my ($self, $url_intvl) = @_;
        my ($url, $intvl) = @$url_intvl;
        pipe(my ($r, $w)) or die "pipe: $!";
-       defined(my $pid = fork) or die "fork: $!";
+       my $seed = rand(0xffffffff);
+       my $pid = fork // die "fork: $!";
        if ($pid == 0) {
+               srand($seed);
+               eval { Net::SSLeay::randomize() };
                close $r;
                watch_atfork_child($self);
                watch_imap_idle_1($self, $url, $intvl);
@@ -648,7 +651,7 @@ sub event_step {
                                imap_idle_fork($self, $url_intvl);
                        }
                };
-               PublicInbox::Sigfd::sig_setmask($oldset);
+               PublicInbox::DS::sig_setmask($oldset);
                die $@ if $@;
        }
        fs_scan_step($self) if $self->{mdre};
@@ -704,8 +707,11 @@ sub poll_fetch_fork ($) { # DS::add_timer callback
        return if $self->{quit};
        pipe(my ($r, $w)) or die "pipe: $!";
        my $oldset = watch_atfork_parent($self);
+       my $seed = rand(0xffffffff);
        my $pid = fork;
        if (defined($pid) && $pid == 0) {
+               srand($seed);
+               eval { Net::SSLeay::randomize() };
                close $r;
                watch_atfork_child($self);
                if ($urls->[0] =~ m!\Aimaps?://!i) {
@@ -716,7 +722,7 @@ sub poll_fetch_fork ($) { # DS::add_timer callback
                close $w;
                _exit(0);
        }
-       PublicInbox::Sigfd::sig_setmask($oldset);
+       PublicInbox::DS::sig_setmask($oldset);
        die "fork: $!"  unless defined $pid;
        $self->{poll_pids}->{$pid} = [ $intvl, $urls ];
        PublicInbox::EOFpipe->new($r, \&reap, [$pid, \&poll_fetch_reap, $self]);
@@ -929,7 +935,7 @@ sub nntp_fetch_all ($$$) {
        $beg = $l_art + 1;
 
        warn "I: $url fetching ARTICLE $beg..$end\n";
-       my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+       my $warn_cb = $SIG{__WARN__} || \&CORE::warn;
        my ($err, $art);
        local $SIG{__WARN__} = sub {
                my $pfx = ($_[0] // '') =~ /^([A-Z]: )/g ? $1 : '';