]> Sergey Matveev's repositories - public-inbox.git/commitdiff
default to CORE::warn in $SIG{__WARN__} handlers
authorEric Wong <e@80x24.org>
Sat, 26 Dec 2020 01:44:36 +0000 (01:44 +0000)
committerEric Wong <e@80x24.org>
Sat, 26 Dec 2020 19:27:15 +0000 (19:27 +0000)
As with CORE::die and $SIG{__DIE__}, it turns out CORE::warn is
safe to use inside $SIG{__WARN__} handlers without triggering
infinite recursion.  So fall back to reusing CORE::warn instead
of creating a new sub.

lib/PublicInbox/Admin.pm
lib/PublicInbox/ExtSearchIdx.pm
lib/PublicInbox/InboxWritable.pm
lib/PublicInbox/Watch.pm

index b468108e8ab654f8cb7288c65dff0905c7b776ea..d414e4e205d95167b5a2cad241936fc12cd55d6b 100644 (file)
@@ -241,7 +241,7 @@ sub index_inbox {
        }
        local %SIG = %SIG;
        setup_signals(\&index_terminate, $ibx);
-       my $warn_cb = $SIG{__WARN__} // sub { print STDERR @_ };
+       my $warn_cb = $SIG{__WARN__} // \&CORE::warn;
        my $idx = { current_info => $ibx->{inboxdir} };
        my $warn_ignore = PublicInbox::InboxWritable->can('warn_ignore');
        local $SIG{__WARN__} = sub {
index e7fdae48ed79ac4f9eecdd14caac8cf8ea98976d..64ebf6db4837ba9899bca11ea5882d4dccfd0e01 100644 (file)
@@ -841,7 +841,7 @@ sub eidx_reindex {
 sub eidx_sync { # main entry point
        my ($self, $opt) = @_;
 
-       my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+       my $warn_cb = $SIG{__WARN__} || \&CORE::warn;
        local $self->{current_info} = '';
        local $SIG{__WARN__} = sub {
                $warn_cb->($self->{current_info}, ': ', @_);
index 31eb3f15a94821e6725cbc8816c73b9066b37f4e..b1d5caf53c73f092731b29994cbdd8ece953a5fc 100644 (file)
@@ -292,7 +292,7 @@ sub warn_ignore {
 
 # this expects to be RHS in this assignment: "local $SIG{__WARN__} = ..."
 sub warn_ignore_cb {
-       my $cb = $SIG{__WARN__} // sub { print STDERR @_ };
+       my $cb = $SIG{__WARN__} // \&CORE::warn;
        sub {
                return if warn_ignore(@_);
                $cb->(@_);
index e1246096dc7b70fd0e1fadfa3e93ccc4df7a7bfc..bc296e01fc3ac7baec4e50dc082e7aef59457a2e 100644 (file)
@@ -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 //= '?';
@@ -929,7 +929,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 : '';