The daemon must not be fooled into thinking it's in oneshot
after a lei client disconnects and erases {sock}.
dump_and_clear_log();
if (my $sock = $self->{sock}) {
send($sock, "x_it $code", MSG_EOR);
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
$SIG{PIPE} = 'DEFAULT'; # $SIG{$signum} doesn't work
kill $signum, $$;
sleep; # wait for signal
# don't want to end up using $? from child processes
for my $f (qw(lxs l2m)) {
my $wq = delete $self->{$f} or next;
# don't want to end up using $? from child processes
for my $f (qw(lxs l2m)) {
my $wq = delete $self->{$f} or next;
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);
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);
+ } elsif ($self->{oneshot}) {
$self->{child_error} = $child_error;
$self->{child_error} = $child_error;
+ } # else noop if client disconnected
}
sub atfork_prepare_wq {
}
sub atfork_prepare_wq {
push @cmd, $mfolder unless defined($replaced);
if (my $sock = $self->{sock}) { # lei(1) client process runs it
send($sock, exec_buf(\@cmd, {}), MSG_EOR);
push @cmd, $mfolder unless defined($replaced);
if (my $sock = $self->{sock}) { # lei(1) client process runs it
send($sock, exec_buf(\@cmd, {}), MSG_EOR);
+ } elsif ($self->{oneshot}) {
$self->{"mua.pid.$self.$$"} = spawn(\@cmd);
}
}
$self->{"mua.pid.$self.$$"} = spawn(\@cmd);
}
}
$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} };
$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);
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);
+ } elsif ($self->{oneshot}) {
$pgr->[0] = spawn([$pager], $new_env, $rdr);
$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};
}
$self->{1} = $wpager;
$self->{2} = $wpager if -t $self->{2};
# do not restore original stdout, just close it so we error out
close(delete($self->{1})) if $self->{1};
my $pid = $pgr->[0];
# 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
}
sub accept_dispatch { # Listener {post_accept} callback
local %PATH2CFG;
umask(077) // die("umask(077): $!");
my $self = bless {
local %PATH2CFG;
umask(077) // die("umask(077): $!");
my $self = bless {
0 => *STDIN{GLOB},
1 => *STDOUT{GLOB},
2 => *STDERR{GLOB},
0 => *STDIN{GLOB},
1 => *STDOUT{GLOB},
2 => *STDERR{GLOB},
fcntl($lei->{startq}, 1031, 4096) if $^O eq 'linux';
$zpipe = $l2m->pre_augment($lei);
}
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 ],
my $ops = {
'|' => [ \&sigpipe_handler, $lei ],
'!' => [ \&fail_handler, $lei ],
'' => [ \&query_done, $lei ],
'mset_progress' => [ \&mset_progress, $lei ],
};
'' => [ \&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});
my ($lei_ipc, @io) = $lei->atfork_parent_wq($self);
delete($lei->{pkt_op});
}
start_query($self, \@io, $lei_ipc);
$self->wq_close(1);
}
start_query($self, \@io, $lei_ipc);
$self->wq_close(1);
# for the $lei_ipc->atfork_child_wq PIPE handler:
while ($op->{sock}) { $op->event_step }
}
# for the $lei_ipc->atfork_child_wq PIPE handler:
while ($op->{sock}) { $op->event_step }
}