]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
21 months agotreewide: use PublicInbox::Lock->new
Eric Wong [Wed, 4 Oct 2023 03:49:26 +0000 (03:49 +0000)] 
treewide: use PublicInbox::Lock->new

This gets rid of a few bare bless statements and helps
ensure we properly load Lock.pm before using it.

21 months agolock: retry on EINTR, improve error reporting
Eric Wong [Wed, 4 Oct 2023 03:49:25 +0000 (03:49 +0000)] 
lock: retry on EINTR, improve error reporting

We'll also add a handy ->new function since there's
a bunch of places we just create objects with bless.

21 months agombox_lock: retry on EINTR and use autodie
Eric Wong [Wed, 4 Oct 2023 03:49:24 +0000 (03:49 +0000)] 
mbox_lock: retry on EINTR and use autodie

EINTR needs to be retried in case signalfd and kevent aren't
available.  And autodie makes it easier to focus on more
important stuff.

21 months agolei: keep signals blocked on daemon shutdown
Eric Wong [Wed, 4 Oct 2023 03:49:23 +0000 (03:49 +0000)] 
lei: keep signals blocked on daemon shutdown

Since we completely shut down all workers before exiting,
we no longer have to care about missing SIGCHLD wakeups
during shutdown.

21 months agolei: reuse PublicInbox::Config::noop
Eric Wong [Wed, 4 Oct 2023 03:49:22 +0000 (03:49 +0000)] 
lei: reuse PublicInbox::Config::noop

No need to define our own empty `noop' sub when PublicInbox::Config
already has one and is loaded anyways.

21 months agot/lei_to_mail: modernize and document test
Eric Wong [Wed, 4 Oct 2023 03:49:21 +0000 (03:49 +0000)] 
t/lei_to_mail: modernize and document test

21 months agolei: get rid of l2m_progress PktOp callback
Eric Wong [Wed, 4 Oct 2023 03:49:20 +0000 (03:49 +0000)] 
lei: get rid of l2m_progress PktOp callback

We already have an ->incr callback we can enhance to support
multiple counters with a single request.  Furthermore, we can
just flatten the object graph by storing counters directly in
the $lei object itself to reduce hash lookups.

21 months agolei: do_env combines fchdir and local
Eric Wong [Wed, 4 Oct 2023 03:49:19 +0000 (03:49 +0000)] 
lei: do_env combines fchdir and local

This will make switching $lei contexts less error-prone
and hopefully save us from some suprising bugs in the future.

Followup-to: 759885e60e59 (lei: ensure --stdin sets %ENV and $current_lei, 2023-09-14)
21 months agoinput_pipe: {args} is never undefined
Eric Wong [Wed, 4 Oct 2023 03:49:18 +0000 (03:49 +0000)] 
input_pipe: {args} is never undefined

So save us a few ugly defined-ness checks.

21 months agolei: close DirIdle (inotify) early at daemon shutdown
Eric Wong [Wed, 4 Oct 2023 03:49:17 +0000 (03:49 +0000)] 
lei: close DirIdle (inotify) early at daemon shutdown

We don't want FS activity to delay lei-daemon shutdown.

21 months agomove all non-test @post_loop_do into named subs
Eric Wong [Wed, 4 Oct 2023 03:49:16 +0000 (03:49 +0000)] 
move all non-test @post_loop_do into named subs

Compared to Danga::Socket, our @post_loop_do API is designed to
make it easier to avoid anonymous subs (and their potential for
leaks in buggy old versions of Perl).

21 months agods: don't pass FD map to post_loop_do callback
Eric Wong [Wed, 4 Oct 2023 03:49:15 +0000 (03:49 +0000)] 
ds: don't pass FD map to post_loop_do callback

It's not used by any post_loop_do callbacks anymore, and the
underlying FD map is a global `our' variable accessible from
anywhere, anyways.

21 months agods: hoist out close_non_busy
Eric Wong [Wed, 4 Oct 2023 03:49:14 +0000 (03:49 +0000)] 
ds: hoist out close_non_busy

