]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
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.

22 months agowatch: reset HUP + USR1 signal handlers in children
Eric Wong [Fri, 8 Sep 2023 10:51:15 +0000 (10:51 +0000)] 
watch: reset HUP + USR1 signal handlers in children

Child processes handling IMAP/NNTP aren't going to want
to handle config reloads nor forced rescans, those are
exclusively for the parent.  We'll leave a note that
QUIT/TERM/INT can safely use the same callback for both
parent and children, as I nearly made the mistake of
resetting those to their default values in the child.

22 months agowatch: set %SIG for non-signalfd/kqueue
Eric Wong [Fri, 8 Sep 2023 10:51:14 +0000 (10:51 +0000)] 
watch: set %SIG for non-signalfd/kqueue

We need to ensure there isn't a window where we lose $SIG{CHLD}
handling.  This is the second part in getting t/imapd.t to pass
the reload-after-setting-imap.pollInterval test

That said, I'm not entirely happy with the way -watch jumps
in and out of the event loop.  It's historical baggage from
the pre-event_loop days.

22 months agods: fix signals unblock for non-signalfd/kqueue
Eric Wong [Fri, 8 Sep 2023 10:51:13 +0000 (10:51 +0000)] 
ds: fix signals unblock for non-signalfd/kqueue

Using the sigset result of allowset() isn't appropriate for
SIG_UNBLOCK.  We must generate a new signal set off of the $sig
dispatch map for use with SIG_UNBLOCK to actually unblock the
signals.

This is the first part in getting t/imapd.t to pass the
reload-after-setting--imap.pollInterval-test when neither
signalfd nor kqueue are usable.

22 months agotail_notify: explicitly detect self deletion
Eric Wong [Fri, 8 Sep 2023 07:51:29 +0000 (07:51 +0000)] 
tail_notify: explicitly detect self deletion

This allows t/tail_notify.t to pass more reliably using
FreeBSD with IO::KQueue.

22 months agofake_inotify + kqnotify: rewrite and combine code
Eric Wong [Fri, 8 Sep 2023 00:49:20 +0000 (00:49 +0000)] 
fake_inotify + kqnotify: rewrite and combine code

KQNotify is now a subclass of FakeInotify since they're both
faking a subset of inotify; and both require directory scanning
via readdir() to detect new/deleted files.

ctime is no longer used with per-file stat to detect new files
with kevent.  That proved too unreliable either due to low
time resolution of the NetBSD/OpenBSD VFS and/or
Time::HiRes::stat being constrained by floating point to
represent `struct timespec', so instead we fuzz the time a bit
if the ctime is recent and merely compare filenames off readdir.

This fixes t/fake_inotify.t and t/kqnotify.t failures under NetBSD
and also removes workarounds for OpenBSD in t/kqnotify.t.  It
also allows us to to remove delays in tests by being more
aggressive in picking up new/deleted files in watch directories
by adjusting the time to scan if the ctime is recent.

This ought to may improve real-world reliability on all *BSDs
regardless of whether IO::KQueue is installed.

22 months agoxap_helper: fix fcntl() argument order
Eric Wong [Thu, 7 Sep 2023 00:54:09 +0000 (00:54 +0000)] 
xap_helper: fix fcntl() argument order

*sigh*  I only noticed this when running `make check-run' under
OpenBSD.

22 months agot/search.t: tweak dir group semantics for all *BSDs
Eric Wong [Thu, 7 Sep 2023 00:54:08 +0000 (00:54 +0000)] 
t/search.t: tweak dir group semantics for all *BSDs

NetBSD shares semantics with FreeBSD and OpenBSD, at least;
and presumably all their *BSD cousins behave the same way.

22 months agot/cmd_ipc.t: allow EMSGSIZE send error for NetBSD
Eric Wong [Thu, 7 Sep 2023 00:54:07 +0000 (00:54 +0000)] 
t/cmd_ipc.t: allow EMSGSIZE send error for NetBSD

NetBSD sendmsg can error out with EMSGSIZE instead of EAGAIN or
ETOOMANYREFS when a socket is non-blocking and the reader isn't
keeping up.

22 months agotail_notify: reinstate watch on reopen
Eric Wong [Thu, 7 Sep 2023 00:54:06 +0000 (00:54 +0000)] 
tail_notify: reinstate watch on reopen

This fixes t/tail_notify.t on NetBSD 9.3 where the log file
is deleted and later recreated.

22 months agot/watch_filter_rubylang.t: DS->Reset to avoid segfault
Eric Wong [Wed, 6 Sep 2023 00:08:26 +0000 (00:08 +0000)] 
t/watch_filter_rubylang.t: DS->Reset to avoid segfault

