* [PATCH 1/8] lei: dump errors to syslog, and not to CLI
2021-09-03 8:54 6% [PATCH 0/8] lei: fix IMAP R/W; L/kw false positives Eric Wong
@ 2021-09-03 8:54 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-09-03 8:54 UTC (permalink / raw)
To: meta
Dumping errors from the previous run can often get lost, so just
spew to syslog since it's a standard place to put errors that
don't make it to a client. Note: we don't rely on $SIG{__WARN__}
since some of the Net:: stuff will write directly to STDERR
(as will external processes).
---
lib/PublicInbox/LEI.pm | 16 +++++++++-------
lib/PublicInbox/LeiStoreErr.pm | 4 ++--
t/lei-daemon.t | 5 -----
3 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 41e811ca..9e9aa165 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -27,6 +27,7 @@ use PublicInbox::Eml;
use Time::HiRes qw(stat); # ctime comparisons for config cache
use File::Path qw(mkpath);
use File::Spec;
+use Sys::Syslog qw(openlog syslog closelog);
our $quit = \&CORE::exit;
our ($current_lei, $errors_log, $listener, $oldset, $dir_idle,
$recv_cmd, $send_cmd);
@@ -464,7 +465,6 @@ sub x_it ($$) {
my ($self, $code) = @_;
# make sure client sees stdout before exit
$self->{1}->autoflush(1) if $self->{1};
- dump_and_clear_log();
stop_pager($self);
if ($self->{pkt_op_p}) { # to top lei-daemon
$self->{pkt_op_p}->pkt_do('x_it', $code);
@@ -765,7 +765,6 @@ sub dispatch {
my ($self, $cmd, @argv) = @_;
local $current_lei = $self; # for __WARN__
$self->{2}->autoflush(1); # keep stdout buffered until x_it|DESTROY
- dump_and_clear_log("from previous run\n");
return _help($self, 'no command given') unless defined($cmd);
# do not support Getopt bundling for this
while ($cmd eq '-C' || $cmd eq '-c') {
@@ -1147,10 +1146,12 @@ sub oldset { $oldset }
sub dump_and_clear_log {
if (defined($errors_log) && -s STDIN && seek(STDIN, 0, SEEK_SET)) {
- my @pfx = @_;
- unshift(@pfx, "$errors_log ") if @pfx;
- warn @pfx, do { local $/; <STDIN> };
- truncate(STDIN, 0) or warn "ftruncate ($errors_log): $!";
+ openlog('lei-daemon', 'pid,nowait,nofatal,ndelay', 'user');
+ chomp(my @lines = <STDIN>);
+ truncate(STDIN, 0) or
+ syslog('warning', "ftruncate (%s): %m", $errors_log);
+ for my $l (@lines) { syslog('warning', '%s', $l) }
+ closelog(); # don't share across fork
}
}
@@ -1243,7 +1244,7 @@ sub lazy_start {
(-p STDOUT) or die "E: stdout must be a pipe\n";
open(STDIN, '+>>', $errors_log) or die "open($errors_log): $!";
STDIN->autoflush(1);
- dump_and_clear_log("from previous daemon process:\n");
+ dump_and_clear_log();
POSIX::setsid() > 0 or die "setsid: $!";
my $pid = fork // die "fork: $!";
return if $pid;
@@ -1345,6 +1346,7 @@ sub DESTROY {
}
$self->{1}->autoflush(1) if $self->{1};
stop_pager($self);
+ dump_and_clear_log();
# preserve $? for ->fail or ->x_it code
}
diff --git a/lib/PublicInbox/LeiStoreErr.pm b/lib/PublicInbox/LeiStoreErr.pm
index 5f9ba24d..cc085fdc 100644
--- a/lib/PublicInbox/LeiStoreErr.pm
+++ b/lib/PublicInbox/LeiStoreErr.pm
@@ -2,7 +2,7 @@
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# forwards stderr from lei/store process to any lei clients using
-# the same store
+# the same store, falls back to syslog if no matching clients exist.
package PublicInbox::LeiStoreErr;
use strict;
use v5.10.1;
@@ -31,7 +31,7 @@ sub event_step {
print $err $$rbuf and $printed = 1;
}
if (!$printed) {
- openlog('lei-store', 'pid,nowait,nofatal,ndelay', 'user');
+ openlog('lei/store', 'pid,nowait,nofatal,ndelay', 'user');
for my $l (split(/\n/, $$rbuf)) { syslog('warning', '%s', $l) }
closelog(); # don't share across fork
}
diff --git a/t/lei-daemon.t b/t/lei-daemon.t
index a7c4b799..b0c94a87 100644
--- a/t/lei-daemon.t
+++ b/t/lei-daemon.t
@@ -21,14 +21,9 @@ test_lei({ daemon_only => 1 }, sub {
ok(kill(0, $pid), 'pid is valid');
ok(-S $sock, 'sock created');
is(-s $err_log, 0, 'nothing in errors.log');
- open my $efh, '>>', $err_log or BAIL_OUT $!;
- print $efh "phail\n" or BAIL_OUT $!;
- close $efh or BAIL_OUT $!;
-
lei_ok('daemon-pid');
chomp(my $pid_again = $lei_out);
is($pid, $pid_again, 'daemon-pid idempotent');
- like($lei_err, qr/phail/, 'got mock "phail" error previous run');
SKIP: {
skip 'only testing open files on Linux', 1 if $^O ne 'linux';
^ permalink raw reply related [relevance 7%]
* [PATCH 0/8] lei: fix IMAP R/W; L/kw false positives
@ 2021-09-03 8:54 6% Eric Wong
2021-09-03 8:54 7% ` [PATCH 1/8] lei: dump errors to syslog, and not to CLI Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-09-03 8:54 UTC (permalink / raw)
To: meta
Back to using syslog more for errors, since it's still less
instrusive. IMAP R/W is fixed (ugh, lack of automatic tests
since we only have a read-only IMAP server for testing).
Some error/warning fixes, and false-positives on L: and kw:
searches on local (but not remote) externals are avoided.
"lei inspect --stdin" was somewhat useful for figuring out why
L: was false-positiving an external result on me.
Eric Wong (8):
lei: dump errors to syslog, and not to CLI
lei/store: quiet down link(2) warnings
lei: ->child_error less error-prone
lei: use lei->lms in place of lse->lms in a few places
lei up --all: avoid double-close on shared STDOUT
lei inspect: support reading eml from --stdin
lei_xsearch: avoid false-positives on externals w/ L: and kw:
lei: fix read/write IMAP access
MANIFEST | 1 +
lib/PublicInbox/LEI.pm | 27 ++++++++++--------
lib/PublicInbox/LeiBlob.pm | 2 +-
lib/PublicInbox/LeiIndex.pm | 2 +-
lib/PublicInbox/LeiInput.pm | 4 +--
lib/PublicInbox/LeiInspect.pm | 43 ++++++++++++++++++++++++-----
lib/PublicInbox/LeiLcat.pm | 2 +-
lib/PublicInbox/LeiPruneMailSync.pm | 26 ++++++++---------
lib/PublicInbox/LeiRediff.pm | 2 +-
lib/PublicInbox/LeiStore.pm | 10 ++-----
lib/PublicInbox/LeiStoreErr.pm | 4 +--
lib/PublicInbox/LeiToMail.pm | 2 +-
lib/PublicInbox/LeiUp.pm | 6 +++-
lib/PublicInbox/LeiXSearch.pm | 1 +
lib/PublicInbox/NetReader.pm | 5 +++-
lib/PublicInbox/NetWriter.pm | 2 ++
lib/PublicInbox/Watch.pm | 2 ++
t/lei-daemon.t | 5 ----
t/lei-up.t | 39 ++++++++++++++++++++++++++
19 files changed, 130 insertions(+), 55 deletions(-)
create mode 100644 t/lei-up.t
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-09-03 8:54 6% [PATCH 0/8] lei: fix IMAP R/W; L/kw false positives Eric Wong
2021-09-03 8:54 7% ` [PATCH 1/8] lei: dump errors to syslog, and not to CLI Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).