Eric Wong [Sun, 1 Oct 2023 09:54:21 +0000 (09:54 +0000)]
git: packed_bytes: deal with glob+stat TOCTTOU
There's not much we can do about this aside from just ignoring
errors and considering un-stat-able files as zero-sized.
There's no syscalls which expose FUSE3 `readdirplus' type
functionality to userspace to avoid this problem.
Eric Wong [Sun, 1 Oct 2023 09:54:20 +0000 (09:54 +0000)]
git: improve error reporting
We can use autodie for socketpair to handle errors for us,
but we need Time::HiRes::stat so we must write the error message
ourselves if stat-ing the git executable fails.
Eric Wong [Sun, 1 Oct 2023 09:54:19 +0000 (09:54 +0000)]
process_pipe: don't run `close' unless requested
If a user is relying on reference counts to invalidate FDs
(as we do in many places), rely on them instead of explicit
`close'. This forces us to do a better job of managing refs
and avoiding redundant fields which make our code more fragile.
Eric Wong [Sun, 1 Oct 2023 09:54:17 +0000 (09:54 +0000)]
gcf2: take non-ref scalar request arg
Asking callers to pass a scalar reference is awkward and
doesn't benefit modern Perl with CoW support. Unlike
some constant error messages, it can't save any allocations
at all since there's no constant strings being passed to
libgit2.
Eric Wong [Sat, 30 Sep 2023 15:20:40 +0000 (15:20 +0000)]
git+gcf2client: switch to level-triggered wakeups
Instead of using ->requeue to emulate level-triggered wakeups in
userspace, just use level-triggered wakeups in the kernel to
save some user time at the expense of system (kernel) time. Of
course, the ready list implementation in the kernel via C is
faster than a Perl one on our end.
We must still use requeue if we've got buffered data, however.
Followup-to: 1181a7e6a853 (listener: switch to level-triggered epoll)
Eric Wong [Sat, 30 Sep 2023 15:20:39 +0000 (15:20 +0000)]
git: use Unix stream sockets for `cat-file --batch-*'
The benefit of 1MB potential pipe buffer size (on Linux) doesn't
seem noticeable when reading from git (unlike when writing to v2
shards), so Unix stream sockets seem fine, here.
This allows us to simplify our process management by using the
same socket FD for reads and writes and enables us to use our
ProcessPipe class for reaping (as we can do with Gcf2Client).
Gcf2Client no longer relies on PublicInbox::DS for write
buffering, and instead just waits for requests to complete
once the number of inflight requests hits the MAX_INFLIGHT
threshold as we do with PublicInbox::Git.
We reuse the existing MAX_INFLIGHT limit (18) that was
determined by the minimum allowed PIPE_BUF (512). (AFAIK) Unix
stream sockets have no analogy to PIPE_BUF, but all *BSDs and
Linux I've checked have default SO_RCVBUF and SO_SNDBUF values
larger than the previously-required PIPE_BUF size of 512 bytes.
Eric Wong [Sat, 30 Sep 2023 15:20:38 +0000 (15:20 +0000)]
git: decouple cat_async_retry from POSIX pipe semantics
While pipes guarantee writes of <= 512 bytes to be atomic,
Unix stream sockets (or TCP sockets) have no such guarantees.
Removing the pipe assumption will make it possible for us to
switch to bidirectional Unix stream sockets and save FDs with
`git cat-file' processes as we have with Gcf2Client. The
performance benefit of larger pipe buffers over stream sockets
isn't irrelevant when interacting with git as it is with
SearchIdx shards.
Eric Wong [Sat, 30 Sep 2023 00:36:16 +0000 (00:36 +0000)]
lei convert: support reading from v1, v2, and extindex
We should be able to dump all public-inbox and extindex directories
to Maildir/mbox* or IMAP folders. Even unindexed inboxes can be
dumped as long as inbox.lock (or ssoma.lock) exists.
This change likely works for `lei tag' and other lei_input-using
things, as well, but that's untested at the moment. I mainly
want to be able to use `lei convert' to benchmark some upcoming
changes...
Eric Wong [Sat, 30 Sep 2023 00:36:15 +0000 (00:36 +0000)]
lei_input: always prefix `maildir:' internally
This allows us to reduce stats for `new' and `cur' subdirs
of the Maildir and will also make it easier for us to support
MH, v2, v1, and extindex directories as inputs.
Eric Wong [Fri, 29 Sep 2023 10:41:05 +0000 (10:41 +0000)]
git: fix unused code path for cat-file stderr reset
We haven't used _bidi_pipe idempotently in a while, so
the stderr was never getting reset on reads.
This isn't fully useful when using async eeeae20893a25956
(imap: use git-cat-file asynchronously, 2020-06-10)
So instead of truncating it on reads, we'll truncate
immediately after reading and rely on O_APPEND to keep
new writes at the end.
Fortunately, this stderrr error checking isn't used
outside of solver (which is synchronous).
Eric Wong [Fri, 29 Sep 2023 02:44:06 +0000 (02:44 +0000)]
git: calculate MAX_INFLIGHT properly in Perl
Unlike C, Perl automatically converts quotients to double-precision
floating point even with UV/IV numerators and denominators. So
force the intermediate quotient to be an integer before
multiplying it by the size of each inflight array element.
This bug was inconsequential for all platforms since d4ba8828ab23f278
(git: fix asynchronous batching for deep pipelines, 2023-01-04)
and inconsequential on most (or all?) Linux even before that due
to the larger 4096-byte PIPE_BUF on Linux.
Eric Wong [Wed, 27 Sep 2023 06:02:49 +0000 (06:02 +0000)]
lei: don't gzip --rsyncable by default for mbox*
Using and memoizing the usability of `--rsyncable' is unsafe
since pigz (or GNU gzip) can be uninstalled and leave a user
with a non-rsync-aware gzip implementation in the long-running
daemon. So we stop passing --rsyncable by default to pigz/gzip
and no longer attempt to check for it (since it was a TOCTTOU
error, anyways).
Specifying --rsyncable explicitly didn't work, either, and
ended up passing `1' to the gzip/pigz argv :x
Finally, we now test --rsyncable on the CLI by adding support
for it in `lei convert' and testing it in t/lei-convert.t
Eric Wong [Wed, 27 Sep 2023 06:02:48 +0000 (06:02 +0000)]
spawn: add popen_wr support
This makes interesting parts of our code easier to read IMHO.
We can take advantage of `local' while avoiding `fileno' calls
since it's called in spawn() anyways to reduce LoC even further.
Eric Wong [Tue, 26 Sep 2023 07:44:39 +0000 (07:44 +0000)]
spamcheck/spamc: rely on ProcessPipe instead of waitpid
We lose error information on CORE::close call, but the
underlying close(2) syscall won't EIO nor ENOSPC on a read-only
side of a pipe. Perl is already shielding us from EINTR and
EBADF would be a bug in Perl itself.
Eric Wong [Tue, 26 Sep 2023 07:44:38 +0000 (07:44 +0000)]
fetch: fix missing chdir arg for error reporting
We need to run `git config -l' in the epoch directory which
failed to get the proper config listing. This went unnoticed
because it doesn't affect any known users and was only found
during code inspection for waitpid usage cleanups.
Eric Wong [Tue, 26 Sep 2023 07:44:36 +0000 (07:44 +0000)]
auto_reap: waitpid never returns undef
Reading the Perl source, it seems impossible to for waitpid
to return undef. perlipc(1) man page also documents waitpid
(and `wait') as functions which always restart on EINTR.
Eric Wong [Mon, 25 Sep 2023 23:29:56 +0000 (23:29 +0000)]
xt/mem-nntpd-tls: drop :epoll import tag use
The export tag for :epoll no longer exists and it seems like
it hasn't been needed in a while, anyways. We can also drop a
useless EPOLLIN import, as well.
Fixes: 3005c1bc5d05 (ds: use object-oriented API for epoll)
Eric Wong [Mon, 25 Sep 2023 10:17:14 +0000 (10:17 +0000)]
tests: add quit_waiter_pipe and wait_for_eof
These generalize the idiom from t/httpd-unix.t and allows them
to be used for all the lei daemon shutdown in tests. This
speeds up the serialized run of `prove -lvw t/lei.t t/lei-daemon.t'
by roughly 8-9% or so since we're no longer sleeping and killing
the daemon in a loop.
Parallelized `make check' and `make check-run' don't show much
difference, yet.
Note that we do eliminate some kill(2) checks since those still
require retries an delays. We assume the kernel auto-closing
FDs on process exit is a strong-enough guarantee that the
process will soon be reaped by PID:1.
These will be useful for the FUSE daemons, as well.
We'll also start introducing more uses of autodie to simplify
our code.
Eric Wong [Mon, 25 Sep 2023 10:17:13 +0000 (10:17 +0000)]
ds: force event_loop wakeup on final child death
Reaping children needs to keep the event_loop spinning another
round when the @post_loop_do callback may be used to check
on process exit during shutdown.
This allows us to get rid of the hacky SetLoopTimeout calls in
lei-daemon and XapHelper.pm during process shutdown if we're
trying to wait for all PIDs to exit before leaving the event
loop.
Eric Wong [Sun, 24 Sep 2023 21:08:22 +0000 (21:08 +0000)]
xap_helper.h: add missing headers and avoid reallocarray
These changes are necessary with glibc 2.17 and g++ 4.8.5
on CentOS 7.x. We don't have to worry about overflow with
realloc(3) here since WORKER_MAX is only USHRT_MAX and
sizeof(pid_t) is 4 bytes on every platform I've encountered.
Eric Wong [Sun, 24 Sep 2023 20:19:22 +0000 (20:19 +0000)]
syscall: fix valgrind error in pure Perl send_cmd4
We need to allocate CMSG_SPACE for the `struct cmsghdr', not the
smaller CMSG_LEN. AFAIK this isn't a real world problem since
the Linux kernel doesn't care about the uninitialized space as
long as memory region belongs to the user, but valgrind complains.
Eric Wong [Sun, 24 Sep 2023 20:19:21 +0000 (20:19 +0000)]
syscall: have `vec' operate on bytes directly
Instead of converting to bytes to bits and asking `vec' to
operate on single bits, we can just have `vec' work on 8 bits
at-a-time.
This also fixes an overallocation in pure Perl Linux recv_cmd4.
Adding an extra byte ourselves for "\0" isn't necessary: Perl
already does it internally everywhere when creating/resizing
scalars.
Eric Wong [Sun, 24 Sep 2023 20:19:19 +0000 (20:19 +0000)]
lei_self_socket: drop unused deps and code
We don't need to repeat the assignment done in DS::new,
nor do we need to disable the `once' warnings after
commit cfd20b04dfe4 (ipc: retry sendmsg + recvmsg calls on EINTR)
removed the need for that pragma.
Eric Wong [Sun, 24 Sep 2023 05:42:14 +0000 (05:42 +0000)]
config: drop scalar ref support from internal API
It's a needless branch to maintain exclusively for our tests.
The `git config -l' output isn't pleasant to write in tests,
anyways. So just use heredocs to write git configs in their
native format rather than emulate the output of `git config -l'.
This does make the test suite do more work with temporary files
and process invocations, but it doesn't seem very measurable
when testing on tmpfs (TMPDIR=/dev/shm).
We'll make a minor improvement to TestCommon::tmpdir by allowing
it to return a single value (which I suspect we can rely on in
more places since File::Temp::Dir overloads stringification).
Eric Wong [Sun, 24 Sep 2023 05:42:13 +0000 (05:42 +0000)]
lei: fix `-c NAME=VALUE' config support
We can pass `-c NAME=VALUE' args directly to git-config without
needing a temporary directory nor file. Furthermore, this opens
the door to us being able to correctly handle `-c NAME=VALUE'
after `delete $lei->{cfg}' if we need to reload the config
during a command.
This tightens up error-checking for `lei config' and ensures we
can make config settings changes while using `-c NAME=VALUE'
instead of editing the temporary file.
The non-obvious part was avoiding the use of the -f/--file arg for
`git config' for read-only operations and include relying on
`-c include.path=$ABS_PATH'. This is done by parsing the
switches to be passed to `git config' to determine if it's a
read-only operation or not.
Eric Wong [Sun, 24 Sep 2023 05:42:12 +0000 (05:42 +0000)]
lei config: send `git config' errors to pager
Our previous use of lei->cfg_dump was wrong as the extra arg was
never supported. Instead, we need to capture the output of
`git config' and send it to the pager if ->cfg_dump fails. We'll
also add a note to the user to quit the pager to continue.
Eric Wong [Sun, 24 Sep 2023 05:42:11 +0000 (05:42 +0000)]
config: handle key-only entries as booleans
It's how git-config works, so our `git config --list' parser
must be able to handle it. Fortunately this doesn't seem to
incur a measurable overhead when parsing a config with 50k
inboxes.
Eric Wong [Fri, 22 Sep 2023 21:13:16 +0000 (21:13 +0000)]
lei: use File::Temp for listing saved searches
I have no idea how badly my brain malfunctioned here when I
wrote the code to create a temporary file without O_EXCL :x
I'm still not sure if users have enough saved searches for
justifying a cache, here.
Eric Wong [Fri, 22 Sep 2023 21:13:15 +0000 (21:13 +0000)]
lei_to_mail: drop awkward duplication of $lei object
Our awaitpid API now exists and ProcessPipe uses it, so it's
immune to cyclic references. Thus there's no need to create
a duplicate of the lei object to prevent leaks.
Eric Wong [Fri, 22 Sep 2023 21:13:14 +0000 (21:13 +0000)]
lei: improve ->fail internal API
Allow the exit code to be the first argument intead of the last
to match our ->child_error, as well as the BSD err(3) API.
We'll also avoid shifting user-passed exit codes so $? can be
passed as-is without losing signal information.
Eric Wong [Fri, 22 Sep 2023 18:37:16 +0000 (18:37 +0000)]
t/lei-mirror: avoid make(1) jobserver warning
We can't control `make test' nor user-defined targets in
config.mak. There's no need for a jobserver to run `make help',
anyways, so just let things be.
This also fixes the use of `gmake check' et al. on *BSDs where
various make flags confuse BSD make(1)
While we're at it, allow the test to run in the odd case make(1)
isn't available at all...
Eric Wong [Fri, 22 Sep 2023 02:18:17 +0000 (02:18 +0000)]
pop3: support initial_limit parameter in mailbox name
`initial_limit' only affects the fetch for new users while
`limit' affects all users. `initial_limit' is intended to be
better than the existing, absolute `limit' for 24/7 servers
(e.g. scheduled POP3 imports via webmail). The existing `limit'
parameter remains and is best suited for systems with sporadic
Internet access.
This also fixes an offset calculation bug with limit when used
on the newest (non-full) slice. The number of messages in the
newest slice is now taken into account.
Eric Wong [Mon, 18 Sep 2023 10:15:16 +0000 (10:15 +0000)]
makefile: avoid non-POSIX which(1)
which(1) isn't in POSIX so it's perhaps less likely to be
available (although I don't think I've noticed a system
without it in decades). So replace it with the POSIX
`command -v', even though everyone seems to use which...
Add a note about `lexgrog', too, since I'm not sure if it's
packaged for various *BSDs.
Eric Wong [Mon, 18 Sep 2023 10:15:15 +0000 (10:15 +0000)]
install/deps: more fixes
We need to mark *-dev packages as optional, and ignore
dependency-only packages in the `optional' field.
Furthermore, make the output less confusing when there's neither
packages to install nor remove; and avoid invoking `apt-get install'
with an empty package list.
This also fixes an OpenBSD-specific regression from commit 82990fb72dac
which made package removal a no-op.
Fixes: 82990fb72dac (install/deps: flesh out libgit2, SQLite, and Xapian packages)
Eric Wong [Mon, 18 Sep 2023 10:15:13 +0000 (10:15 +0000)]
makefile: avoid needless use of double-colon rules
This non-portable construct isn't needed for our own rules.
I'm understanding them correctly, they have different
semantics between *BSDs and GNU make.
Eric Wong [Mon, 18 Sep 2023 10:15:10 +0000 (10:15 +0000)]
drop GNU nproc(1) support in favor of getconf(1)
`getconf NPROCESSORS_ONLN' will succeed on GNU/Linux systems
anyways; and the non-underscore-prefixed invocation works fine
on all BSD flavors tested.
Thus the `nproc' and `gnproc' attempts will never be reached.
The only downside is we lose the ability to account for CPU
affinity, but that's probably not an issue since CPU affinity
(AFAIK) isn't a commonly-used feature.
Eric Wong [Sat, 16 Sep 2023 21:33:14 +0000 (21:33 +0000)]
devel/sysdefs-list: cleanup and make partially eval-able
It's stdout can now be placed into a Perl hash, now.
The MAYBE pseudo-macro can now emit hex as well as decimal
output to make some constants look nicer and eliminate some
special cases.
Constants for _SC_AVPHYS_PAGES and _SC_PAGE*SIZE have also been
added in case we dynamically generate BATCH_SIZE for search
indexing
I'm not sure how far I want to go down this route, but it could
open the door to us supporting more things on platforms with
unstable syscall numbers with only a C compiler, but without
relying on needing Inline::C (nor XS and difficult-to-audit
binaries). This is because a C compiler is readily installed on
more systems than Inline::C (even if packaged) requires an
additional installation step.
Eric Wong [Sat, 16 Sep 2023 13:10:52 +0000 (13:10 +0000)]
xap_helper: test cleanup + throw support in C++
We need to ensure whatever C++ compiler gets used supports this
GNU extension as we expect it to. clang 13 and 14 and g++ 10
all work as we expect it to.
Eric Wong [Sat, 16 Sep 2023 12:09:24 +0000 (12:09 +0000)]
install/deps: flesh out libgit2, SQLite, and Xapian packages
This seems to work reasonably well across multiple BSDs and
Debian and smooth out differences in packaging granularity.
Declaring the $always_deps relationship between `Xapian'(.pm) and
libxapian means we can get rid of the OpenBSD-specific hack to
remove `xapian-bindings-perl' before other packages.
Eric Wong [Sat, 16 Sep 2023 03:21:21 +0000 (03:21 +0000)]
Makefile: add `check-debris' target
This non-parallelized target is useful for noticing core dumps
and preventing them from being clobbered as we run the test
suite. It will also notice leftover temporary files and
directories.
This make target was used on OpenBSD 7.3 to develop at least two
recent fixes:
e281363ba937 (lei: ensure we run DESTROY|END at daemon exit w/ kqueue) 759885e60e59 (lei: ensure --stdin sets %ENV and $current_lei)
I considered using a per-test TMPDIR for this to enable
parallelization, but on-filesystem UNIX sockets won't work
with excessively long path names.
Eric Wong [Tue, 12 Sep 2023 22:40:34 +0000 (22:40 +0000)]
pop3: support `?limit=$NUM' parameter in mailbox name
I'm not sure if `?' or `=' are allowed characters in POP3
mailbox names. In fact, I can't find any information on
valid characters allowed in RFC 1081 nor RFC 1939.
In any case, it works fine with mpop, Claws-Mail, and
Thunderbird.
Tested-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Eric Wong [Fri, 15 Sep 2023 10:11:57 +0000 (10:11 +0000)]
lei: ensure we run DESTROY|END at daemon exit w/ kqueue
The fundamental difference which I originally missed when
implementing kqueue EVFILT_SIGNAL support is that it does not
consume signals like signalfd(2) does. In other words, with
EVFILT_SIGNAL, it's possible for a single signal to be delivered
twice if we unblock signals upon leaving the event loop as we do
in lei.
Note: Our DS->event_loop and Sigfd APIs can/should probably be
changed to better accomodate EVFILT_SIGNAL differences from
signalfd without sacrificing usability of either.
This fixes the problem of leftover lei-ovv.dst*, lei_cfg-* and
skv.* files in $TMPDIR at the end of test suite runs on *BSD
when IO::KQueue is installed.
Eric Wong [Thu, 14 Sep 2023 23:10:05 +0000 (23:10 +0000)]
lei: ensure --stdin sets %ENV and $current_lei
--stdin usage means the current request can be delayed
indefinitely while other requests with different %ENV
come in. So make sure our warnings and %ENV can match
non-stdin behavior.
This probably fix segfaults during process cleanup on OpenBSD
since _lei_atfork_child use non-localized assignment of
$current_lei. But it could be another red herring. Either way,
it's the right thing to do from an environment replication
perspective.
Eric Wong [Thu, 14 Sep 2023 20:52:05 +0000 (20:52 +0000)]
test_common: eliminate call to non-existent cleanup_task
cleanup_task is long gone since all that cleanup work got moved
into DS itself. Adding a DS->Reset here breaks t/imapd.t (and
possibly other tests), and is actually unlikely to avoid any
cleanup segfaults on OpenBSD since those are only happening
after `END {}' blocks are called.
Eric Wong [Thu, 14 Sep 2023 12:12:55 +0000 (12:12 +0000)]
t/lei-mirror: do not bail out on `make help' failure
I'm not sure why, but this test occasionally fails on OpenBSD
and I can't reproduce it on a repeatable basis. In any case,
there's no reason we can't continue the rest of the test if
`make help' fails.
Eric Wong [Wed, 13 Sep 2023 09:12:41 +0000 (09:12 +0000)]
install/deps: safer defaults for regular users
We'll leave forcing `--yes' to ci/run.sh and remove --purge
usage with apt-get(1) entirely. Also start defining some
more profiles aimed at users who want a minimal install for
the subset of public-inbox they wish to use.
There'll be some more built-in dependency handling to work
across different distros, but the $always_deps thing is a
start.
Eric Wong [Wed, 13 Sep 2023 09:12:40 +0000 (09:12 +0000)]
updates around RPM packages on CentOS 7.x
Add explicit dependencies on packages that are possible to
remove without removing the `perl' RPM from CentOS 7.x.
However, simplify deps.perl to avoid naming essential Perl
modules (e.g. `perl-Exporter') that cannot be removed
without removing the `perl' RPM entirely.
We can also drop `Socket6' from deps.perl since it's pulled
in as-needed by other packages and we try to avoid it in favor
of the (now-standard) IO::Socket::IP.
Eric Wong [Wed, 13 Sep 2023 09:12:39 +0000 (09:12 +0000)]
move deps.perl into new install/ directory
deps.perl can be useful for non-CI purposes as long as it's not
blindly removing packages. Thus, a --allow-remove flag now
exists for CI use and removals are disabled by default.
deps.perl also gets easier-to-use in that now install/os.perl
is split off from from ci/profiles.perl so OS-supplied packaged
manager.
Eric Wong [Tue, 12 Sep 2023 10:48:29 +0000 (10:48 +0000)]
xap_helper_cxx: detect libxapian version changes
As with libgit2, Xapian can be upgraded and break linkage
with the xap_helper binary. For now, save the result of
`pkg-config --modversion xapian-core' to a file and
compare it with the current output.
Perhaps portable some make(1) can be used for this...
Eric Wong [Tue, 12 Sep 2023 10:48:28 +0000 (10:48 +0000)]
gcf2: detect libgit2 version changes
We need to force Inline::C to rebuild if libgit2 is updated;
otherwise dynamic linking can be broken. Adding the output
from the `--modversion' of pkg-config(1) along with the existing
`--libs' and `--cflags' output seems appropriate for this task.
To force Inline::C into a rebuild, neither CFLAGSEX nor CPPFLAGS
changes are enough. Modifying the source string and adding
comments seems like the most obvious way to force a rebuild.
The `-print-file-name=LIBRARY' feature from gcc+clang could also
be used, but that requires parsing the library name from
`pkg-config --libs' output into a library basename appropriate
for `-print-file-name='. IOW, we'd need to transform:
`-lgit2' => `libgit2.so'; and possibly deal with platforms
which deal with static libraries in the future.
So just use pkg-config, since `pkg-config --modversion' is
roughly 2-3x as fast as `gcc-10 -print-file-name=', and
10-20x faster than clang-11.
Eric Wong [Mon, 11 Sep 2023 09:41:32 +0000 (09:41 +0000)]
spawn: 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.
Eric Wong [Mon, 11 Sep 2023 09:41:31 +0000 (09:41 +0000)]
ds: use constants for @UNBLOCKABLE list
There's no need for for a complicated map {} block here. All
these unblockable signals are POSIX since 2001 at the latest, so
there's no reason any platform would lack them.
Eric Wong [Mon, 11 Sep 2023 09:41:30 +0000 (09:41 +0000)]
dspoll: switch to the documented IO::Poll API
IO::Poll::_poll has always been an undocumented API. While it's
remained working so far (since the early 2000s with Danga::Socket),
I'm uncomfortable continuing with it moving forward since it's
not documented (the leading underscore typically means it's
not meant to be used by 3rd-parties).
So switch to the documented API and just learn to live with some
redundant object references and awkwardness in the API.
Eric Wong [Mon, 11 Sep 2023 09:41:29 +0000 (09:41 +0000)]
favor poll(2) for most daemons
public-inbox-watch, lei-daemon, the master process of
public-inbox-(netd|httpd|imapd|nntpd|pop3d),
and the (mostly) Perl implementation of XapHelper do not
have many FDs to watch so epoll|kqueue end up being overkill.
Of course, *BSDs already have separate kqueue FDs emulating
signalfd and/or inotify, even.
In other words, only the worker processes of
public-inbox-(netd|httpd|imapd|nntpd|pop3d) are expected
to see C10K (or C100K) types of traffic where epoll|kqueue
shine.
Perhaps lei could benefit from epoll/kqueue on some virtual users
IMAP/JMAP system one day; as could -watch with many IMAP IDLE
folders; but we'll probably add a knob if/when it comes to that.
Eric Wong [Mon, 11 Sep 2023 09:41:28 +0000 (09:41 +0000)]
ds: use object-oriented API for epoll
This allows us to cut down on imports and reduce code.
This also makes it easier (in the next commit) to provide an option
to disable epoll/kqueue when saving an FD is valued over scalability.
Eric Wong [Mon, 11 Sep 2023 09:41:27 +0000 (09:41 +0000)]
daemon: depend on DS event_loop in master process, too
The awaitpid API turns out to be quite handy for managing
long-lived worker processes. This allows us to ensure all our
uses of signalfd (and kevent emulation) are non-blocking.
Eric Wong [Mon, 11 Sep 2023 09:41:26 +0000 (09:41 +0000)]
tests: map CLOFORK->FD_CLOEXEC temporarily for `tail -f'
This fixes `TAIL="tail -F" prove -bvw t/lei-refresh-mail-sync.t'
since that test relies on lacking FD_CLOEXEC to detect dead
lei-daemons, but we still want FD_CLOEXEC when when relying
on tail(1) to check -imapd output.
Eric Wong [Mon, 11 Sep 2023 07:26:39 +0000 (07:26 +0000)]
treewide: favor Xapian (SWIG binding) over Search::Xapian
The Xapian SWIG bindings are favored by Xapian upstream for
ease-of-maintenance compared to the XS version. While Debian
lags on this front, the SWIG bindings are widely available
on all *BSDs.
Eric Wong [Sun, 10 Sep 2023 02:05:32 +0000 (02:05 +0000)]
ci/profiles: strip everything after the `-' in utsname.release
This fixes the script under FreeBSD (tested 13.2) FreeBSD 13.2
has `13.2-RELEASE-p3' in its uname(2) utsname.release. While
the `.2' component is a welcome addition over the old script,
Perl parses the `-' as a subtraction operation, which isn't
what we want.
Eric Wong [Sat, 9 Sep 2023 12:01:42 +0000 (12:01 +0000)]
xap_helper: clamp workers to USHRT_MAX
This allows us to avoid any integer overflow problems while
having enough room to grow for some future hardware, though it
looks like having hundreds of cores isn't ever going to make
it to typical servers nor workstations.
Eric Wong [Sat, 9 Sep 2023 12:01:41 +0000 (12:01 +0000)]
xap_helper: use _OPENBSD_SOURCE on NetBSD for reallocarray
NetBSD prefers reallocarr(3) for predictable zero-sized
allocation behavior; but no other OS seems to have reallocarr(3).
reallocarray(3) appears in by OpenBSD, FreeBSD, glibc, and musl,
so continue to go with that.
Eric Wong [Sat, 9 Sep 2023 12:01:38 +0000 (12:01 +0000)]
ci/profiles: rewrite in Perl
Reading os-release(5) is a bit more painful, now; and still
requires using the shell. However, sharing code between *BSDs
and being able to use v-strings for version comparisons is much
easier.
Test profiles for *BSDs are also trimmed down and more focused
on portability stuff.
Eric Wong [Sat, 9 Sep 2023 12:01:37 +0000 (12:01 +0000)]
ci/run.sh: parameterize BUILD_JOBS TEST_JOBS and TEST_TARGET
Parallezing BUILD_JOBS is usually harmless, but TEST_JOBS can
be problematic when tracking down problems on new platforms.
TEST_TARGET can be `check' or `check-run' for performance.
Eric Wong [Sat, 9 Sep 2023 12:01:35 +0000 (12:01 +0000)]
Makefile.PL: check `getconf NPROCESSORS_ONLN', too
NetBSD and OpenBSD getconf(1) don't accept a leading underscore,
while glibc getconf(1) only accepts the leading underscore
(`_NPROCESSORS_ONLN'). FreeBSD getconf(1) accepts both variants.
Eric Wong [Sat, 9 Sep 2023 01:48:38 +0000 (01:48 +0000)]
pop3d: support fcntl locks on NetBSD and OpenBSD
MboxLock already supported it since it locked the whole file,
but POP3D requires more fine-grained locking at file offsets.
I wonder if "struct flock" is old enough for it to be the same
across all the BSDs, it certainly seems so.
I originally considered using C11 `_Generic' support for the
struct offset/type dumping as I have in other projects, but
I am not ready to depend on C11 for this project, yet.
While we're modifying devel/sysdefs-list, add some Linux-only
structs to verify our `pack' templates are correct and remain
so when we encounter new architectures.