]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
21 months agot/lei-convert: fix uninitialized variable w/o pigz
Eric Wong [Sat, 30 Sep 2023 16:17:21 +0000 (16:17 +0000)] 
t/lei-convert: fix uninitialized variable w/o pigz

`backtick` captures return `undef' when a command is missing

Fixes: 5df0446abcca (lei: don't gzip --rsyncable by default for mbox*)
21 months agolei convert: support reading from v1, v2, and extindex
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...

21 months agolei_input: always prefix `maildir:' internally
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.

21 months agogit: fix unused code path for cat-file stderr reset
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).

21 months agogit: calculate MAX_INFLIGHT properly in Perl
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.

22 months agolei: don't gzip --rsyncable by default for mbox*
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

22 months agospawn: add popen_wr support
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.

22 months agoconvert: use ProcessPipe with popen_rd
Eric Wong [Wed, 27 Sep 2023 06:02:47 +0000 (06:02 +0000)] 
convert: use ProcessPipe with popen_rd

ProcessPipe->CLOSE will already run waitpid for us and
exit on errors, so we can do less, here.

22 months agospawn: add run_wait to simplify spawn+waitpid use
Eric Wong [Tue, 26 Sep 2023 07:44:40 +0000 (07:44 +0000)] 
spawn: add run_wait to simplify spawn+waitpid use

It's basically the `system' perlop with support for env overrides,
redirects, chdir, rlimits, and setpgid support.

22 months agospamcheck/spamc: rely on ProcessPipe instead of waitpid
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.

22 months agofetch: fix missing chdir arg for error reporting
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.

22 months agolei_blob: use ProcessPipe to eliminate a waitpid call
Eric Wong [Tue, 26 Sep 2023 07:44:37 +0000 (07:44 +0000)] 
lei_blob: use ProcessPipe to eliminate a waitpid call

waitpid with a positive PID isn't going to return anything
else unless we set ($SIG{CHLD} = 'IGNORE').

22 months agoauto_reap: waitpid never returns undef
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.

22 months agods: awaitpid: Perl waitpid retries on EINTR automatically
Eric Wong [Tue, 26 Sep 2023 07:44:35 +0000 (07:44 +0000)] 
ds: awaitpid: Perl waitpid retries on EINTR automatically

perlipc(1) man page states both wait + waitpid will retry
on EINTR.  Thus there's no need to retry it ourselves.

22 months agoxt/mem-nntpd-tls: drop :epoll import tag use
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)
22 months agotests: add quit_waiter_pipe and wait_for_eof
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.

22 months agods: force event_loop wakeup on final child death
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.

22 months agoxap_helper.h: add missing headers and avoid reallocarray
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.

22 months agolei: use scalar %SIG assignment
Eric Wong [Sun, 24 Sep 2023 21:08:21 +0000 (21:08 +0000)] 
lei: use scalar %SIG assignment

Perl v5.16.3 (and possibly some later versions) complain about
this, but newer (v5.32.1) are fine with it.

Fixes: e281363ba937 ("lei: ensure we run DESTROY|END at daemon exit w/ kqueue")
22 months agoinstall/deps: fix RPM installation of some packages
Eric Wong [Sun, 24 Sep 2023 21:08:20 +0000 (21:08 +0000)] 
install/deps: fix RPM installation of some packages

Not including 3rd-party repo-sourced packages, yet (e.g. git242
and xapian14-* stuff).

22 months agotest_common: force IPv4 with pre-IPv6 Net::POP3
Eric Wong [Sun, 24 Sep 2023 21:08:19 +0000 (21:08 +0000)] 
test_common: force IPv4 with pre-IPv6 Net::POP3

This fixes t/pop3d-limit.t with the Net::POP3 shipped with Perl v5.16.3
on CentOS 7.x

22 months agosyscall: fix valgrind error in pure Perl send_cmd4
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.

22 months agosyscall: have `vec' operate on bytes directly
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.

22 months agoipc: recv_cmd4 clobbers destination buffer on errors
Eric Wong [Sun, 24 Sep 2023 20:19:20 +0000 (20:19 +0000)] 
ipc: recv_cmd4 clobbers destination buffer on errors

Handling this should be done at the lowest levels possible;
so away from higher-level lei code.

22 months agolei_self_socket: drop unused deps and code
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.

22 months agot/cmd_ipc: assume SOCK_SEQPACKET
Eric Wong [Sun, 24 Sep 2023 20:19:18 +0000 (20:19 +0000)] 
t/cmd_ipc: assume SOCK_SEQPACKET

We can also enable the SIGALRM test by default as we're killing
manually in a loop to ensure the signal handler eventually
fires.

Followup-to: 2a6063fbc4580315 ("ipc: assume SOCK_SEQPACKET exists")
22 months agotest_common: fixes for TEST_RUN_MODE=0
Eric Wong [Sun, 24 Sep 2023 20:19:17 +0000 (20:19 +0000)] 
test_common: fixes for TEST_RUN_MODE=0

This fixes t/httpd-https.t when running `make check TEST_RUN_MODE=0'
to disable all code preloading and reuse.

