From 842e684f0a4154787274843eb3c9be2eef11b160 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 3 Apr 2021 10:48:27 +0000 Subject: lei/store: (more) synchronous non-fatal error output Since every command that writes to lei/store calls ->done to commit its output, we can rely on that to return a pathname for a readable file with errors in it. Errors can still get crossed up if multiple lei commands are writing to the store at once, but reduces the delay in seeing them and ensures it won't get seen when somebody is attempting to use shell completion. --- lib/PublicInbox/LeiStoreErr.pm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/PublicInbox/LeiStoreErr.pm (limited to 'lib/PublicInbox/LeiStoreErr.pm') diff --git a/lib/PublicInbox/LeiStoreErr.pm b/lib/PublicInbox/LeiStoreErr.pm new file mode 100644 index 00000000..68ce96d6 --- /dev/null +++ b/lib/PublicInbox/LeiStoreErr.pm @@ -0,0 +1,30 @@ +# Copyright (C) 2021 all contributors +# License: AGPL-3.0+ + +# forwards stderr from lei/store process to any lei clients using +# the same store +package PublicInbox::LeiStoreErr; +use strict; +use v5.10.1; +use parent qw(PublicInbox::DS); +use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT); + +sub new { + my ($cls, $rd, $lei) = @_; + my $self = bless { sock => $rd, store_path => $lei->store_path }, $cls; + $self->SUPER::new($rd, EPOLLIN | EPOLLONESHOT); +} + +sub event_step { + my ($self) = @_; + $self->do_read(\(my $rbuf), 4096) or return; + my $cb; + for my $lei (values %PublicInbox::DS::DescriptorMap) { + $cb = $lei->can('store_path') // next; + next if $cb->($lei) ne $self->{store_path}; + my $err = $lei->{2} // next; + print $err $rbuf; + } +} + +1; -- cgit v1.2.3-24-ge0c7