* [PATCH 08/16] lib: explicitly distinguish oneshot use
2021-02-02 11:46 5% [PATCH 00/16] lei: -I/--include and more Eric Wong
@ 2021-02-02 11:46 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-02-02 11:46 UTC (permalink / raw)
To: meta
The daemon must not be fooled into thinking it's in oneshot
after a lei client disconnects and erases {sock}.
---
lib/PublicInbox/LEI.pm | 23 ++++++++++++++---------
lib/PublicInbox/LeiXSearch.pm | 5 ++---
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index bb7efd59..d6fa814c 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -284,11 +284,13 @@ sub x_it ($$) {
dump_and_clear_log();
if (my $sock = $self->{sock}) {
send($sock, "x_it $code", MSG_EOR);
- } elsif (my $signum = ($code & 127)) { # oneshot, usually SIGPIPE (13)
+ } elsif (!$self->{oneshot}) {
+ return; # client disconnected, noop
+ } elsif (my $signum = ($code & 127)) { # usually SIGPIPE (13)
$SIG{PIPE} = 'DEFAULT'; # $SIG{$signum} doesn't work
kill $signum, $$;
sleep; # wait for signal
- } else { # oneshot
+ } else {
# don't want to end up using $? from child processes
for my $f (qw(lxs l2m)) {
my $wq = delete $self->{$f} or next;
@@ -334,10 +336,9 @@ sub child_error { # passes non-fatal curl exit codes to user
my ($self, $child_error) = @_; # child_error is $?
if (my $sock = $self->{sock}) { # send to lei(1) client
send($sock, "child_error $child_error", MSG_EOR);
- } else { # oneshot
+ } elsif ($self->{oneshot}) {
$self->{child_error} = $child_error;
- }
- undef;
+ } # else noop if client disconnected
}
sub atfork_prepare_wq {
@@ -784,7 +785,7 @@ sub start_mua {
push @cmd, $mfolder unless defined($replaced);
if (my $sock = $self->{sock}) { # lei(1) client process runs it
send($sock, exec_buf(\@cmd, {}), MSG_EOR);
- } else { # oneshot
+ } elsif ($self->{oneshot}) {
$self->{"mua.pid.$self.$$"} = spawn(\@cmd);
}
}
@@ -802,13 +803,16 @@ sub start_pager {
$new_env->{MORE} = 'FRX' if $^O eq 'freebsd';
pipe(my ($r, $wpager)) or return warn "pipe: $!";
my $rdr = { 0 => $r, 1 => $self->{1}, 2 => $self->{2} };
- my $pgr = [ undef, @$rdr{1, 2}, $$ ];
+ my $pgr = [ undef, @$rdr{1, 2} ];
if (my $sock = $self->{sock}) { # lei(1) process runs it
delete @$new_env{keys %$env}; # only set iff unset
my $fds = [ map { fileno($_) } @$rdr{0..2} ];
$send_cmd->($sock, $fds, exec_buf([$pager], $new_env), MSG_EOR);
- } else {
+ } elsif ($self->{oneshot}) {
$pgr->[0] = spawn([$pager], $new_env, $rdr);
+ $pgr->[3] = $$; # ew'll reap it
+ } else {
+ die 'BUG: start_pager w/o socket';
}
$self->{1} = $wpager;
$self->{2} = $wpager if -t $self->{2};
@@ -823,7 +827,7 @@ sub stop_pager {
# do not restore original stdout, just close it so we error out
close(delete($self->{1})) if $self->{1};
my $pid = $pgr->[0];
- dwaitpid($pid, undef, $self->{sock}) if $pid && $pgr->[3] == $$;
+ dwaitpid($pid) if $pid && ($pgr->[3] // 0) == $$;
}
sub accept_dispatch { # Listener {post_accept} callback
@@ -1056,6 +1060,7 @@ sub oneshot {
local %PATH2CFG;
umask(077) // die("umask(077): $!");
my $self = bless {
+ oneshot => 1,
0 => *STDIN{GLOB},
1 => *STDOUT{GLOB},
2 => *STDERR{GLOB},
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index 5cf02136..e997431f 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -409,7 +409,6 @@ sub do_query {
fcntl($lei->{startq}, 1031, 4096) if $^O eq 'linux';
$zpipe = $l2m->pre_augment($lei);
}
- my $in_loop = exists $lei->{sock};
my $ops = {
'|' => [ \&sigpipe_handler, $lei ],
'!' => [ \&fail_handler, $lei ],
@@ -417,7 +416,7 @@ sub do_query {
'' => [ \&query_done, $lei ],
'mset_progress' => [ \&mset_progress, $lei ],
};
- (my $op, $lei->{pkt_op}) = PublicInbox::PktOp->pair($ops, $in_loop);
+ (my $op, $lei->{pkt_op}) = PublicInbox::PktOp->pair($ops, !$lei->{oneshot});
my ($lei_ipc, @io) = $lei->atfork_parent_wq($self);
delete($lei->{pkt_op});
@@ -428,7 +427,7 @@ sub do_query {
}
start_query($self, \@io, $lei_ipc);
$self->wq_close(1);
- unless ($in_loop) {
+ if ($lei->{oneshot}) {
# for the $lei_ipc->atfork_child_wq PIPE handler:
while ($op->{sock}) { $op->event_step }
}
^ permalink raw reply related [relevance 7%]
* [PATCH 00/16] lei: -I/--include and more
@ 2021-02-02 11:46 5% Eric Wong
2021-02-02 11:46 7% ` [PATCH 08/16] lib: explicitly distinguish oneshot use Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-02-02 11:46 UTC (permalink / raw)
To: meta
We're further embracing SOCK_SEQPACKET for progress reporting.
There's numerous cleanups for the oneshot case, but that's still
using worker processes. Worker-less oneshot seems pretty-broken
atm, but 16/16 will let us work on it more easily.
Eric Wong (16):
lei: switch to use SEQPACKET socketpair instead of pipe
lei_query: default to 10000 messages as documented
lei q: emit progress and counting via PktOp
lei q: support --only, --include and --exclude
lei: complete: do not complete non-arg options w/ help text
lei: q: shell completion for --(include|exclude|only)
lei_xsearch: truncate curl stderr after reading it
lib: explicitly distinguish oneshot use
lei q: do not leave temporary files after oneshot exit
cmd_ipc4: fix comments and formatting
pktop: fix potential undefined var
lei_xsearch: ensure curl.err and tail(1) cleanup happens
doc: lei-q: note "-a" and link to Xapian QueryParser
lei_overview: avoid unnecessary {l2m} delete
lei q: tidy up progress reporting
lei q: support --jobs [SEARCHERS],[WRITERS]
Documentation/lei-q.pod | 5 +-
MANIFEST | 2 +-
lib/PublicInbox/CmdIPC4.pm | 7 ++-
lib/PublicInbox/IPC.pm | 42 +++++++++++++----
lib/PublicInbox/LEI.pm | 60 +++++++++++++++---------
lib/PublicInbox/LeiExternal.pm | 12 ++---
lib/PublicInbox/LeiOverview.pm | 15 +++---
lib/PublicInbox/LeiQuery.pm | 77 ++++++++++++++++++++++++-------
lib/PublicInbox/LeiXSearch.pm | 83 ++++++++++++++++++++++++----------
lib/PublicInbox/OpPipe.pm | 41 -----------------
lib/PublicInbox/PktOp.pm | 69 ++++++++++++++++++++++++++++
lib/PublicInbox/V2Writable.pm | 22 +--------
t/lei.t | 14 ++++--
t/lei_external.t | 2 +-
xt/lei-sigpipe.t | 29 ++++++++++--
15 files changed, 318 insertions(+), 162 deletions(-)
delete mode 100644 lib/PublicInbox/OpPipe.pm
create mode 100644 lib/PublicInbox/PktOp.pm
^ permalink raw reply [relevance 5%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-02-02 11:46 5% [PATCH 00/16] lei: -I/--include and more Eric Wong
2021-02-02 11:46 7% ` [PATCH 08/16] lib: explicitly distinguish oneshot use Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).