X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FLeiStoreErr.pm;h=47fa2277f2548310b0d4f7d7eab97b895cc77d86;hb=refs%2Fheads%2Fmaster;hp=68ce96d61d05e396aaecbfa06e6c736480a75b3a;hpb=842e684f0a4154787274843eb3c9be2eef11b160;p=public-inbox.git
diff --git a/lib/PublicInbox/LeiStoreErr.pm b/lib/PublicInbox/LeiStoreErr.pm
index 68ce96d6..47fa2277 100644
--- a/lib/PublicInbox/LeiStoreErr.pm
+++ b/lib/PublicInbox/LeiStoreErr.pm
@@ -1,29 +1,38 @@
-# Copyright (C) 2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
# 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;
+use v5.12;
use parent qw(PublicInbox::DS);
-use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
+use PublicInbox::Syscall qw(EPOLLIN);
+use Sys::Syslog qw(openlog syslog closelog);
+use IO::Handle (); # ->blocking
sub new {
my ($cls, $rd, $lei) = @_;
my $self = bless { sock => $rd, store_path => $lei->store_path }, $cls;
- $self->SUPER::new($rd, EPOLLIN | EPOLLONESHOT);
+ $rd->blocking(0);
+ $self->SUPER::new($rd, EPOLLIN); # level-trigger
}
sub event_step {
my ($self) = @_;
- $self->do_read(\(my $rbuf), 4096) or return;
- my $cb;
+ my $n = sysread($self->{sock}, my $buf, 8192);
+ return ($!{EAGAIN} ? 0 : $self->close) if !defined($n);
+ return $self->close if !$n;
+ my $printed;
for my $lei (values %PublicInbox::DS::DescriptorMap) {
- $cb = $lei->can('store_path') // next;
+ my $cb = $lei->can('store_path') // next;
next if $cb->($lei) ne $self->{store_path};
my $err = $lei->{2} // next;
- print $err $rbuf;
+ print $err $buf and $printed = 1;
+ }
+ if (!$printed) {
+ openlog('lei/store', 'pid,nowait,nofatal,ndelay', 'user');
+ for my $l (split(/\n/, $buf)) { syslog('warning', '%s', $l) }
+ closelog(); # don't share across fork
}
}