Fixes: b914e67f82ee (test_common: start_script: set default signals)
22 months agoconfig: drop scalar ref support from internal API
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).

22 months agolei: fix `-c NAME=VALUE' config support
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.

22 months agolei config: send `git config' errors to pager
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.

22 months agoconfig: handle key-only entries as booleans
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.

22 months agolei view_text: used tied ProcessPipe for `git config'
Eric Wong [Sun, 24 Sep 2023 05:42:10 +0000 (05:42 +0000)] 
lei view_text: used tied ProcessPipe for `git config'

The code exists and is loaded anyways, so we might as well
save an explicit call to waitpid.  Noticed while checking
over our uses of `git config'

22 months agolei: check git-config(1) failures
Eric Wong [Sun, 24 Sep 2023 05:42:09 +0000 (05:42 +0000)] 
lei: check git-config(1) failures

2020-2021 were bad times and I somehow got deluded into
believing git-config(1) would always succeed :x

22 months agolei: use File::Temp for listing saved searches
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.

22 months agolei_to_mail: drop awkward duplication of $lei object
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.

22 months agolei: improve ->fail internal API
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.

22 months agolei blob|rediff: fix usage of lei->fail
Eric Wong [Fri, 22 Sep 2023 21:13:13 +0000 (21:13 +0000)] 
lei blob|rediff: fix usage of lei->fail

lei->fail only takes one message argument, presently;
but it's probably a good idea to change the API...

22 months agot/lei-mirror: avoid make(1) jobserver warning
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...

22 months agopop3: support initial_limit parameter in mailbox name
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.

Link: https://public-inbox.org/meta/20230918-barrel-unhearing-b63869@meerkat/
Fixes: 392d251f97d4 (pop3: support `?limit=$NUM' parameter in mailbox name)
22 months agomakefile: avoid non-POSIX which(1)
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.

22 months agoinstall/deps: more fixes
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)
22 months agopop3d: split @FLOCK into $FLOCK_TMPL and @FLOCK_ORDER
Eric Wong [Mon, 18 Sep 2023 10:15:14 +0000 (10:15 +0000)] 
pop3d: split @FLOCK into $FLOCK_TMPL and @FLOCK_ORDER

This improves readability since we don't have to subscript
the array for use with the `pack' perlop.

22 months agomakefile: avoid needless use of double-colon rules
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.

22 months agorename t/run.perl to xt/check-run
Eric Wong [Mon, 18 Sep 2023 10:15:12 +0000 (10:15 +0000)] 
rename t/run.perl to xt/check-run

This allows us to get rid of some duplication in our Makefile

22 months agoipc: assume SOCK_SEQPACKET exists
Eric Wong [Mon, 18 Sep 2023 10:15:11 +0000 (10:15 +0000)] 
ipc: assume SOCK_SEQPACKET exists

The rest of our code does, and we haven't encountered a platform
we'd care about without it.

22 months agodrop GNU nproc(1) support in favor of getconf(1)
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.

22 months agoci/run: favor `make check' as the default target
Eric Wong [Mon, 18 Sep 2023 10:15:09 +0000 (10:15 +0000)] 
ci/run: favor `make check' as the default target

While parallelism isn't always a good thing, `make check'
has more verbose output to help us track down occasionally
failing tests.

22 months agodevel/sysdefs-list: cleanup and make partially eval-able
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.

22 months agoxap_helper: test cleanup + throw support in C++
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.

22 months agoinstall/deps: flesh out libgit2, SQLite, and Xapian packages
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.

22 months agoMakefile: add `check-debris' target
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.

22 months agolei q: set exit code for invalid Xapian queries
Eric Wong [Fri, 15 Sep 2023 22:47:00 +0000 (22:47 +0000)] 
lei q: set exit code for invalid Xapian queries

Xapian can't parse every query, so ensure we set the
exit code for the client.

22 months agowww_coderepo: use space for snapshot_fmt prefix
Eric Wong [Fri, 15 Sep 2023 18:33:44 +0000 (18:33 +0000)] 
www_coderepo: use space for snapshot_fmt prefix

The tab character causes inconsistent spacing on display,
and a single space seems fine, here.

22 months agopop3: limit default mailbox to 1K messages
Eric Wong [Thu, 14 Sep 2023 00:38:28 +0000 (00:38 +0000)] 
pop3: limit default mailbox to 1K messages

This is probably friendlier to webmail providers which
support importing mail from POP3.

22 months agopop3: support `?limit=$NUM' parameter in mailbox name
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>
22 months agolei: ensure we run DESTROY|END at daemon exit w/ kqueue
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.

