1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # forwards stderr from lei/store process to any lei clients using
5 # the same store, falls back to syslog if no matching clients exist.
6 package PublicInbox::LeiStoreErr;
9 use parent qw(PublicInbox::DS);
10 use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
11 use Sys::Syslog qw(openlog syslog closelog);
12 use IO::Handle (); # ->blocking
15 my ($cls, $rd, $lei) = @_;
16 my $self = bless { sock => $rd, store_path => $lei->store_path }, $cls;
18 $self->SUPER::new($rd, EPOLLIN | EPOLLONESHOT);
23 my $rbuf = $self->{rbuf} // \(my $x = '');
24 $self->do_read($rbuf, 8192, length($$rbuf)) or return;
27 for my $lei (values %PublicInbox::DS::DescriptorMap) {
28 $cb = $lei->can('store_path') // next;
29 next if $cb->($lei) ne $self->{store_path};
30 my $err = $lei->{2} // next;
31 print $err $$rbuf and $printed = 1;
34 openlog('lei/store', 'pid,nowait,nofatal,ndelay', 'user');
35 for my $l (split(/\n/, $$rbuf)) { syslog('warning', '%s', $l) }
36 closelog(); # don't share across fork