It's shared by both by lei and public-facing daemons in using
the ->busy callback.

21 months agolei: drop stores explicitly at daemon shutdown
Eric Wong [Wed, 4 Oct 2023 03:49:13 +0000 (03:49 +0000)] 
lei: drop stores explicitly at daemon shutdown

This will allow us to avoid unblocking signals during
shutdown to simplify our code.

21 months agot/lei-q-save: quiet `no email in From: ...' warnings
Eric Wong [Tue, 3 Oct 2023 16:18:17 +0000 (16:18 +0000)] 
t/lei-q-save: quiet `no email in From: ...' warnings

PublicInbox::Import will warn if it can't extract a valid
address from an email.  We need to ensure our tests capture
them to $lei_err instead of spewing them to the terminal.

While we're at it, use autodie and xsys_e to simplify some.

21 months agodaemon: enable SO_ACCEPTFILTER on NetBSD
Eric Wong [Tue, 3 Oct 2023 09:26:01 +0000 (09:26 +0000)] 
daemon: enable SO_ACCEPTFILTER on NetBSD

NetBSD 5.0+ has accept filter support from FreeBSD; and I
I think we can assume all NetBSD is 5.0+ (released in 2009)
nowadays if we're already depending on Perl 5.12 from 2010.

21 months agonet_reader: note glob support in .onion hint
Eric Wong [Tue, 3 Oct 2023 06:43:52 +0000 (06:43 +0000)] 
net_reader: note glob support in .onion hint

It's only available for git 2.26+ users, but I figure most
distros have it at this point.

21 months agoxt/lei-onion-convert: test TLS + SOCKS
Eric Wong [Tue, 3 Oct 2023 06:43:51 +0000 (06:43 +0000)] 
xt/lei-onion-convert: test TLS + SOCKS

While .onion URLs don't commonly use TLS, using Tor to access
non-.onion URLs is possible and TLS is advisable in that case.

TLS + SOCKS support is also useful for non-Tor SOCKS proxies
(e.g. "ssh -D"), but 127.0.0.1:9050 (Tor) is probably the most
standardized address.

While we're in the area: switch to v5.12, use autodie, and
ensure all necessary modules are present.

21 months agonet_reader: process title reflects NNTP article
Eric Wong [Tue, 3 Oct 2023 06:43:50 +0000 (06:43 +0000)] 
net_reader: process title reflects NNTP article

This matches the IMAP behavior with UIDs.  While we're in the
area, cut down on LoC a bit and reduce the scope of the $art
variable.

21 months agolei: workers exit after they tell lei-daemon
Eric Wong [Tue, 3 Oct 2023 06:43:49 +0000 (06:43 +0000)] 
lei: workers exit after they tell lei-daemon

We don't want workers continuing after their stdout has triggered
EPIPE or some other write error.

This fixes xt/lei-onion-convert.t to ensure the quit_waiter_pipe
is fully-closed at daemon teardown during tests.  Using the
`exit' perlop still ensures OnDestroy callbacks will fire.

21 months agonet_reader: support imap.sslVerify + nntp.sslVerify
Eric Wong [Tue, 3 Oct 2023 06:43:48 +0000 (06:43 +0000)] 
net_reader: support imap.sslVerify + nntp.sslVerify

These options are useful for testing as well as users stuck on
out-of-date systems, dealing with forgetful sysadmins, broken
cronjobs, and/or are willing to risk MITM attacks.

21 months agoconfig: fix key-only truthy values with urlmatch
Eric Wong [Tue, 3 Oct 2023 06:43:47 +0000 (06:43 +0000)] 
config: fix key-only truthy values with urlmatch

When using --get-urlmatch, we need a way to distinguish between
between key-only or a `key=val' pair even if the `val' is empty.
In other words, git interprets `-c imap.debug' as true and
`-c imap.debug=' as false, but an untyped --get-urlmatch
invocation has no way to distinguish between them.

So we must specify we want `--bool' (we're avoiding `--type=bool'
since that only appears in git 2.18+)