22 months agolei: ensure --stdin sets %ENV and $current_lei
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.

22 months agoxap_helper: detect non-socket STDIN
Eric Wong [Thu, 14 Sep 2023 21:22:40 +0000 (21:22 +0000)] 
xap_helper: detect non-socket STDIN

We don't want to get into a worker respawn loop if somebody
just decides to start the executable from a terminal.

22 months agotest_common: eliminate call to non-existent cleanup_task
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.

22 months agods: Reset at END
Eric Wong [Thu, 14 Sep 2023 12:50:56 +0000 (12:50 +0000)] 
ds: Reset at END

This seems to avoid some DBI teardown segfaults on OpenBSD 7.3;
but there may be other places where something similar is necessary.

22 months agot/lei-mirror: do not bail out on `make help' failure
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.

22 months agot/xap_helper: improve reliability of TTIN/TTOU tests
Eric Wong [Wed, 13 Sep 2023 09:12:42 +0000 (09:12 +0000)] 
t/xap_helper: improve reliability of TTIN/TTOU tests

We need to send more parallel requests and possibly retry more
to ensure SIGTTIN/TTOU are handled due to OS scheduling delays.

$doreq was also getting too noisy with extra is() calls, so just
xbail on mismatches if somehow we get a truncated write.

22 months agoinstall/deps: safer defaults for regular users
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.

22 months agoupdates around RPM packages on CentOS 7.x
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.

22 months agomove deps.perl into new install/ directory
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.

22 months agoINSTALL: update for 2023, NetBSD and OpenBSD
Eric Wong [Wed, 13 Sep 2023 09:12:38 +0000 (09:12 +0000)] 
INSTALL: update for 2023, NetBSD and OpenBSD

We'll also note that curl is used by lei and -clone.

22 months agotests: allow more tests to pass without xapian-compact
Eric Wong [Tue, 12 Sep 2023 12:25:24 +0000 (12:25 +0000)] 
tests: allow more tests to pass without xapian-compact

22 months agotests: favor IO::Socket::IP for IPv6 listeners
Eric Wong [Tue, 12 Sep 2023 12:25:23 +0000 (12:25 +0000)] 
tests: favor IO::Socket::IP for IPv6 listeners

IO::Socket::IP is bundled with Perl 5.24+ so it's more likely
to be available than IO::Socket::INET6.

22 months agogcf2: switch build phase to use autodie
Eric Wong [Tue, 12 Sep 2023 10:48:30 +0000 (10:48 +0000)] 
gcf2: switch build phase to use autodie

This simplifies much of our code since much of it is
error-handling.

22 months agoxap_helper_cxx: detect libxapian version changes
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...

22 months agogcf2: detect libgit2 version changes
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.

22 months agoRevert "dspoll: switch to the documented IO::Poll API"
Eric Wong [Tue, 12 Sep 2023 06:16:06 +0000 (06:16 +0000)] 
Revert "dspoll: switch to the documented IO::Poll API"

This reverts commit 831ac641e8c23e3c87931b902527d7f5600fd80a.

22 months agoprovide select(2) backend for PublicInbox::DS
Eric Wong [Tue, 12 Sep 2023 06:13:04 +0000 (06:13 +0000)] 
provide select(2) backend for PublicInbox::DS

This is safer than relying on an internal API of IO::Poll
and doesn't create extra references to IO globs like the
public one.

22 months agospawn: do not block ABRT/BUS/ILL/SEGV signals
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.

22 months agods: use constants for @UNBLOCKABLE list
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.

22 months agodspoll: switch to the documented IO::Poll API
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.

22 months agofavor poll(2) for most daemons
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.

22 months agods: use object-oriented API for epoll
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.

22 months agodaemon: depend on DS event_loop in master process, too
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.

22 months agotests: map CLOFORK->FD_CLOEXEC temporarily for `tail -f'
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.

22 months agotreewide: favor Xapian (SWIG binding) over Search::Xapian
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.

22 months agoxap_helper: relicense C++ implementation to GPL-2.0+
Eric Wong [Sun, 10 Sep 2023 02:03:51 +0000 (02:03 +0000)] 
xap_helper: relicense C++ implementation to GPL-2.0+

This will allow us to incorporate approxidate time/date parsing
from git.git without needing to relicense git code.

