1 # Copyright (C) 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;
8 use parent qw(PublicInbox::DS);
9 use PublicInbox::Syscall qw(EPOLLIN);
10 use Sys::Syslog qw(openlog syslog closelog);
11 use IO::Handle (); # ->blocking
14 my ($cls, $rd, $lei) = @_;
15 my $self = bless { sock => $rd, store_path => $lei->store_path }, $cls;
17 $self->SUPER::new($rd, EPOLLIN); # level-trigger
22 my $n = sysread($self->{sock}, my $buf, 8192);
23 return ($!{EAGAIN} ? 0 : $self->close) if !defined($n);
24 return $self->close if !$n;
26 for my $lei (values %PublicInbox::DS::DescriptorMap) {
27 my $cb = $lei->can('store_path') // next;
28 next if $cb->($lei) ne $self->{store_path};
29 my $err = $lei->{2} // next;
30 print $err $buf and $printed = 1;
33 openlog('lei/store', 'pid,nowait,nofatal,ndelay', 'user');
34 for my $l (split(/\n/, $buf)) { syslog('warning', '%s', $l) }
35 closelog(); # don't share across fork