Fixes: f170d220f876 (lei: fix `-c NAME=VALUE' config support)
21 months agonet_reader: avoid IO::Socket::SSL 2.079..2.081 warning
Eric Wong [Tue, 3 Oct 2023 06:43:46 +0000 (06:43 +0000)] 
net_reader: avoid IO::Socket::SSL 2.079..2.081 warning

IO::Socket::SSL had an unitialized variable warning from a bad
regexp for a few releases.  This will also prepare us to support
imap.sslverify as git does and possibly other TLS-related
options.

21 months agonet_reader: bail out on NNTP SOCKS connection failure
Eric Wong [Tue, 3 Oct 2023 06:43:45 +0000 (06:43 +0000)] 
net_reader: bail out on NNTP SOCKS connection failure

It takes some effort to get Net::NNTP and IO::Socket::Socks
to place nice together, but we don't want the setsockopt
call to fail on an undefined value.  So die with an error
that tries to show various possible error sources.

$SOCKS_ERROR is a special variable, so even using `//'
(defined-or) operator isn't enough to squelch warnings
about using it in its uninitialized state.

21 months agolei: do label/keyword parsing in optparse
Eric Wong [Mon, 2 Oct 2023 15:00:23 +0000 (15:00 +0000)] 
lei: do label/keyword parsing in optparse

Calling vmd_mod_extract after optparse causes the implicit
stdin-as-input functionality to fail, as the implicit stdin
requires a lack of inputs remaining in argv after option
parsing (along with a regular file or pipe as stdin).

This allows commands such as `lei import -F eml +kw:seen'
to work without `--stdin', `-' or any path names when
importing a single message.  This also ensures commands like
`lei import +kw:seen' without any inputs/locations will fail
reliably, as the extra +kw: arg won't be a false-positive.

21 months agolei up: faster non-thread, single-source incremental query
Eric Wong [Mon, 2 Oct 2023 14:58:07 +0000 (14:58 +0000)] 
lei up: faster non-thread, single-source incremental query

When using isearch (that is v1/v2 inbox relying on extindex
for search), there's actually no guarantee that IMAP UIDs
are in the correct order with regard to Xapian docids.

Thus we must iterate through every UID(num) to see if it's
suitable to display in a saved search.  The old grep filter
(before commit a6fe84489127) was not effective since it
didn't account for the mset->items correspondence.

Fortunately, this bug merely manifests in reduced performance
as of a6fe84489127.  Prior to that, it could cause incorrect
keywords and labels to be applied.

Unfortunately, this behavior is hard-to-test so no test case
is included.

Followup-to: a6fe84489127 (lei up: fix missing -t/--threads matches w/ saved search)
21 months agolei_to_mail: avoid uninitialized vars for l2m_progress
Eric Wong [Sun, 1 Oct 2023 22:34:44 +0000 (22:34 +0000)] 
lei_to_mail: avoid uninitialized vars for l2m_progress

nr_write may be undef if nothing was written due to dedupe, but
with seen messages.

21 months agolei up: fix missing -t/--threads matches w/ saved search
Eric Wong [Sun, 1 Oct 2023 22:29:07 +0000 (22:29 +0000)] 
lei up: fix missing -t/--threads matches w/ saved search

We must not filter out seen docids from the mset; but only with
the result of over->expand_thread.

21 months agolei: deal with clients with blocked stderr
Eric Wong [Sun, 1 Oct 2023 09:54:29 +0000 (09:54 +0000)] 
lei: deal with clients with blocked stderr

lei/store can get stuck if lei-daemon is blocked, and lei-daemon
can get stuck when a clients stderr is redirected to a pager
that isn't consumed.

So start relying on Time::HiRes::alarm to generate SIGALRM to
break out of the `print' perlop.  Unfortunately, this isn't easy
since Perl auto-restarts all writes, so we dup(2) the
destination FD and close the copy in the SIGALRM handler to
force `print' to return.

Most programs (MUAs, editors, etc.) aren't equipped to deal with
non-blocking STDERR, so we can't make the stderr file description
non-blocking.

Another way to solve this problem would be to have script/lei
send a non-blocking pipe to lei-daemon in the {2} slot and
make script/lei splice messages from the pipe to stderr.
Unfortunately, that requires more work and forces more
complexity into script/lei and slow down normal cases where
stderr doesn't get blocked.

21 months agolei: ->fail only allows integer exit codes
Eric Wong [Sun, 1 Oct 2023 09:54:28 +0000 (09:54 +0000)] 
lei: ->fail only allows integer exit codes

We can't use floating point numbers nor Inf/-Inf as exit codes;
but we can allow `-1' as shorthand for 255.

21 months agotreewide: enable warnings in all exec-ed processes
Eric Wong [Sun, 1 Oct 2023 09:54:27 +0000 (09:54 +0000)] 
treewide: enable warnings in all exec-ed processes

While forked processes inherit from the parent, exec-ed
processes need the `-w' flag passed to them.  To determine
whether or not we should pass them, we must check the `$^W'
global perlvar, first.

We'll also favor `perl -e' over `perl -E' in places where
we don't rely on the latest features, since `-E' incurs
slightly more startup time overhead from loading feature.pm
(while `perl -Mv5.12' does not).

21 months agooveridx: fix version comparison
Eric Wong [Sun, 1 Oct 2023 09:54:26 +0000 (09:54 +0000)] 
overidx: fix version comparison

We can't use $DBD::SQLite::sqlite_version_number with older versions of
DBD::SQLite.  Thus we need to treat the $DBD::SQLite::sqlite_version
string (e.g. "3.8.3", not v-string) and convert it to a v-string with
eval for version comparisons to determine if we can fork multiple
children when using SQLite.

Fixes: fa04201baae9 ("lei: force --jobs=1,1 for SQLite < 3.8.3")
21 months agolei_store: unlink stderr buffer early
Eric Wong [Sun, 1 Oct 2023 09:54:25 +0000 (09:54 +0000)] 
lei_store: unlink stderr buffer early

While we're at it, ensure we clear the Perl internal EOF
marker before attempting to read the appended-to file
handle since newer Perl may leave the internal EOF marker set.

21 months agolei mail-diff: don't remove temporary subdirectory
Eric Wong [Sun, 1 Oct 2023 09:54:24 +0000 (09:54 +0000)] 
lei mail-diff: don't remove temporary subdirectory

->{curdir} is localized inside MailDiff->dump_eml anyways, so it
was attempting to remove `undef' :x.  Since most messages don't
have too many attachments, save some opcodes on our end and just
let File::Temp::Dir->DESTROY handle all the cleanup.

21 months agolei: correct exit signal
Eric Wong [Sun, 1 Oct 2023 09:54:23 +0000 (09:54 +0000)] 
lei: correct exit signal

The first argument passed to Perl signal handlers is a
signal name (e.g. "TERM") and not an integer that can
be passed to the `exit' perlop. Thus we must look up the
integer value from the POSIX module.

21 months agolei rediff: `git diff -O<order-file>' support
Eric Wong [Sun, 1 Oct 2023 09:54:22 +0000 (09:54 +0000)] 
lei rediff: `git diff -O<order-file>' support

We can't use the `-O' switch since it conflicts with
--only|-O= to specify externals.  Thus we'll introduce
a more verbose `--order-file=FILE' option when running
`git diff'.

21 months agogit: packed_bytes: deal with glob+stat TOCTTOU
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.

21 months agogit: improve error reporting
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.

21 months agoprocess_pipe: don't run `close' unless requested
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.

21 months agot/git: show git_version in diag output
Eric Wong [Sun, 1 Oct 2023 09:54:18 +0000 (09:54 +0000)] 
t/git: show git_version in diag output

This is useful to ensure we're testing properly with git <= 2.35
to ensure we don't break --batch-check support for those users.

21 months agogcf2: take non-ref scalar request arg
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.

21 months agogit+gcf2client: switch to level-triggered wakeups
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)
21 months agogit: use Unix stream sockets for `cat-file --batch-*'
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.

21 months agogit: decouple cat_async_retry from POSIX pipe semantics
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.

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).

22 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.