Object destruction order needs to be managed manually here to
avoid an occasional segfault at _rthread_mutex_timedlock() with
the following callstack:

XS_DBI_dispatch()
XS_DBD__SQLite__st_DESTROY()
sqlite_st_destroy()
sqlite3_finalize()
_rthread_mutex_timedlock()

...on OpenBSD 7.3 (Perl 5.36, DBD::SQLite 1.70v0, DBI 1.643p0,
sqlite 3.41.0).  I'm not sure exactly where the bug is, but I
suspect it's something inherent in Perl's unpredictable
destruction order at process teardown (something I've had to
workaround in the past when dealing with XS extensions).

There's no downloadable debug-* OpenBSD packages to ease
debugging for these components, either.

22 months agodskqxs: get rid of needless confess check
Eric Wong [Tue, 5 Sep 2023 07:37:25 +0000 (07:37 +0000)] 
dskqxs: get rid of needless confess check

Destruction order is unpredictable at process teardown,
so confessing or warning here is unnecessary, just break
out of the sub since it's for to delete an entry, anyways.

22 months agoxap_helper: allow non-standard file description flags
Eric Wong [Mon, 4 Sep 2023 23:49:46 +0000 (23:49 +0000)] 
xap_helper: allow non-standard file description flags

pipe2(.., O_CLOEXEC) on NetBSD sets the O_CLOEXEC file description
flag along with the FD_CLOEXEC file descriptor flag, so we must
not attempt to do exact matches on the file description flags.

22 months agoxap_helper: use rpath for libxapian on NetBSD
Eric Wong [Mon, 4 Sep 2023 23:49:45 +0000 (23:49 +0000)] 
xap_helper: use rpath for libxapian on NetBSD

While rpath is frowned upon by Debian and other distro packagers; it
appears embraced by in the world of NetBSD ports and packages.  This is
because ldconfig(8) on NetBSD doesn't put /usr/pkg/lib in its search
path by default.  This behavior differs from the ports and packaging
systems of FreeBSD and OpenBSD which do search library paths of
pkg*-installed packages (and presumably ports).

22 months agotest_common: start_script: set default signals
Eric Wong [Mon, 4 Sep 2023 10:36:07 +0000 (10:36 +0000)] 
test_common: start_script: set default signals

We need to ensure signal handlers in the child process aren't
inherited from the parent.  This change was originally intended
to block signals all the way until PublicInbox::Daemon and
PublicInbox::Watch were fully ready to handle them (preferably
via EVFILT_SIGNAL or signalfd); but that proved unrealistic.
Now, all signal handlers are restored to their default values
before signals are unblocked.

Drop a redundant DS->Reset while we're at it.

22 months agotests: add `+SCM_RIGHTS' as a require_mods target
Eric Wong [Mon, 4 Sep 2023 10:36:06 +0000 (10:36 +0000)] 
tests: add `+SCM_RIGHTS' as a require_mods target

