about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiStoreErr.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-04-03 10:48:27 +0000
committerEric Wong <e@80x24.org>2021-04-03 18:38:47 +0000
commit842e684f0a4154787274843eb3c9be2eef11b160 (patch)
treebece05a1c22a104953ec7007cfa7e23cdf4ac42b /lib/PublicInbox/LeiStoreErr.pm
parentb3e2975029ae938bb232aaa0cbc3dabda55d57d6 (diff)
downloadpublic-inbox-842e684f0a4154787274843eb3c9be2eef11b160.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/LeiStoreErr.pm')
-rw-r--r--lib/PublicInbox/LeiStoreErr.pm30
1 files changed, 30 insertions, 0 deletions
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 <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# 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;