about summary refs log tree commit homepage
path: root/lib/PublicInbox/SpawnPP.pm
DateCommit message (Collapse)
2024-04-03treewide: avoid getpid() for OnDestroy checks
getpid() isn't cached by glibc nowadays and system calls are more expensive due to CPU vulnerability mitigations. To ensure we switch to the new semantics properly, introduce a new `on_destroy' function to simplify callers. Furthermore, most OnDestroy correctness is often tied to the process which creates it, so make the new API default to guarded against running in subprocesses. For cases which require running in all children, a new PublicInbox::OnDestroy::all call is provided.
2023-10-28spawnpp: use autodie for syscall failures
We lose a little info for fork failures, but I don't think it matters.
2023-09-11spawn: do not block ABRT/BUS/ILL/SEGV signals
SIGABRT, SIGBUS, SIGILL, and SIGSEGV may all happen if we introduce bugs in the section where signals are blocked. We can delay handling of SIGFPE, SIGXCPU and SIGXFSZ since there's no floating point operations; while SIGXCPU and SIGXFSZ are safe to delay, especially in the absence of threads in our current code paths.
2023-03-25spawn: show failing directory for chdir failures
Our use of `git rev-parse --git-dir' depends on our (v)fork+exec wrapper doing chdir, so the error message is required to avoid user confusion. I'm still avoiding `git -C $DIR' for now since ancient versions of git did not support it.
2023-02-09spawn_pp: fix incorrect `use'
We can't `use PublicInbox::Spawn' from SpawnPP because PublicInbox::Spawn loads SpawnPP from BEGIN. Fixes: 9eb8baf199cd148b (spawn_pp: use `which()' properly for pure-Perl spawn, 2023-01-29)
2023-01-30spawn_pp: use `which()' properly for pure-Perl spawn
I have no idea if mod_perl/mod_perl2 is used nowadays, but we're stuck supporting it as long as mod_perl exists. So add some tests and make minor updates to existing ones to ensure it stays working.
2022-12-25spawn_pp: cleanup, error checks and descriptive errors
The pipe(2) call needs to be checked for failure. While we're at it, none of this is affected by unicode_strings, so Perl v5.12 is safe to use and gets rid of the strict.pm overhead. We can also `die' directly since it's pure Perl and not contort our Perl code to the assumptions of the Inline::C version. `die' already implies a failure, so follow existing conventions of just having the failing function or op name. We can also rely on the grep op for filtering out non-system signals to avoid writing a loop ourselves. Finally, drop a needless `undef' on the read side of the pipe since it's already closed immediately in the child.
2021-02-08spawnpp: raise exception on E2BIG errors
This matches the Inline::C version, and lets us test argv overflow with $search->query_argv_to_string;
2021-02-07spawn_pp: die more consistently in child
The default $SIG{__DIE__} inside a forked child doesn't actually do what we want it to do. We don't want it to zip up the stack the parent used, but instead want to exit the child process after warning.
2021-02-07spawn: pi_fork_exec: support "pgid"
We'll be using this to allow the "git clone" process hierarchy to be killed via Ctrl-C. This also fixes a long-standing bug in error reporting for the Inline::C version, because we're actually testing for errors, now! n.b. strlen(3) is officially async-signal-safe as of POSIX.1-2016, but I can't think of a reason any previous implementation prior to that wouldn't be.
2021-02-07spawn: pi_fork_exec: restore parent sigmask in child
We continue to unblock SIGCHLD unconditionally, but also any signals not blocked by the parent (wq_worker). This will allow Ctrl-C (SIGINT) to stop "git clone" and allow git-clone cleanup to be performed and other long-running processes when pi_fork_exec supports setpgid(2). This won't affect existing daemons on systems with signalfd(2) or EVFILT_SIGNAL at all, since those run with signals blocked anyways.
2021-01-01update copyrights for 2021
Using "make update-copyrights" after setting GNULIB_PATH in my config.mak
2020-06-30spawn: unblock SIGCHLD in subprocess
Subprocess we spawn may want to use SIGCHLD for themselves. This also ensures we restore default signal handlers in the pure Perl version.
2020-02-06treewide: run update-copyrights from gnulib for 2019
I didn't wait until September to do it, this year!
2019-12-30spawn: support chdir via -C option
This simplifies our admin module a bit and allows solver to be used with v1 inboxes using git versions prior to v1.8.5 (but still >= git v1.8.0).
2019-12-30spawn: allow passing GLOB handles for redirects
We can save callers the trouble of {-hold} and {-dev_null} refs as well as the trouble of calling fileno().
2019-09-24spawnpp: use absolute path for exec
We support "-env" to clear the environment with spawn(), which causes test failures but no runtime failures (since "-env" isn't used anywhere in our real code) Reported-and-tested-by: Alyssa Ross <hi@alyssa.is>
2019-09-09run update-copyrights from gnulib for 2019
2019-04-04spawn: support RLIMIT_CPU, RLIMIT_DATA and RLIMIT_CORE
We'll be spawning cgit and git-diff, which can take gigantic amounts of CPU time and/or heap given the right (ermm... wrong) input. Limit the damage that large/expensive diffs can cause.
2019-01-09doc: various overview-level module comments
Hopefully this helps people familiarize themselves with the source code.
2018-02-07update copyrights for 2018
Using update-copyrights from gnulib While we're at it, use the SPDX identifier for AGPL-3.0+ to ease mechanical processing.
2016-06-21spawn: improve error checking for fork failures
fork failures are unfortunately common when Xapian has gigabytes and gigabytes mmapped.
2016-06-18spawn: try to keep signals blocked in spawned child
While we only want to stop our daemons and gracefully destroy subprocesses, it is common for 'Ctrl-C' from a terminal to kill the entire pgroup. Killing an entire pgroup nukes subprocesses like git-upload-pack breaks graceful shutdown on long clones. Make a best effort to ensure git-upload-pack processes are not broken when somebody signals an entire process group. Followup-to: commit 37bf2db81bbbe114d7fc5a00e30d3d5a6fa74de5 ("doc: systemd examples should only kill one process")
2016-05-03spawnpp: use native perl %ENV outside of mod_perl
We only need to use env(1) under mod_perl; since mod_perl is uncommon nowadays, support native %ENV for a teeny speedup for folks uncomfortable with running vfork via Inline::C snippet.
2016-02-29spawnpp: use env(1) for mod_perl compatibility
We cannot modify %ENV directly under mod_perl (even after forking!), so use env(1) instead to pass the environment.
2016-02-28spawnpp: die instead of exit on exec failure
Perl may complain about exit not being executed, but not die.
2016-02-28spawnpp: fix error message for stderr redirect failing
Oops :x
2016-02-27initial spawn implementation using vfork
Under Linux, vfork maintains constant performance as parent process size increases. fork needs to prepare pages for copy-on-write, requiring a linear scan of the address space.