We'll also ensure the existing `lei' target expands to depend on
`+SCM_RIGHTS', and use require_mods in t/lei-import-nntp.t and
t/lei.t so they can be skipped when Inline::C and Socket::MsgHdr
are missing on OpenBSD.

22 months agoxap_helper.h: include signal.h for sig* functions
Eric Wong [Mon, 4 Sep 2023 10:36:05 +0000 (10:36 +0000)] 
xap_helper.h: include signal.h for sig* functions

This is documented by all sig* manpages of FreeBSD and Linux,
but only OpenBSD fails to build without this header.

22 months agoxap_helper: support SIGTTIN+SIGTTOU worker adjustments
Eric Wong [Mon, 4 Sep 2023 10:36:04 +0000 (10:36 +0000)] 
xap_helper: support SIGTTIN+SIGTTOU worker adjustments

Being able to tune worker process counts on-the-fly when
xap_helper gets used with -{netd,httpd,imapd} will be useful
for tuning new setups.

22 months agowatch: ensure children can use signal handlers
Eric Wong [Mon, 4 Sep 2023 10:36:03 +0000 (10:36 +0000)] 
watch: ensure children can use signal handlers

Blindly using the signal set inherited from the parent process
is wrong, since the parent (or grandparent) could've blocked all
signals.  Ensure children can process signals in the event loop
when sig handlers have to use standard Perl facilities.

22 months agodaemon: workaround pre-EVFILT_SIGNAL signals
Eric Wong [Mon, 4 Sep 2023 10:36:02 +0000 (10:36 +0000)] 
daemon: workaround pre-EVFILT_SIGNAL signals

FreeBSD and OpenBSD kqueue EVFILT_SIGNAL isn't able to handle
blocked signals which were sent before the filter is created.
This behavior differs from Linux signalfd, which can process
blocked signals that were sent before the signalfd existed.

22 months agoupdate devel/syscall-list to devel/sysdefs-list
Eric Wong [Mon, 4 Sep 2023 10:36:01 +0000 (10:36 +0000)] 
update devel/syscall-list to devel/sysdefs-list

We use it to dump SIGWINCH and _SC_NPROCESSORS_ONLN, so
"sysdefs" is a more appropriate list for *BSD users.

22 months agot/sigfd: better checks related to SIGWINCH
Eric Wong [Mon, 4 Sep 2023 10:36:00 +0000 (10:36 +0000)] 
t/sigfd: better checks related to SIGWINCH

Check to ensure there's a numeric value of SIGWINCH defined for
the given platform.  SIGWINCH may also fire while the test is
running due to a user resizing their terminal, so a boolean test
to ensure it fired rather than an exact value check is more
correct.

22 months agot/sigfd: test EVFILT_SIGNAL vs signalfd differences
Eric Wong [Mon, 4 Sep 2023 10:35:59 +0000 (10:35 +0000)] 
t/sigfd: test EVFILT_SIGNAL vs signalfd differences

Verify that observed OpenBSD and FreeBSD EVFILT_SIGNAL behavior
works differently than what Linux signalfd does to ease upcoming
changes to PublicInbox::DS.

22 months agods: don't block important signals we don't use
Eric Wong [Mon, 4 Sep 2023 10:35:58 +0000 (10:35 +0000)] 
ds: don't block important signals we don't use

Don't block SIGABRT, SIGBUS, SIGFPE, SIGILL nor SIGSEGV since
blocking them can hide real bugs in our code or 3rd-party
libraries and executables.

We'll also leave SIGXCPU and SIGXFSZ unblocked since users
may've setup RLIMIT_CPU and RLIMIT_FSIZE, respectively.

22 months agoClarify Inline::C dependency (optional on Linux, required elsewhere)
Štěpán Němec [Sat, 2 Sep 2023 20:45:01 +0000 (22:45 +0200)] 
Clarify Inline::C dependency (optional on Linux, required elsewhere)

Link: https://public-inbox.org/meta/20230901110903.M876537@dcvr/
Link: https://public-inbox.org/meta/20230902194407.M464597@dcvr/
Fixes: 88c7c7c26b44 ("lei: wire up pure Perl sendmsg/recvmsg for Linux users")
Fixes: acefd91b302d ("syscall: implement sendmsg+recvmsg in pure Perl")
22 months agoxap_helper: deal with Xapian::DocNotFoundError
Eric Wong [Thu, 31 Aug 2023 08:38:57 +0000 (08:38 +0000)] 
xap_helper: deal with Xapian::DocNotFoundError

It's possible for a long mset streaming operation to hit missing
documents after a database reopen if deletes hit the DB.

22 months agoxap_helper.h: fix double-free on OpenBSD hdestroy
Eric Wong [Wed, 30 Aug 2023 05:10:45 +0000 (05:10 +0000)] 
xap_helper.h: fix double-free on OpenBSD hdestroy

hdestroy on OpenBSD assumes each key in the table can be freed,
so use strdup to fulfil that requirement.

This behavior differs from tested behavior on glibc and FreeBSD,
as well as what I can see from reading the musl and NetBSD
source code.  OpenBSD may be the only relevant OS which requires
this workaround.

22 months agoxap_helper.h: limit stderr assignment to glibc+FreeBSD
Eric Wong [Wed, 30 Aug 2023 05:10:44 +0000 (05:10 +0000)] 
xap_helper.h: limit stderr assignment to glibc+FreeBSD

This fixes the C++ xap_helper compilation on OpenBSD.
Assignable `FILE *' pointers appear to only be supported on
FreeBSD and glibc.  Based on my reading of musl and NetBSD
source code, this should also fix builds on those platforms.

22 months agoxap_helper.h: don't compress debug sections on OpenBSD
Eric Wong [Wed, 30 Aug 2023 05:10:43 +0000 (05:10 +0000)] 
xap_helper.h: don't compress debug sections on OpenBSD

ld(1) on OpenBSD 7.3 doesn't appear to support zlib-compressed
debug sections out-of-the-box.  Oh well, being able to build
this C++ bit at all is required to get acceptable performance
with -cindex --associate.

22 months agot/kqnotify: improve test reliability on OpenBSD
Eric Wong [Wed, 30 Aug 2023 05:10:42 +0000 (05:10 +0000)] 
t/kqnotify: improve test reliability on OpenBSD

Unlike FreeBSD, OpenBSD (tested 7.3) kevent doesn't document
EVFILT_VNODE behavior when directories are being watched.

