about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-05-26 18:08:57 +0000
committerEric Wong <e@80x24.org>2021-05-26 19:33:30 +0000
commit1d6e1f9a6a66a42d18f109aea406237cf8571597 (patch)
tree827b7465812239e9b4070eaa7162b33cabf42584 /lib
parent708b182a57373172f5523f3dc297659d58e03b58 (diff)
downloadpublic-inbox-1d6e1f9a6a66a42d18f109aea406237cf8571597.tar.gz
The cost of supporting separate code paths between oneshot and
daemon isn't worth the trouble; especially if there are more
users to support.  The test suite time nearly doubles with
oneshot, so that's hurting developer productivity.

FD passing is currently required to work efficiently with
remote HTTP(S) queries which return large messages, as seen in
commit 708b182a57373172f5523f3dc297659d58e03b58
("ipc: wq: handle >MAX_ARG_STRLEN && <EMSGSIZE case").

Additionally, upcoming support for IMAP IDLE and inotify-based
monitoring of Maildirs cannot work properly without a background
daemon.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/GitCredential.pm2
-rw-r--r--lib/PublicInbox/LEI.pm58
-rw-r--r--lib/PublicInbox/LeiEditSearch.pm19
-rw-r--r--lib/PublicInbox/LeiStore.pm13
-rw-r--r--lib/PublicInbox/LeiSucks.pm3
-rw-r--r--lib/PublicInbox/LeiUp.pm26
-rw-r--r--lib/PublicInbox/TestCommon.pm15
7 files changed, 30 insertions, 106 deletions
diff --git a/lib/PublicInbox/GitCredential.pm b/lib/PublicInbox/GitCredential.pm
index 2d81817c..b29780d6 100644
--- a/lib/PublicInbox/GitCredential.pm
+++ b/lib/PublicInbox/GitCredential.pm
@@ -9,7 +9,7 @@ sub run ($$;$) {
         my ($in_r, $in_w, $out_r);
         my $cmd = [ qw(git credential), $op ];
         pipe($in_r, $in_w) or die "pipe: $!";
-        if ($lei && !$lei->{oneshot}) { # we'll die if disconnected:
+        if ($lei) { # we'll die if disconnected:
                 pipe($out_r, my $out_w) or die "pipe: $!";
                 $lei->send_exec_cmd([ $in_r, $out_w ], $cmd, {});
         } else {
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index c8d2f315..6ff249d0 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -444,19 +444,6 @@ sub x_it ($$) {
         dump_and_clear_log();
         if (my $s = $self->{pkt_op_p} // $self->{sock}) {
                 send($s, "x_it $code", MSG_EOR);
-        } elsif ($self->{oneshot}) {
-                # don't want to end up using $? from child processes
-                _drop_wq($self);
-                # cleanup anything that has tempfiles or open file handles
-                %PATH2CFG = ();
-                delete @$self{qw(ovv dedupe sto cfg)};
-                if (my $signum = ($code & 127)) { # usually SIGPIPE (13)
-                        $SIG{PIPE} = 'DEFAULT'; # $SIG{$signum} doesn't work
-                        kill $signum, $$;
-                        sleep(1) while 1; # wait for signal
-                } else {
-                        $quit->($code >> 8);
-                }
         } # else ignore if client disconnected
 }
 
@@ -921,17 +908,6 @@ sub start_mua {
                 my $io = [];
                 $io->[0] = $self->{1} if $self->{opt}->{stdin} && -t $self->{1};
                 send_exec_cmd($self, $io, \@cmd, {});
-        } elsif ($self->{oneshot}) {
-                my $pid = fork // die "fork: $!";
-                if ($pid > 0) { # original process
-                        if ($self->{opt}->{stdin} && -t STDOUT) {
-                                open STDIN, '+<&', \*STDOUT or die "dup2: $!";
-                        }
-                        exec(@cmd);
-                        warn "exec @cmd: $!\n";
-                        POSIX::_exit(1);
-                }
-                POSIX::setsid() > 0 or die "setsid: $!";
         }
         if ($self->{lxs} && $self->{au_done}) { # kick wait_startq
                 syswrite($self->{au_done}, 'q' x ($self->{lxs}->{jobs} // 0));
@@ -952,14 +928,11 @@ sub send_exec_cmd { # tell script/lei to execute a command
 sub poke_mua { # forces terminal MUAs to wake up and hopefully notice new mail
         my ($self) = @_;
         my $alerts = $self->{opt}->{alert} // return;
+        my $sock = $self->{sock};
         while (my $op = shift(@$alerts)) {
                 if ($op eq ':WINCH') {
                         # hit the process group that started the MUA
-                        if ($self->{sock}) {
-                                send($self->{sock}, '-WINCH', MSG_EOR);
-                        } elsif ($self->{oneshot}) {
-                                kill('-WINCH', $$);
-                        }
+                        send($sock, '-WINCH', MSG_EOR) if $sock;
                 } elsif ($op eq ':bell') {
                         out($self, "\a");
                 } elsif ($op =~ /(?<!\\),/) { # bare ',' (not ',,')
@@ -968,11 +941,7 @@ sub poke_mua { # forces terminal MUAs to wake up and hopefully notice new mail
                         my $cmd = $1; # run an arbitrary command
                         require Text::ParseWords;
                         $cmd = [ Text::ParseWords::shellwords($cmd) ];
-                        if (my $s = $self->{sock}) {
-                                send($s, exec_buf($cmd, {}), MSG_EOR);
-                        } elsif ($self->{oneshot}) {
-                                $self->{"pid.$self.$$"}->{spawn($cmd)} = $cmd;
-                        }
+                        send($sock, exec_buf($cmd, {}), MSG_EOR) if $sock;
                 } else {
                         err($self, "W: unsupported --alert=$op"); # non-fatal
                 }
@@ -1009,9 +978,6 @@ sub start_pager {
         if ($self->{sock}) { # lei(1) process runs it
                 delete @$new_env{keys %$env}; # only set iff unset
                 send_exec_cmd($self, [ @$rdr{0..2} ], [$pager], $new_env);
-        } elsif ($self->{oneshot}) {
-                my $cmd = [$pager];
-                $self->{"pid.$self.$$"}->{spawn($cmd, $new_env, $rdr)} = $cmd;
         } else {
                 die 'BUG: start_pager w/o socket';
         }
@@ -1253,29 +1219,13 @@ sub lazy_start {
 
 sub busy { 1 } # prevent daemon-shutdown if client is connected
 
-# for users w/o Socket::Msghdr installed or Inline::C enabled
-sub oneshot {
-        my ($main_pkg) = @_;
-        my $exit = $main_pkg->can('exit'); # caller may override exit()
-        local $quit = $exit if $exit;
-        local %PATH2CFG;
-        umask(077) // die("umask(077): $!");
-        my $self = bless { oneshot => 1, env => \%ENV }, __PACKAGE__;
-        for (0..2) { open($self->{$_}, '+<&=', $_) or die "open fd=$_: $!" }
-        dispatch($self, @ARGV);
-        x_it($self, $self->{child_error}) if $self->{child_error};
-}
-
 # ensures stdout hits the FS before sock disconnects so a client
 # can immediately reread it
 sub DESTROY {
         my ($self) = @_;
         $self->{1}->autoflush(1) if $self->{1};
         stop_pager($self);
-        my $err = $?;
-        my $oneshot_pids = delete $self->{"pid.$self.$$"} or return;
-        waitpid($_, 0) for keys %$oneshot_pids;
-        $? = $err if $err; # preserve ->fail or ->x_it code
+        # preserve $? for ->fail or ->x_it code
 }
 
 sub wq_done_wait { # dwaitpid callback
diff --git a/lib/PublicInbox/LeiEditSearch.pm b/lib/PublicInbox/LeiEditSearch.pm
index 30ac65bd..13713d24 100644
--- a/lib/PublicInbox/LeiEditSearch.pm
+++ b/lib/PublicInbox/LeiEditSearch.pm
@@ -14,19 +14,12 @@ sub lei_edit_search {
         my @cmd = (qw(git config --edit -f), $lss->{'-f'});
         $lei->qerr("# spawning @cmd");
         $lss->edit_begin($lei);
-        if ($lei->{oneshot}) {
-                require PublicInbox::Spawn;
-                waitpid(PublicInbox::Spawn::spawn(\@cmd), 0);
-                # non-fatal, editor could fail after successful write
-                $lei->child_error($?) if $?;
-                $lss->edit_done($lei);
-        } else { # run in script/lei foreground
-                require PublicInbox::PktOp;
-                my ($op_c, $op_p) = PublicInbox::PktOp->pair;
-                # $op_p will EOF when $EDITOR is done
-                $op_c->{ops} = { '' => [$lss->can('edit_done'), $lss, $lei] };
-                $lei->send_exec_cmd([ @$lei{qw(0 1 2)}, $op_p ], \@cmd, {});
-        }
+        # run in script/lei foreground
+        require PublicInbox::PktOp;
+        my ($op_c, $op_p) = PublicInbox::PktOp->pair;
+        # $op_p will EOF when $EDITOR is done
+        $op_c->{ops} = { '' => [$lss->can('edit_done'), $lss, $lei] };
+        $lei->send_exec_cmd([ @$lei{qw(0 1 2)}, $op_p ], \@cmd, {});
 }
 
 *_complete_edit_search = \&PublicInbox::LeiUp::_complete_up;
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index a7a0ebef..af5edbc2 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -431,20 +431,15 @@ sub write_prepare {
                 my $d = $lei->store_path;
                 $self->ipc_lock_init("$d/ipc.lock");
                 substr($d, -length('/lei/store'), 10, '');
-                my $err_pipe;
-                unless ($lei->{oneshot}) {
-                        pipe(my ($r, $w)) or die "pipe: $!";
-                        $err_pipe = [ $r, $w ];
-                }
+                pipe(my ($r, $w)) or die "pipe: $!";
+                my $err_pipe = [ $r, $w ];
                 # Mail we import into lei are private, so headers filtered out
                 # by -mda for public mail are not appropriate
                 local @PublicInbox::MDA::BAD_HEADERS = ();
                 $self->ipc_worker_spawn("lei/store $d", $lei->oldset,
                                         { lei => $lei, err_pipe => $err_pipe });
-                if ($err_pipe) {
-                        require PublicInbox::LeiStoreErr;
-                        PublicInbox::LeiStoreErr->new($err_pipe->[0], $lei);
-                }
+                require PublicInbox::LeiStoreErr;
+                PublicInbox::LeiStoreErr->new($err_pipe->[0], $lei);
         }
         $lei->{sto} = $self;
 }
diff --git a/lib/PublicInbox/LeiSucks.pm b/lib/PublicInbox/LeiSucks.pm
index 2ce64d62..a71158f3 100644
--- a/lib/PublicInbox/LeiSucks.pm
+++ b/lib/PublicInbox/LeiSucks.pm
@@ -23,8 +23,7 @@ sub lei_sucks {
         }
         eval { require PublicInbox };
         my $pi_ver = eval('$PublicInbox::VERSION') // '(???)';
-        my $daemon = $lei->{oneshot} ? 'oneshot' : 'daemon';
-        my @out = ("lei $pi_ver mode=$daemon\n",
+        my @out = ("lei $pi_ver\n",
                 "perl $Config{version} / $os $rel / $mac ".
                 "ptrsize=$Config{ptrsize}\n");
         chomp(my $gv = `git --version` || "git missing");
diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm
index 4399c4fb..9069232b 100644
--- a/lib/PublicInbox/LeiUp.pm
+++ b/lib/PublicInbox/LeiUp.pm
@@ -76,22 +76,18 @@ sub lei_up {
                 my @all = PublicInbox::LeiSavedSearch::list($lei);
                 my @local = grep(!m!\Aimaps?://!i, @all);
                 $lei->_lei_store->write_prepare($lei); # share early
-                if ($lei->{oneshot}) { # synchronous
-                        up1_redispatch($lei, $_) for @local;
-                } else {
-                        # daemon mode, re-dispatch into our event loop w/o
-                        # creating an extra fork-level
-                        require PublicInbox::DS;
-                        require PublicInbox::PktOp;
-                        my ($op_c, $op_p) = PublicInbox::PktOp->pair;
-                        for my $o (@local) {
-                                PublicInbox::DS::requeue(sub {
-                                        up1_redispatch($lei, $o, $op_p);
-                                });
-                        }
-                        $lei->event_step_init;
-                        $op_c->{ops} = { '' => [$lei->can('dclose'), $lei] };
+                # daemon mode, re-dispatch into our event loop w/o
+                # creating an extra fork-level
+                require PublicInbox::DS;
+                require PublicInbox::PktOp;
+                my ($op_c, $op_p) = PublicInbox::PktOp->pair;
+                for my $o (@local) {
+                        PublicInbox::DS::requeue(sub {
+                                up1_redispatch($lei, $o, $op_p);
+                        });
                 }
+                $lei->event_step_init;
+                $op_c->{ops} = { '' => [$lei->can('dclose'), $lei] };
         } else {
                 up1($lei, $out);
         }
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 460c9da0..83dcf650 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -544,7 +544,8 @@ EOM
         ($tmpdir, $for_destroy) = tmpdir unless $tmpdir;
         state $persist_xrd = $ENV{TEST_LEI_DAEMON_PERSIST_DIR};
         SKIP: {
-                skip 'TEST_LEI_ONESHOT set', 1 if $ENV{TEST_LEI_ONESHOT};
+                $ENV{TEST_LEI_ONESHOT} and
+                        xbail 'TEST_LEI_ONESHOT no longer supported';
                 my $home = "$tmpdir/lei-daemon";
                 mkdir($home, 0700) or BAIL_OUT "mkdir: $!";
                 local $ENV{HOME} = $home;
@@ -568,22 +569,12 @@ EOM
                         lei_ok(qw(daemon-kill), \"daemon-kill after $t");
                 }
         }; # SKIP for lei_daemon
-        unless ($test_opt->{daemon_only}) {
-                $ENV{TEST_LEI_DAEMON_ONLY} and
-                        skip 'TEST_LEI_DAEMON_ONLY set', 1;
-                require_ok 'PublicInbox::LEI';
-                my $home = "$tmpdir/lei-oneshot";
-                mkdir($home, 0700) or BAIL_OUT "mkdir: $!";
-                local $ENV{HOME} = $home;
-                local $ENV{XDG_RUNTIME_DIR} = '/dev/null';
-                $cb->();
-        }
         if ($daemon_pid) {
                 for (0..10) {
                         kill(0, $daemon_pid) or last;
                         tick;
                 }
-                ok(!kill(0, $daemon_pid), "$t daemon stopped after oneshot");
+                ok(!kill(0, $daemon_pid), "$t daemon stopped");
                 my $f = "$daemon_xrd/lei/errors.log";
                 open my $fh, '<', $f or BAIL_OUT "$f: $!";
                 my @l = <$fh>;