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-ASN: 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 9663B1F9F3 for ; Fri, 3 Sep 2021 08:54:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/8] lei: ->child_error less error-prone Date: Fri, 3 Sep 2021 08:54:22 +0000 Message-Id: <20210903085427.5541-4-e@80x24.org> In-Reply-To: <20210903085427.5541-1-e@80x24.org> References: <20210903085427.5541-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: I was calling "child_error(1, ...)" in a few places where I meant to be calling "child_error(1 << 8, ...)" and inadvertantly triggering SIGHUP in script/lei. Since giving a zero exit code to child_error makes no sense, just allow falsy values to default to 1 << 8. --- lib/PublicInbox/LEI.pm | 7 ++++--- lib/PublicInbox/LeiBlob.pm | 2 +- lib/PublicInbox/LeiIndex.pm | 2 +- lib/PublicInbox/LeiInput.pm | 4 ++-- lib/PublicInbox/LeiLcat.pm | 2 +- lib/PublicInbox/LeiRediff.pm | 2 +- lib/PublicInbox/LeiUp.pm | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 9e9aa165..8b6c1d36 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -532,6 +532,7 @@ sub puts ($;@) { out(shift, map { "$_\n" } @_) } sub child_error { # passes non-fatal curl exit codes to user my ($self, $child_error, $msg) = @_; # child_error is $? + $child_error ||= 1 << 8; $self->err($msg) if $msg; if ($self->{pkt_op_p}) { # to top lei-daemon $self->{pkt_op_p}->pkt_do('child_error', $child_error); @@ -1341,7 +1342,7 @@ sub DESTROY { if (my $counters = delete $self->{counters}) { for my $k (sort keys %$counters) { my $nr = $counters->{$k}; - $self->child_error(1 << 8, "$nr $k messages"); + $self->child_error(0, "$nr $k messages"); } } $self->{1}->autoflush(1) if $self->{1}; @@ -1417,7 +1418,7 @@ sub refresh_watches { add_maildir_watch($d, $cfg_f); } } else { # TODO: imap/nntp/jmap - $lei->child_error(1, "E: watch $url not supported, yet") + $lei->child_error(0, "E: watch $url not supported, yet") } } @@ -1452,7 +1453,7 @@ sub refresh_watches { my $d = canonpath_harder($1); cancel_maildir_watch($d, $cfg_f); } else { # TODO: imap/nntp/jmap - $lei->child_error(1, "E: watch $url TODO"); + $lei->child_error(0, "E: watch $url TODO"); } } } diff --git a/lib/PublicInbox/LeiBlob.pm b/lib/PublicInbox/LeiBlob.pm index 21003894..b94f67a0 100644 --- a/lib/PublicInbox/LeiBlob.pm +++ b/lib/PublicInbox/LeiBlob.pm @@ -32,7 +32,7 @@ sub solver_user_cb { # called by solver when done my $lei = $self->{lei}; my $log_buf = delete $lei->{'log_buf'}; $$log_buf =~ s/^/# /sgm; - ref($res) eq 'ARRAY' or return $lei->child_error(1 << 8, $$log_buf); + ref($res) eq 'ARRAY' or return $lei->child_error(0, $$log_buf); $lei->qerr($$log_buf); my ($git, $oid, $type, $size, $di) = @$res; my $gd = $git->{git_dir}; diff --git a/lib/PublicInbox/LeiIndex.pm b/lib/PublicInbox/LeiIndex.pm index 5b545998..ef3e4d0b 100644 --- a/lib/PublicInbox/LeiIndex.pm +++ b/lib/PublicInbox/LeiIndex.pm @@ -21,7 +21,7 @@ sub input_eml_cb { # used by input_maildir_cb and input_net_cb sub input_fh { # overrides PublicInbox::LeiInput::input_fh my ($self, $ifmt, $fh, $input, @args) = @_; - $self->{lei}->child_error(1<<8, <{lei}->child_error(0, < } // - return $self->{lei}->child_error(1 << 8, <<""); + return $self->{lei}->child_error(0, <<""); error reading $name: $! # mutt pipes single RFC822 messages with a "From " line, @@ -104,7 +104,7 @@ sub handle_http_input ($$@) { my $err = $@; waitpid($pid, 0); $? || $err and - $lei->child_error($? || 1, "@$cmd failed".$err ? " $err" : ''); + $lei->child_error($?, "@$cmd failed".$err ? " $err" : ''); } sub input_path_url { diff --git a/lib/PublicInbox/LeiLcat.pm b/lib/PublicInbox/LeiLcat.pm index 9d95e899..1e54c3bf 100644 --- a/lib/PublicInbox/LeiLcat.pm +++ b/lib/PublicInbox/LeiLcat.pm @@ -18,7 +18,7 @@ sub lcat_folder ($$$) { my $err = $lms->arg2folder($lei, $folders); $lei->qerr(@{$err->{qerr}}) if $err && $err->{qerr}; if ($err && $err->{fail}) { - $lei->child_error(1 << 8, "# unknown folder: $folder"); + $lei->child_error(0, "# unknown folder: $folder"); } else { for my $f (@$folders) { my $fid = $lms->fid_for($f); diff --git a/lib/PublicInbox/LeiRediff.pm b/lib/PublicInbox/LeiRediff.pm index 0ba5897c..60286b06 100644 --- a/lib/PublicInbox/LeiRediff.pm +++ b/lib/PublicInbox/LeiRediff.pm @@ -23,7 +23,7 @@ sub rediff_user_cb { # called by solver when done my $lei = $self->{lei}; my $log_buf = delete $lei->{log_buf}; $$log_buf =~ s/^/# /sgm; - ref($res) eq 'ARRAY' or return $lei->child_error(1 << 8, $$log_buf); + ref($res) eq 'ARRAY' or return $lei->child_error(0, $$log_buf); $lei->qerr($$log_buf); my ($git, $oid, $type, $size, $di) = @$res; my $oid_want = delete $self->{cur_oid_want}; diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm index 85efd9f5..e1da64aa 100644 --- a/lib/PublicInbox/LeiUp.pm +++ b/lib/PublicInbox/LeiUp.pm @@ -59,7 +59,7 @@ sub up1_redispatch { up1($l, $out); $l->qerr("# $out done"); }; - $l->child_error(1 << 8, $@) if $@; + $l->child_error(0, $@) if $@; } sub lei_up {