Regardless, FreeBSD semantics appear to be mostly (if not
unreliably) supported.  Detecting rename(2) isn't reliable
at all and events seem to get lost and the test needs to
retry the rename(2) to succeed.  Fortunately, rename(2)
isn't recommended for Maildirs anyways since it can clobber
existing files.

link(2) detection appears to be merely delayed on OpenBSD,
so the test merely needs an occasional delay.

22 months agoMakefile.PL: depend on autodie, at least for tests
Eric Wong [Wed, 30 Aug 2023 05:10:41 +0000 (05:10 +0000)] 
Makefile.PL: depend on autodie, at least for tests

While using autodie everywhere is not appropriate[*], many of
our tests and FS access code can be easier-to-write and more
readable using autodie as we've started doing in XapHelperCxx.pm
and xap_helper.t

[*] - EAGAIN on non-blocking I/O shouldn't die, nor should
      certain cases of opening maybe-missing files for reading

22 months agoMakefile.PL: fix syntax for ASan and valgrind targets
Eric Wong [Wed, 30 Aug 2023 05:10:40 +0000 (05:10 +0000)] 
Makefile.PL: fix syntax for ASan and valgrind targets

Mixing various quoting and escaping rules between shell, make,
and Perl got confusing in Makefile.PL :x  This hopefully sorts
out my confusion.

We'll also fix and use TEST_XH_CXX_ONLY=1 to avoid needlessly
running the tests on the XS||SWIG implementation when we're
checking for memory errors.

Fixes: 2312ca26023fcbe3 (makefile: add targets for ASan and valgrind)
22 months agotreewide: drop MSG_EOR with AF_UNIX+SOCK_SEQPACKET
Eric Wong [Wed, 30 Aug 2023 05:10:39 +0000 (05:10 +0000)] 
treewide: drop MSG_EOR with AF_UNIX+SOCK_SEQPACKET

It's apparently not needed for AF_UNIX + SOCK_SEQPACKET as our
receivers never check for MSG_EOR in "struct msghdr".msg_flags
anyways.  I don't believe POSIX is clear on the exact semantics
of MSG_EOR on this socket type.  This works around truncation
problems on OpenBSD recvmsg when MSG_EOR is used by the sender.

Link: https://marc.info/?i=20230826020759.M335788@dcvr
22 months agot/spawn.t: workaround OpenBSD RLIMIT_CPU delays
Eric Wong [Tue, 29 Aug 2023 17:20:16 +0000 (17:20 +0000)] 
t/spawn.t: workaround OpenBSD RLIMIT_CPU delays

RLIMIT_CPU on OpenBSD doesn't work reliably with few syscalls or
on mostly idle systems.  Even at its most accurate, it takes an
extra second to fire compared to FreeBSD or Linux due to
internal accounting differences, but worst case even the SIGKILL
can be 50s delayed.

So rewrite the CPU burner script in Perl where we can unblock
SIGXCPU and reliably use more syscalls.

Link: https://marc.info/?i=20230829010110.M269767@dcvr
23 months agopublic-inbox-init: honor umask when creating config file
Štěpán Němec [Mon, 28 Aug 2023 10:45:13 +0000 (12:45 +0200)] 
public-inbox-init: honor umask when creating config file

Creating config 0600 disregarding umask breaks scenarios where daemons
run with credentials different from config owner (but need to read the
config).

File::Temp defaults to 0600, which is unsuitable for the
recommended/typical scenario of daemons running unprivileged and with
UID different from $PI_CONFIG owner, as the deamons need to read
$PI_CONFIG.

Respecting umask might end up creating world-unreadable config, too,
but for people who use such umask that's expected behavior.

23 months agodoc: daemon: clarify TLS and well-known ports
Eric Wong [Mon, 28 Aug 2023 21:11:54 +0000 (21:11 +0000)] 
doc: daemon: clarify TLS and well-known ports

Reported-by: Štěpán Němec <stepnem@smrk.net>
23 months agoFix some typos/grammar/errors in docs and comments
Štěpán Němec [Mon, 28 Aug 2023 10:42:46 +0000 (12:42 +0200)] 
Fix some typos/grammar/errors in docs and comments

23 months agospawn: remove distracting empty line
Štěpán Němec [Mon, 28 Aug 2023 10:42:45 +0000 (12:42 +0200)] 
spawn: remove distracting empty line

If anything, it should have been before the $rlim declaration, not
after, but the immediately preceding similar block has no empty line,
either.

23 months agospawn: remove stray variable $ndc_err
Štěpán Němec [Mon, 28 Aug 2023 10:42:44 +0000 (12:42 +0200)] 
spawn: remove stray variable $ndc_err

Code that could be setting it was removed in 14fa0abdcc7b.
Likewise for the double assignment to $err.

Fixes: 14fa0abdcc7b ("rewrite Linux nodatacow use in pure Perl w/o system")