]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiStoreErr.pm
lei/store: (more) synchronous non-fatal error output
[public-inbox.git] / lib / PublicInbox / LeiStoreErr.pm
1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # forwards stderr from lei/store process to any lei clients using
5 # the same store
6 package PublicInbox::LeiStoreErr;
7 use strict;
8 use v5.10.1;
9 use parent qw(PublicInbox::DS);
10 use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
11
12 sub new {
13         my ($cls, $rd, $lei) = @_;
14         my $self = bless { sock => $rd, store_path => $lei->store_path }, $cls;
15         $self->SUPER::new($rd, EPOLLIN | EPOLLONESHOT);
16 }
17
18 sub event_step {
19         my ($self) = @_;
20         $self->do_read(\(my $rbuf), 4096) or return;
21         my $cb;
22         for my $lei (values %PublicInbox::DS::DescriptorMap) {
23                 $cb = $lei->can('store_path') // next;
24                 next if $cb->($lei) ne $self->{store_path};
25                 my $err = $lei->{2} // next;
26                 print $err $rbuf;
27         }
28 }
29
30 1;