about summary refs log tree commit homepage
path: root/lib/PublicInbox/Spawn.pm
DateCommit message (Collapse)
2020-02-02spawn: actually die on (vfork|fork) failures
Commit 9f5a583694396f84 ("spawn (and thus popen_rd) die on failure") was incomplete in that it only removed error checking for spawn failures for non-(vfork|fork) calls, but the actual (vfork|fork) PID result could still be undef. Fixes: 9f5a583694396f84 ("spawn (and thus popen_rd) die on failure")
2020-01-11spawn (and thus popen_rd) die on failure
Most spawn and popen_rd callers die on failure to spawn, anyways, and some are missing checks entirely. This saves us a bunch of verbose error-checking code in callers. This also makes popen_rd more consistent, since it already dies on pipe creation failures.
2020-01-06treewide: "require" + "use" cleanup and docs
There's a bunch of leftover "require" and "use" statements we no longer need and can get rid of, along with some excessive imports via "use". IO::Handle usage isn't always obvious, so add comments describing why a package loads it. Along the same lines, document the tmpdir support as the reason we depend on File::Temp 0.19, even though every Perl 5.10.1+ user has it. While we're at it, favor "use" over "require", since it it gives us extra compile-time checking.
2019-12-30spawn: better error handling
Since vfork always shares memory between the child and parent, we can propagate errors to the parent errno using shared memory instead of just dumping to stderr and hoping somebody sees it.
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-12-24remove "no warnings 'once'" in a few places
We can use "use" to get the namespace into the "BEGIN" phase of the interpreter. While we're at it, use \&coderef syntax explicitly instead of globbing everything.
2019-12-11spawn: remove support for clearing the env
It's unnecessary code which I'm not sure we ever used. In retrospect, completely clearing the environment doesn't make sense for the processes we spawn. We don't need to clobber individual environment variables in our code, either (and if we did for tests, we can use 'local').
2019-11-16spawn: which: allow embedded slash for relative path
This makes the subroutine behave more like which(1) command and will make using spawn() in tests easier.
2019-09-09run update-copyrights from gnulib for 2019
2019-06-24spawn: remove `Blocking' flag handling
Instead, the O_NONBLOCK flag is set by PublicInbox::HTTPD::Async; and we won't be setting it elsewhere.
2019-05-07spawn (Inline::C): fix off-by-one error
Noticed while testing on FreeBSD 11.2 amd64 with the optional Inline::C extension using clang 6.0.0. The end result on FreeBSD was spawning processes failed badly and things were immediately unusable with this enabled. av_len is a misleading API, and I failed to read the API comments in perl:/av.c which state: > Note that, unlike what the name implies, it returns > the highest index in the array, so to get the size of > the array you need to use "av_len(av) + 1". > This is unlike "sv_len", which returns what you would expect. If this bug affected anybody, it would've only affected users using both the optional Inline::C module AND set the PERL_INLINE_DIRECTORY environment variable. That said, I've never seen any evidence of it on Debian GNU/Linux + gcc on any x86 variant. That includes full 64-bit systems, a full 32-bit system, a 64-bit system with 32-bit userspace, across multiple gcc versions since 2016.
2019-04-04spawn: require soft and hard entries in RLIMIT_* handling
Our high-level config already treats single limits as a soft==hard limit for limiters; so stop handling that redundant in the low-level spawn() sub.
2019-04-04qspawn: wire up RLIMIT_* handling to limiters
This allows users to configure RLIMIT_{CORE,CPU,DATA} using our "limiter" config directive when spawning external processes.
2019-04-04spawn: support absolute paths
cgit (and most other CGI executables) is not typically installed for use via $PATH, so we'll need to support absolute paths to run it.
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.
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-22spawn: note we do not use absolute paths within our code
We can't rely on absolute paths when installed on other systems. Unfortunately, mlmmj-* requires them, but none of the core code will use it.
2016-05-02spawn: proper signal handling for vfork
We cannot afford to fire Perl-level signal handlers in the vforked child process since they're not designed to run in the child like that. Thus we need to block all signals before calling vfork, reset signal dispositions in the child, and restore the signal mask in the parent. ref: https://ewontfix.com/7
2016-02-29favor procedural calls for most private functions
This makes for better compile-time checking and also helps document which calls are private for HTTP and NNTP. While we're at it, use IO::Handle::* functions procedurally, too, since we know we're working with native glob handles.
2016-02-28reduce calls to close unless error checks are needed
We can rely on timely auto-destruction based on reference counting; reducing the chance of redundant close(2) calls which may hit the wront FD. We do care about certain close calls (e.g. writing to a buffered IO handle) if we require error-checking for write-integrity. In other cases, let things go out-of-scope so it can be freed automatically after use.
2016-02-28spawn: disable popen optimization for non-vfork
This is necessary since we want to be able to do arbitrary redirects via the popen interface. Oh well, we'll be a little slower for now for users without vfork. vfork users will get all the performance benefits.
2016-02-27spawn: fail properly if Inline fails
We must stash the error correctly when nesting evals, oops :x
2016-02-27git: use built-in spawn implementation for vfork
This should reduce overhead of spawning git processes from our long-running httpd and nntpd servers.
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.