]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
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
23 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")
23 months agowatch: remove unused variable
Štěpán Němec [Mon, 28 Aug 2023 10:42:43 +0000 (12:42 +0200)] 
watch: remove unused variable

23 months agoci/profiles.sh: fix case matching logic
Štěpán Němec [Mon, 28 Aug 2023 10:42:42 +0000 (12:42 +0200)] 
ci/profiles.sh: fix case matching logic

'-' could never match, remove that alternative (it might have been a
typo of '--', but that is already covered by '*--|--*' ('*' matches
the null string)).

Replace '*--*' with the equivalent '*' ('--' is always present).

It would seem clearer to just replace the whole case command with
something like '[ "$ID" -a "$VERSION_ID" ] && break' (or the
POSIX-non-deprecated equivalent '[ "$ID" ] && [ "$VERSION_ID" ]' ); I
assume a preference of using case here (e.g., to avoid syscall
overhead in case [ is not implemented as a shell builtin (which seems
far-fetched given the context, though)).

23 months agot/xap_helper: skip test if missing SCM_RIGHTS support
Eric Wong [Sat, 26 Aug 2023 20:14:04 +0000 (20:14 +0000)] 
t/xap_helper: skip test if missing SCM_RIGHTS support

xap_helper currently relies on FDs passed via SCM_RIGHTS for
robustness against $TMPDIR failures and over-eager FS cleanup
tasks.  This depends on stable syscall numbers (Linux) or
Inline::C||Socket::MsgHdr being available, though, as Perl5
itself doesn't support SCM_RIGHTS.

We could probably add FIFO support to xap_helper for portability
to systems where neither Inline::C nor Socket::MsgHdr are available,
but that's for another day.

23 months agocindex: make prune work without SCM_RIGHTS support
Eric Wong [Sat, 26 Aug 2023 20:14:03 +0000 (20:14 +0000)] 
cindex: make prune work without SCM_RIGHTS support

We don't have to create extra pipes to pass around, actually.
Sending records via send/sendmsg isn't noticeably more expensive
than writing to a pipe.

23 months agoxap_helper: fix C++-specific warnings
Eric Wong [Sat, 26 Aug 2023 06:13:17 +0000 (06:13 +0000)] 
xap_helper: fix C++-specific warnings

While initialization of zeroed structs in C is done via `{0}',
I've just learned from g++(1) that C++ uses `{}'.  I can't seem
to get use of a single designated initializer to compile without
warnings in C++, either, so we'll just initialize them as zero
and assign them ASAP for __cleanup__ functions.

This fixes compilation warnings under -Wextra in g++ (Debian 10.2.1-6)
which adds -Wmissing-field-initializers.  This also fixes compilation
warnings under -Wall in clang (FreeBSD 13.0.0) from -Wmissing.

23 months agocindex: document pipelines created for prune
Eric Wong [Sat, 26 Aug 2023 06:13:16 +0000 (06:13 +0000)] 
cindex: document pipelines created for prune

This ought to make things easier-to-understand for people
reading the code for the first time (or rereading it for the
first time in a few days :x)

23 months agomakefile: add targets for ASan and valgrind
Eric Wong [Sat, 26 Aug 2023 06:13:15 +0000 (06:13 +0000)] 
makefile: add targets for ASan and valgrind

I would never consider working on C++ code without at least one
one of these tools present.

23 months agot/psgi_scan_all: reduce use_ok statements
Eric Wong [Sat, 26 Aug 2023 06:13:14 +0000 (06:13 +0000)] 
t/psgi_scan_all: reduce use_ok statements

This can save a handful of cycles to avoid testing things which
are already implicit from other tests.

23 months agodoc: INSTALL: note OpenBSD xapian-bindings-perl package
Eric Wong [Thu, 24 Aug 2023 19:35:09 +0000 (19:35 +0000)] 
doc: INSTALL: note OpenBSD xapian-bindings-perl package

The `xapian-bindings-perl' package contains the Xapian.pm
SWIG bindings, but doesn't adhere to the existing convention
of naming system packages after the Perl package name itself
using: "p5-${\($Perl_package_name =~ s/::/-/gr)}".

Reported-by: Štěpán Němec <stepnem@smrk.net>
Link: https://public-inbox.org/meta/20230824132323+0200.507058-stepnem@smrk.net/
23 months agocindex: dump cidx shards before inboxes
Eric Wong [Thu, 24 Aug 2023 22:07:46 +0000 (22:07 +0000)] 
cindex: dump cidx shards before inboxes

Since cidx shards used for associations are typically bigger
than individual inboxes, we'll dump them first to get better
work scheduling for xap_helper processes.

This gives roughly a 5% performance improvement with doing
a full associate on (git+lore).kernel.org

23 months agot/cindex: avoid reading default PI_CONFIG
Eric Wong [Thu, 24 Aug 2023 22:07:37 +0000 (22:07 +0000)] 
t/cindex: avoid reading default PI_CONFIG

I sometimes test on a machine with a broken
~/.public-inbox/config to detect inadvertant accesses in tests

23 months agodrop unused CidxRecvIbx.pm
Eric Wong [Thu, 24 Aug 2023 12:30:20 +0000 (12:30 +0000)] 
drop unused CidxRecvIbx.pm

This is no longer needed since xap_helper performs its
functionality while having an optional C++ implementation
which is being significantly faster.

23 months agoxap_helper: reopen+retry in MSetIterator loops
Eric Wong [Thu, 24 Aug 2023 01:22:36 +0000 (01:22 +0000)] 
xap_helper: reopen+retry in MSetIterator loops

It's possible to hit a DatabaseModifiedError while iterating
through an MSet.  We'll retry in these cases and cleanup some
code in both the Perl and C++ implementations.

23 months agocindex: implement dump_roots in C++
Eric Wong [Thu, 24 Aug 2023 01:22:35 +0000 (01:22 +0000)] 
cindex: implement dump_roots in C++

It's now just `dump_roots' instead of `dump_shard_roots', since
this doesn't need to be tied to the concept of shards.  I'm
still shaky with C++, but intend to keep using stuff like
hsearch(3) to make life easier for C hackers :P

23 months agocindex: fix sorting and uniqueness
Eric Wong [Thu, 24 Aug 2023 01:22:34 +0000 (01:22 +0000)] 
cindex: fix sorting and uniqueness

We can't rely on combining the `-u' and `-k1,1' switches of POSIX
sort(1) to do what we want.  So only rely on `sort -k1,1' while
introducing a small Perl helper to fold identical prefixes into
one line.  In other words, input such as:

  deadbeef 0
  deadbeef 1
  deadbeef 2

Was getting deduplicated into a single line:

  deadbeef 0

... with `sort -u -k1,1'
This makes puts the output into a more optimal form for eventual
(not-fully-implemented-yet) parsing:

  deadbeef 0,1,2

ORS is current the comma (`,') for inbox IDs, but it'll be a
space (` ') for coderepo root IDs.  This implementation also
combines identical IDs in the 2nd column.  Thus:

  deadbeef 0
  deadbeef 0

Becomes a single `deadbeef 0' line thanks to the use of
XS List::Util::uniq (which beats a pure Perl hash).

I attempted to implement this in awk but Perl is close enough to
gawk in performance while being shorter and easier-to-understand
due to List::Util::uniq.  mawk was faster, but still not enough
to matter as the bottleneck is from iterating through Xapian
MSets.

23 months agointroduce optional C++ xap_helper
Eric Wong [Thu, 24 Aug 2023 01:22:33 +0000 (01:22 +0000)] 
introduce optional C++ xap_helper

This allows us to perform the expensive "dump_ibx" operations in
native C++ code using the Xapian C++ library.  This provides the
majority of the speedup with the -cindex --associate switch.

Eventually this may be expanded to cover all uses of Xapian
within the project to ensure we have access to Xapian APIs which
aren't available in XS|SWIG bindings; and also for
ease-of-installation on systems which don't provide
pre-packaged Perl Xapian bindings (e.g. OpenBSD 7.3) but
do provide Xapian development libraries.

Most of the C++ code is still C, as I'm not remotely familiar
with C++ compared to C.  I suspect many users and potential
hackers being from git, Linux kernel, and glibc world are in the
same boat.

23 months agocindex: add --show-roots switch
Eric Wong [Thu, 24 Aug 2023 01:22:32 +0000 (01:22 +0000)] 
cindex: add --show-roots switch

This aids in development, but I'm not sure it's going to stay
or be moved into another interface.

23 months agocindex: read-only association dump
Eric Wong [Thu, 24 Aug 2023 01:22:31 +0000 (01:22 +0000)] 
cindex: read-only association dump

This will eventually allow associating coderepos with inboxes
and vice-versa; avoiding the need for manual configuration via
tedious publicinbox.*.coderepo directives.

I'm not sure how this should be stored for WWW, yet, but it's
required since it takes about 8 hours to do this fully across
lore and git.kernel.org.

23 months agosearch: hoist out shards_dir for future use
Eric Wong [Thu, 24 Aug 2023 01:22:30 +0000 (01:22 +0000)] 
search: hoist out shards_dir for future use

This will be useful for internal tooling and APIs.

23 months agoipc: support _SC_NPROCESSORS_ONLN on OpenBSD
Eric Wong [Sat, 19 Aug 2023 09:56:53 +0000 (09:56 +0000)] 
ipc: support _SC_NPROCESSORS_ONLN on OpenBSD

Tested on both amd64 and i386, and these constants tend to be
architecture-independent.

23 months agoisearch: avoid hex string for Xapian sortable_serialise
Eric Wong [Sat, 19 Aug 2023 08:30:51 +0000 (08:30 +0000)] 
isearch: avoid hex string for Xapian sortable_serialise

While a string representing a integer in hex is fine for DBI and
SQLite, Xapian's sortable_serialise requires a Perl integer value.
So just retrieve the last Xapian DB document ID in this rare
code path because we can't use 64-bit integer literals in some
32-bit Perl builds (e.g. OpenBSD on i386)

Fixes: be2a0a353d60 ("isearch: support 64-bit article numbers for SQLite query")
23 months agot/nntp.t: attempt to quiet spurious uninitialized warnings
Eric Wong [Thu, 17 Aug 2023 07:23:10 +0000 (07:23 +0000)] 
t/nntp.t: attempt to quiet spurious uninitialized warnings

When running via t/run.perl ("make check-run") to reduce test
startup time, t/nntp.t occasionally hits uninitialized variable
warnings in the quote_str sub.  I can't reproduce these
reliably, but scoping subs in tests reduces the chance of
conflict when we reuse interpreters.

23 months agosearch: all_terms: remove needless prefix check
Eric Wong [Wed, 16 Aug 2023 08:07:12 +0000 (08:07 +0000)] 
search: all_terms: remove needless prefix check

The ->allterms_{begin,end} methods of Xapian::Database already
filter match on prefix natively.   Thus there's no need to do
filtering ourselves (unlike per-document ->termlist_{begin/end})

23 months agodoc: extindex: note the use of `newsgroup' entries
Eric Wong [Wed, 16 Aug 2023 02:26:57 +0000 (02:26 +0000)] 
doc: extindex: note the use of `newsgroup' entries

We'll also be using this for -cindex for associating inboxes
to coderepos.

23 months agodoc: *index: fix misuse of apostrophe in `its'
Eric Wong [Wed, 16 Aug 2023 02:14:24 +0000 (02:14 +0000)] 
doc: *index: fix misuse of apostrophe in `its'

Reported-by: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/87leeovmig.fsf@kyleam.com/
23 months agodoc: clone: add a note about git 2.41+ and fetch.hideRefs
Eric Wong [Sun, 6 Aug 2023 02:31:56 +0000 (02:31 +0000)] 
doc: clone: add a note about git 2.41+ and fetch.hideRefs

It's unusable for large mirrors, otherwise.

23 months agodoc: add manpage for -cindex
Eric Wong [Sun, 6 Aug 2023 02:31:55 +0000 (02:31 +0000)] 
doc: add manpage for -cindex

It's similar to a combination of -index and -extindex but
perhaps more refined this time around...

2 years agoclone: allow running without DBI / DBD::SQLite
Eric Wong [Thu, 27 Jul 2023 21:18:55 +0000 (21:18 +0000)] 
clone: allow running without DBI / DBD::SQLite

Due to historic reasons, LeiQuery.pm gets loaded with LEI.pm and
-clone depends on LEI.  So delay loading any DBI-dependent
modules until querying is actually required.

2 years agoMakefile.pl: *.cols: account for non-UTF-8-aware awk
Eric Wong [Thu, 27 Jul 2023 21:18:54 +0000 (21:18 +0000)] 
Makefile.pl: *.cols: account for non-UTF-8-aware awk

When checking line length limits, the `length()' function of
mawk doesn't count non-ASCII characters properly in UTF-8
locales.  Force the man(1) output to use C locale and use normal
`-' instead of multi-byte dash characters.

2 years agotail_notify: cleanups and wakeup avoidance
Eric Wong [Fri, 14 Jul 2023 20:35:15 +0000 (20:35 +0000)] 
tail_notify: cleanups and wakeup avoidance

Avoid adding redundant watches at initialization, and avoid
unnecessarily wake ups when no timeout is specified.

2 years agotests: t/run.perl: fix invocations with <10 tests
Eric Wong [Fri, 14 Jul 2023 09:28:47 +0000 (09:28 +0000)] 
tests: t/run.perl: fix invocations with <10 tests

We must account for the maximum index of an array to avoid
filling unused slots with `undef' from out-of-bounds reads.
This is needed to avoid undefined entry errors in workers when
fewer than 10 tests are run.  We'll also silence the message
when a single test is run.

While I was diagnosing this, I also noticed a small
simplification and optimization in our generation of $todo_buf
since I initially thought that was the cause of undefined
entry errors in the $todo arrayref.

2 years agot/imapd: workaround a Perl 5.36.0 readline regression
Eric Wong [Thu, 13 Jul 2023 05:39:17 +0000 (05:39 +0000)] 
t/imapd: workaround a Perl 5.36.0 readline regression

Buffered readline (and read) ops under Perl 5.36.0 fails to read
new data after writes are made by other file handles (or
processes).

To fix and improve our test, introduce a new, (currently)
test-only TailNotify class to use inotify or kevent if available
to workaround it while avoiding infinite polling loops.  Further
refinements to these test APIs since we use the same pattern for
testing daemons in many places.

This also fixes the TEST_KILL_IMAPD condition in t/imapd.t under
GNU/Linux, AFAIK that test was never reliable under FreeBSD.

Link: https://bugs.debian.org/1040947
2 years agodoc: HACKING: drop bit about Debian 9.x (stretch)
Eric Wong [Thu, 13 Jul 2023 05:40:20 +0000 (05:40 +0000)] 
doc: HACKING: drop bit about Debian 9.x (stretch)

It's oldoldstable, by now; just refer to Debian stable as
the primary but keep LTS distros in mind because stuff like
CentOS 7.x needs to remain supported.

2 years agoli2wrap: use Perl v5.12
Eric Wong [Thu, 13 Jul 2023 09:48:49 +0000 (09:48 +0000)] 
li2wrap: use Perl v5.12

No sense in leaving strictness off here, and it's not affected
by the `unicode_strings' feature.

2 years agoMakefile.PL: depend on IO::Poll in case distros split it out
Eric Wong [Tue, 11 Jul 2023 10:29:28 +0000 (10:29 +0000)] 
Makefile.PL: depend on IO::Poll in case distros split it out

IO::Poll is part of the Perl standard library, but there's
always a chance distros will make it part of another package
since it's not portable to non-POSIX-like OSes.

2 years agot/solver_git: drop needless `use' and Plack deps
Eric Wong [Wed, 21 Jun 2023 10:16:57 +0000 (10:16 +0000)] 
t/solver_git: drop needless `use' and Plack deps

`lei (blob|rediff)' works without Plack installed, so don't put
a dependency on Plack or anything related to HTTP aside from
the URI module which we use everywhere.  This only enables testing
the solver component on systems without Plack (as the actual lei
functionality has always worked without Plack).

2 years agowww_stream: drop unused $same_host variable
Eric Wong [Sat, 17 Jun 2023 00:52:29 +0000 (00:52 +0000)] 
www_stream: drop unused $same_host variable

2 years agowww: use correct threadid for per-thread search
Eric Wong [Fri, 16 Jun 2023 23:13:01 +0000 (23:13 +0000)] 
www: use correct threadid for per-thread search

For individual public-inboxes relying on extindex for per-inbox
search, we must use the threadid from the extindex over.sqlite3
rather than the per-inbox over.sqlite3 file.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20230616-rudy-comedy-vision-2b9f92@meerkat/
2 years agolei: make --dedupe=content always account for Message-IDs
Eric Wong [Thu, 15 Jun 2023 09:50:53 +0000 (09:50 +0000)] 
lei: make --dedupe=content always account for Message-IDs

The content dedupe logic was originally designed for v2 public
inboxes as a fallback for when the importer sees identical
Message-IDs.  Thus it did not account for Message-ID(s) in
the message itself.

This change doesn't affect saved searches (the default when
writing to a pathname or IMAP).  It affects --no-save, and
outputs to stdout (even if stdout is redirected to a file).

Prior to this change, lei reused the v2 logic as-is without
accounting for Message-IDs anywhere with `--dedupe=content'
(the default).  This could cause messages to be skipped when
the content matches despite Message-IDs being different.

So with this change, `lei q --dedupe=content' will hash the
Message-ID(s) in the message to ensure messages with different
Message-IDs are NOT deduplicated.

Whether or not this change is a bug fix or introduces regression
is actually debatable.  In my mind, it is better to err on the
side of showing too many messages rather than too few, even if
the actual contents of the message are identical.  Making saved
searches deduplicate without accounting for Message-IDs would be
more difficult, too.

2 years agolei import: set +(L|kw) on already-imported blobs
Eric Wong [Thu, 15 Jun 2023 08:46:37 +0000 (08:46 +0000)] 
lei import: set +(L|kw) on already-imported blobs

When import hits blobs it's already seen, we'll add labels
regardless in order to match the behavior of other inexact
matches.  This is useful when importing exact copies of
messages which exist in multiple mailboxes.

I noticed this when I had a message imported from my normal IMAP
`INBOX', but also copied it to a different folder for future
reference.

2 years agodoc: lei q: document v2:$INBOX_DIR output format
Eric Wong [Thu, 15 Jun 2023 00:08:06 +0000 (00:08 +0000)] 
doc: lei q: document v2:$INBOX_DIR output format

This has been supported in every lei release, actually.

2 years agoadd compat package for List::Util::uniqstr
Eric Wong [Fri, 9 Jun 2023 10:31:08 +0000 (10:31 +0000)] 
add compat package for List::Util::uniqstr

This will make it easier to switch in the far future while
making callers easier-to-read (and more callers will be added).

Anyways, Perl 5.26 is a long time away for enterprise users;
but isolating compatibility code away can improve readability
of code we actually care about in the meantime.

2 years agosearch: hoist out do_enquire for codesearch
Eric Wong [Fri, 9 Jun 2023 10:31:07 +0000 (10:31 +0000)] 
search: hoist out do_enquire for codesearch

Reusing this bit seems to make sense as mail and code search
are similar enough w.r.t. setting up sort options.  This
deduplication will become more useful as -cindex will
likely combine code and mail search to generate associations
between inboxes and code repos.

2 years agosearch: add comments wrt codesearch, reduce ops
Eric Wong [Fri, 9 Jun 2023 10:31:06 +0000 (10:31 +0000)] 
search: add comments wrt codesearch, reduce ops

Add some comments about various usages of xdb_shards_flat and
mset since the addition of CodeSearch (and other search things)
subclassing it may become confusing.

Since we're in the area, we can also avoid an extra hash
lookups/initializations and reduce Perl ops in various places.

2 years agot/lei.t: quiet newline warning on older Perls
Eric Wong [Thu, 8 Jun 2023 18:26:08 +0000 (18:26 +0000)] 
t/lei.t: quiet newline warning on older Perls

Perl < 5.22 warned on newlines in the middle of a string instead
of just the end.  Workaround it by disabling all warnings on older
Perls while running File::Path::mkpath.

2 years agoxapcmd: rely on File::Temp cleanup for temporary dir
Eric Wong [Thu, 8 Jun 2023 18:04:54 +0000 (18:04 +0000)] 
xapcmd: rely on File::Temp cleanup for temporary dir

remove_tree from File::Path 2.09 (from Perl 5.16.3 on CentOS 7.x)
doesn't seem to work properly on File::Temp objects.   Since
File::Temp->newdir sets CLEANUP=>1 by default anyways, we'll
just rely on that to perform cleanup instead of doing it ourselves.

2 years agowww: more restrictive query string parsing
Eric Wong [Wed, 31 May 2023 22:10:01 +0000 (22:10 +0000)] 
www: more restrictive query string parsing

Only allow single-character query keys to prevent clients from
wasting memory in Perl's hash tables.  We'll also perform the
utf8::decode and tr/+/ / calls once on the whole query string at
once to reduce op calls.

This also avoids creating an empty hash in the common case
when the QUERY_STRING is empty and instead relies on
auto-vivification of Perl.

2 years agosearchview: clarify that only pct% links are same page
Eric Wong [Wed, 31 May 2023 09:14:45 +0000 (09:14 +0000)] 
searchview: clarify that only pct% links are same page

Non-matching messages in the skeleton aren't rendered on
the same page.

2 years agosearchview: fix 80-column violation for "above" link
Eric Wong [Wed, 31 May 2023 09:14:44 +0000 (09:14 +0000)] 
searchview: fix 80-column violation for "above" link

I think just noting "options" is enough and the mbox download
buttons are visible enough at the top of the search results
pages.

2 years agocindex: fix --no-scan no-op non-termination
Eric Wong [Tue, 9 May 2023 09:15:30 +0000 (09:15 +0000)] 
cindex: fix --no-scan no-op non-termination

We must account for the shards_active() recursing upon itself
when outside DS->event_loop.  This is tricky, unfortunately, but
--no-scan isn't a common mode of operation.  Noticed while
developing the monster --associate functionality to
automatically create bidirectional associations of
inboxes/extindices to coderepos.

2 years agocindex: fix --no-scan --prune
Eric Wong [Mon, 8 May 2023 16:58:14 +0000 (16:58 +0000)] 
cindex: fix --no-scan --prune

We must define $GIT_TODO to be non-undef when using --no-scan
for prune-only invocations to run.  I'm leaning towards making
--no-scan a publicly-documented switch for -cindex; but I'm
less certain about documenting it for -index and -extindex...

2 years agoisearch: support 64-bit article numbers for SQLite query
Eric Wong [Sat, 6 May 2023 22:40:03 +0000 (22:40 +0000)] 
isearch: support 64-bit article numbers for SQLite query

While IMAP UIDs are specified as 32-bit in RFC 3501, there's no
reason we can't support 64-bit article numbers on our end when
the time comes.  Neither NNTP nor POP3 have the 32-bit
limitation, even, so it's not inconceivable that IMAP will drop
that limitation at some point, too.

2 years agoxcpdb: support cindex upgrades and resharding
Eric Wong [Thu, 4 May 2023 11:06:42 +0000 (11:06 +0000)] 
xcpdb: support cindex upgrades and resharding

xcpdb is necessary for upgrading Xapian backends (e.g. glass to
honey), thus codesearch indices (cindex) must be supported.
Resharding is also useful if CPU count is altered on system
upgrades or downgrades.

cindex Xapian sharding is completely different than anything
else we do, so the resharding operation must be a special case
based on existing cindex sharding rules.

2 years agocompact+xcpdb: ux: include basename(*dir) in progress
Eric Wong [Thu, 4 May 2023 11:06:41 +0000 (11:06 +0000)] 
compact+xcpdb: ux: include basename(*dir) in progress

This is helpful if compacting multiple
inboxes/extindices/cindices sequentially from the CLI.

2 years agocindex: --prune + --exclude= drops repo information
Eric Wong [Wed, 3 May 2023 11:42:15 +0000 (11:42 +0000)] 
cindex: --prune + --exclude= drops repo information

--exclude= alone only prevents a coderepo from being indexed in
a particular invocation, but --prune will purge all traces of it
to ensure --update doesn't pick it up again w/o --exclude=
(unless --project-list= includes it).

2 years agoipc: get rid of lock support
Eric Wong [Wed, 3 May 2023 06:33:25 +0000 (06:33 +0000)] 
ipc: get rid of lock support

SOCK_SEQPACKET is used whenever we care about parallel writes to
a socket, so there's no need to mess with locks in userspace
code.

2 years agocompact: support codesearch indices
Eric Wong [Wed, 3 May 2023 03:11:14 +0000 (03:11 +0000)] 
compact: support codesearch indices

This is much easier to support than xcpdb since it's 1:1 and
doesn't follow a different sharding scheme than the inboxes and
extindices.

2 years agoadmin: hoist out resolve_any_idxdir from resolve_{inboxdir,eidxdir}
Eric Wong [Wed, 3 May 2023 03:11:13 +0000 (03:11 +0000)] 
admin: hoist out resolve_any_idxdir from resolve_{inboxdir,eidxdir}

This bit of common code will be handy for the upcoming
resolve_cidxdir, too.

2 years agodaemon: improve handling of Git->async_abort
Eric Wong [Mon, 1 May 2023 23:29:35 +0000 (23:29 +0000)] 
daemon: improve handling of Git->async_abort

The $oid arg for Git->cat_async is defined on async_abort using
the original request, so use undefined $type to distinguish that
case in caller-supplied callbacks.  async_abort isn't common, of
course, but sometimes git subprocesses can die unexpectedly.

2 years agosolver_git: don't spew to daemon err on git apply failure
Eric Wong [Sat, 29 Apr 2023 20:02:14 +0000 (20:02 +0000)] 
solver_git: don't spew to daemon err on git apply failure

Too many patches don't apply (due to coderepos being a PITA to
associate) and interested admins can check for 404s to diagnose
them, anyways.  This reduces the noise in syslog/stderr for
public-facing daemons.

2 years agot/lei-import-nntp: dump $lei_err on failure
Eric Wong [Sat, 29 Apr 2023 07:18:53 +0000 (07:18 +0000)] 
t/lei-import-nntp: dump $lei_err on failure

I hit an error on the backwards range import test and can't
reproduce it, perhaps dumping $lei_err can help diagnose it
in the future.

2 years agogit: make check_async callbacks identical to cat_async
Eric Wong [Fri, 28 Apr 2023 21:07:30 +0000 (21:07 +0000)] 
git: make check_async callbacks identical to cat_async

This simplifies Git->cat_async_step and fixes Git->async_abort,
the latter of which was passing arguments improperly for the
--batch-check (or `info') case at the cost of making the few
check_async callers handle an extra argument.

The extra (PublicInbox::Git) $self argument for check_async
callbacks is now gone, as avoiding the temporary cyclic
reference doesn't seem worthwhile since the temporary cyclic
reference appears in the ->cat_async code paths, too.

2 years agocontent_digest_dbg: handle empty inputs
Eric Wong [Fri, 28 Apr 2023 09:43:27 +0000 (09:43 +0000)] 
content_digest_dbg: handle empty inputs

It's possible that we hit messages or attachments with empty
bodies, so avoid doing a regexp match on an uninitialized variable.

2 years agot/gzip_filter: enhance diagnostics on missing SIGPIPE
Eric Wong [Fri, 28 Apr 2023 01:08:19 +0000 (01:08 +0000)] 
t/gzip_filter: enhance diagnostics on missing SIGPIPE

I encountered this SIGPIPE test not working as intended on
FreeBSD 12.4 once (out of hundreds of runs); but can't reproduce
it...

2 years agot/watch_maildir: eliminate extra LF from cat-file requests
Eric Wong [Thu, 27 Apr 2023 22:32:21 +0000 (22:32 +0000)] 
t/watch_maildir: eliminate extra LF from cat-file requests

This allows us to eliminate the workaround of respawning
`git cat-file', too :x

2 years agoINSTALL: fix FreeBSD pkg name typos
Siva Mahadevan [Thu, 27 Apr 2023 20:16:54 +0000 (16:16 -0400)] 
INSTALL: fix FreeBSD pkg name typos

Tested on FreeBSD 13.2-RELEASE.

2 years agoxcpdb: preserve indexlevel for extindex
Eric Wong [Wed, 26 Apr 2023 00:49:29 +0000 (00:49 +0000)] 
xcpdb: preserve indexlevel for extindex

This likely fixes indexlevel preservation for some v2 on some
systems, too, since (apparently) we need to sort shards
numerically to get Xapian metadata working properly on a
combined (multi-shard) Xapian DB.

2 years agoemergency: make error messages more consistent
Eric Wong [Tue, 25 Apr 2023 11:02:58 +0000 (11:02 +0000)] 
emergency: make error messages more consistent

Showing "failed" is needless if we already know the program
is die-ing.  We'll prefix "BUG:" to bug messages, "W:" to
non-fatal warnings to be consistent with our newer code such
as lei.

2 years agosearchidx: reduce short-lived variables for TermGenerator
Eric Wong [Tue, 25 Apr 2023 11:02:57 +0000 (11:02 +0000)] 
searchidx: reduce short-lived variables for TermGenerator

We can avoid needless refcount traffic in some cases.

2 years agosearchidxshard: use BUG error messages more consistently
Eric Wong [Tue, 25 Apr 2023 11:02:56 +0000 (11:02 +0000)] 
searchidxshard: use BUG error messages more consistently

We'll also drop the "\n" for die() to make diagnostics easier.
There's no known bugs in this area, just consistency
improvements and LoC reduction.

2 years agocindex: simplify store_repo
Eric Wong [Tue, 25 Apr 2023 11:02:55 +0000 (11:02 +0000)] 
cindex: simplify store_repo

It's easier to just create a new Xapian::Document and
replace it rather than to load and edit it.  I don't
know if there's any performance difference one way or
the other, but fewer branches helps with maintainability
and smaller optree size to lower memory use and startup
speed.

2 years agocindex: simplify tmpfile management for indexing
Eric Wong [Tue, 25 Apr 2023 11:02:54 +0000 (11:02 +0000)] 
cindex: simplify tmpfile management for indexing

I considered making this a pipe, but we must avoid spawning
`git log --stdin --no-walk=unsorted' for the no-op case since that
still emits a commit if stdin is empty.  So just get rid of an
unnecessary loop and do lseek(2) inside workers for parallelism

2 years agocindex: drop unneeded module use
Eric Wong [Tue, 25 Apr 2023 11:02:53 +0000 (11:02 +0000)] 
cindex: drop unneeded module use

I initially thought I'd use the PublicInbox::Eml module and rely
on --pretty=mboxrd; but eventually decided against it since
it wasn't saving any code.