From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 774A31FA19 for ; Thu, 14 Jan 2021 07:06:28 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/14] lei: rely on localized $current_lei for warnings Date: Wed, 13 Jan 2021 19:06:19 -1200 Message-Id: <20210114070627.18195-7-e@80x24.org> In-Reply-To: <20210114070627.18195-1-e@80x24.org> References: <20210114070627.18195-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This lets us get rid of the Sys::Syslog import and __WARN__ override in LeiXSearch, though we still need it with ->atfork_child_wq. --- lib/PublicInbox/LEI.pm | 7 +++++-- lib/PublicInbox/LeiXSearch.pm | 7 ------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index fd2b722c..a8fea16d 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -26,6 +26,7 @@ use Text::Wrap qw(wrap); use File::Path qw(mkpath); use File::Spec; our $quit = \&CORE::exit; +our $current_lei; my ($recv_cmd, $send_cmd); my $GLP = Getopt::Long::Parser->new; $GLP->configure(qw(gnu_getopt no_ignore_case auto_abbrev)); @@ -447,7 +448,7 @@ sub optparse ($$$) { sub dispatch { my ($self, $cmd, @argv) = @_; - local $SIG{__WARN__} = sub { err($self, @_) }; + local $current_lei = $self; # for __WARN__ return _help($self, 'no command given') unless defined($cmd); my $func = "lei_$cmd"; $func =~ tr/-/_/; @@ -849,7 +850,9 @@ sub lazy_start { # STDOUT will cause the calling `lei' client process to finish # reading the <$daemon> pipe. openlog($path, 'pid', 'user'); - local $SIG{__WARN__} = sub { syslog('warning', "@_") }; + local $SIG{__WARN__} = sub { + $current_lei ? err($current_lei, @_) : syslog('warning', "@_"); + }; my $on_destroy = PublicInbox::OnDestroy->new($$, sub { syslog('crit', "$@") if $@; }); diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index d06b6f1d..68889e81 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -8,7 +8,6 @@ package PublicInbox::LeiXSearch; use strict; use v5.10.1; use parent qw(PublicInbox::LeiSearch PublicInbox::IPC); -use Sys::Syslog qw(syslog); sub new { my ($class) = @_; @@ -187,12 +186,6 @@ sub do_query { } } -sub ipc_atfork_child { - my ($self) = @_; - $SIG{__WARN__} = sub { syslog('warning', "@_") }; - $self->SUPER::ipc_atfork_child; # PublicInbox::IPC -} - sub ipc_atfork_prepare { my ($self) = @_; $self->wq_set_recv_modes(qw[+<&= >&= >&= +<&=]);