22 months agoci/profiles: strip everything after the `-' in utsname.release
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.

22 months agoxap_helper: clamp workers to USHRT_MAX
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.

22 months agoxap_helper: use _OPENBSD_SOURCE on NetBSD for reallocarray
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.

22 months agoxap_helper: note __cleanup__ works with C++ exceptions
Eric Wong [Sat, 9 Sep 2023 12:01:40 +0000 (12:01 +0000)] 
xap_helper: note __cleanup__ works with C++ exceptions

In case somebody reviewing this code gets curious.

22 months agoupdate CI helper scripts for NetBSD and `pkgin'
Eric Wong [Sat, 9 Sep 2023 12:01:39 +0000 (12:01 +0000)] 
update CI helper scripts for NetBSD and `pkgin'

22 months agoci/profiles: rewrite in Perl
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.

22 months agoci/run.sh: parameterize BUILD_JOBS TEST_JOBS and TEST_TARGET
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.

22 months agoipc: define _SC_NPROCESSORS_ONLN for NetBSD
Eric Wong [Sat, 9 Sep 2023 12:01:36 +0000 (12:01 +0000)] 
ipc: define _SC_NPROCESSORS_ONLN for NetBSD

We'll reorganize this into a hash table for ease-of-reading.

22 months agoMakefile.PL: check `getconf NPROCESSORS_ONLN', too
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.

22 months agopop3d: support fcntl locks on NetBSD and OpenBSD
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.

22 months agoimapd: lazy-load IMAPsearchqp for Parse::RecDescent
Eric Wong [Sat, 9 Sep 2023 01:48:37 +0000 (01:48 +0000)] 
imapd: lazy-load IMAPsearchqp for Parse::RecDescent

This enables the t/pop3d.t test to pass when Parse::RecDescent
is not available.

22 months agofix some tests when `curl' is missing
Eric Wong [Sat, 9 Sep 2023 01:48:36 +0000 (01:48 +0000)] 
fix some tests when `curl' is missing

Debian-based distros allow uninstalling the `curl' CLI tool
independently of libcurl* packages which git depends on.

22 months agoci/deps: redo and fix essential package handling
Eric Wong [Fri, 8 Sep 2023 22:31:12 +0000 (22:31 +0000)] 
ci/deps: redo and fix essential package handling

git depends on p5-TimeDate on FreeBSD, too, so ensure git
doesn't get uninstalled on FreeBSD.  Instead of making
@precious a separate array, we can actually stuff dependencies
into the $non_auto map and save us some code.

We can also eliminate some duplication in $non_auto by
populating the Perl standard library packages in a loop.

22 months agoci: updates for OpenBSD
Eric Wong [Fri, 8 Sep 2023 13:09:08 +0000 (13:09 +0000)] 
ci: updates for OpenBSD

Still a work-in-progress, but OpenBSD's pkg_add/pkg_delete seem
to be working somewhat.  The dependency system seems to need some
extra help to ensure leaf packages with their own dependencies
(e.g.  `xapian-bindings-perl') get uninstalled before their
dependencies (`xapian-core').

Deduplicating the command-line is also required since both
pkg_add and pkg_delete will repeat the installation/removal if
a package is specified multiple times in the same invocation.

22 months agoci/deps: drop unnecessary mappings and add Inline
Eric Wong [Fri, 8 Sep 2023 13:09:07 +0000 (13:09 +0000)] 
ci/deps: drop unnecessary mappings and add Inline

The automatic mapping can work for more packages, so redundant
entries in $non_auto are just clutter.

Unfortunately, `Inline::C' is part of `Inline' on CentOS 7.x and
OpenBSD 7.3, so we'll add $non_auto mappings for those.

We'll also depend on `IO::Compress' to simplify mappings since
that's the CPAN distribution which holds both IO::Compress::Gzip
and IO::Compress::Gunzip and I'm not aware of any packagers who
split them.

22 months agoci/deps: add IMAP-related optional packages
Eric Wong [Fri, 8 Sep 2023 13:09:06 +0000 (13:09 +0000)] 
ci/deps: add IMAP-related optional packages

Mail::IMAPClient and Parse::RecDescent are widely available in
all relevant OS package/ports systems.

22 months agoupdate docs + tests for xapian-delve use
Eric Wong [Fri, 8 Sep 2023 13:09:05 +0000 (13:09 +0000)] 
update docs + tests for xapian-delve use

Since -cindex uses the xapian-delve(1) command for `--prune'
functionality, we'll rename our `xapian-compact' dependency to
the Debian package name (xapian-tools) since `xapian-delve' is
in the same package.

22 months agofake_inotify: increase directory ctime adjustment window
Eric Wong [Fri, 8 Sep 2023 12:54:12 +0000 (12:54 +0000)] 
fake_inotify: increase directory ctime adjustment window

It actually needs to be bigger than the polling interval.
I suspect I missed this due to parallel tests on a loaded
VM, but running t/dir_idle.t on an unloaded machine reproduces
the problem when neither IO::KQueue nor Linux::Inotify2 are
present.