]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
21 months agoxap_helper.pm: quiet undefined warnings at shutdown
Eric Wong [Mon, 23 Oct 2023 19:35:17 +0000 (19:35 +0000)] 
xap_helper.pm: quiet undefined warnings at shutdown

We can't force EBADF with high-level I/O wrappers like we can
in C, so instead we quiet Perl itself.

21 months agot/init.t: don't modify $HOME/.public-inbox/config in test
Eric Wong [Mon, 23 Oct 2023 08:58:12 +0000 (08:58 +0000)] 
t/init.t: don't modify $HOME/.public-inbox/config in test

Oops :x

21 months agowww: fully qualify read_all subroutine call
Eric Wong [Mon, 23 Oct 2023 08:24:20 +0000 (08:24 +0000)] 
www: fully qualify read_all subroutine call

IMHO, this is not worth importing here since it's only called at
startup.

Fixes: 19b791f4894e (use read_all in more places to improve safety)
21 months agolei: simplify startq/au_done wakeup notifications
Eric Wong [Thu, 19 Oct 2023 01:14:31 +0000 (01:14 +0000)] 
lei: simplify startq/au_done wakeup notifications

We only need to write one byte at MUA start instead of a byte
for every LeiXSearch worker.  Also, make sure it succeeds by
enabling autodie for syswrite.

When reading, we can rely on `:perlio' layer `read' semantics
to retry on EINTR to avoid looping and other error checking.

21 months agoRevert "kqnotify: drop EV_CLEAR (edge triggering)"
Eric Wong [Wed, 18 Oct 2023 20:56:08 +0000 (20:56 +0000)] 
Revert "kqnotify: drop EV_CLEAR (edge triggering)"

This reverts commit 13a2088c74fdb4fa51cd97cefc00862cc2082330.

It's causing errors on an OpenBSD development snapshot while
despite being fine on OpenBSD 7.3 (amd64) and other *BSDs I've
tested.

Reported-by: Štěpán Němec <stepnem@smrk.net>
Link: https://public-inbox.org/meta/20231018170111+0200.599564-stepnem@smrk.net/
21 months agoidx_stack: use autodie + read_all
Eric Wong [Tue, 17 Oct 2023 23:38:15 +0000 (23:38 +0000)] 
idx_stack: use autodie + read_all

We'll also add a note to support multi-hash git repos once git
itself gains that ability.

21 months agoconvert: use read_all to simplify error checks
Eric Wong [Tue, 17 Oct 2023 23:38:14 +0000 (23:38 +0000)] 
convert: use read_all to simplify error checks

There wasn't a need to loop anyways with Perl `read' since
the default PerlIO layer will retry.

21 months agolei_config: drop redundant open check
Eric Wong [Tue, 17 Oct 2023 23:38:13 +0000 (23:38 +0000)] 
lei_config: drop redundant open check

autodie already takes care of checking for open failures.

21 months agolei_auth: update comments and use v5.12
Eric Wong [Tue, 17 Oct 2023 23:38:12 +0000 (23:38 +0000)] 
lei_auth: update comments and use v5.12

There's nothing affected by the `unicode_strings' feature, so
it's safe to use v5.12, here.

21 months agolei: use autodie where appropriate
Eric Wong [Tue, 17 Oct 2023 23:38:11 +0000 (23:38 +0000)] 
lei: use autodie where appropriate

This makes us a bit harsher with misbehaving clients, but we
only have one client implementation at the moment.

21 months agoxt/mem-imapd-tls: reduce FDs for lsof use
Eric Wong [Tue, 17 Oct 2023 23:38:10 +0000 (23:38 +0000)] 
xt/mem-imapd-tls: reduce FDs for lsof use

We need some pipes in our parent process to capture the output
of lsof(1), so give us some more padding for temporary FDs.

21 months agoxt/mem-imapd-tls: remove unused/broken epoll imports
Eric Wong [Tue, 17 Oct 2023 23:38:09 +0000 (23:38 +0000)] 
xt/mem-imapd-tls: remove unused/broken epoll imports

The `:epoll' tag has been gone for a few weeks, and EPOLLIN
isn't used in this file anywhere.

Fixes: 3005c1bc5d05 (ds: use object-oriented API for epoll)
21 months agoinit: use autodie to reduce distractions
Eric Wong [Tue, 17 Oct 2023 23:38:08 +0000 (23:38 +0000)] 
init: use autodie to reduce distractions

This hurts startup time a bit, but our tests use run_script
by default and I don't think normal users call -init enough
to care.

21 months agoinit: drop extraneous `+'
Eric Wong [Tue, 17 Oct 2023 23:38:07 +0000 (23:38 +0000)] 
init: drop extraneous `+'

It's actually valid Perl syntax, but still confusing to look at.

Fixes: add90b9504f4 ("support -C (chdir) for most non-daemon commands")
21 months agotest_common: use $cwdfh for every run_script command
Eric Wong [Tue, 17 Oct 2023 23:38:06 +0000 (23:38 +0000)] 
test_common: use $cwdfh for every run_script command

It's not lei-specific since we have `-C' to perform chdir
for multiple admin commands.

21 months agotest_common: only hide TCP port in messages
Eric Wong [Tue, 17 Oct 2023 23:38:05 +0000 (23:38 +0000)] 
test_common: only hide TCP port in messages

v2:// lei outputs are on the filesystem, so putting $HOST:$PORT
is nonsensical.  We'll also keep `127.0.0.1' or `[::1]' since
it's harmless and can point out obvious errors in system
configuration when testing with old Perls or libraries.

21 months agotest_common: use autodie and read_all where possible
Eric Wong [Tue, 17 Oct 2023 23:38:04 +0000 (23:38 +0000)] 
test_common: use autodie and read_all where possible

Noise reduction to help my aging eyes.

21 months agot/lei-up: additional diagnostics for match failures
Eric Wong [Tue, 17 Oct 2023 23:38:03 +0000 (23:38 +0000)] 
t/lei-up: additional diagnostics for match failures

I'm not sure why, but this test just failed for some odd reason
from `make check-run' on my Debian bullseye workstatation.

21 months agosyscall: common $F_SETPIPE_SZ definition
Eric Wong [Tue, 17 Oct 2023 23:38:02 +0000 (23:38 +0000)] 
syscall: common $F_SETPIPE_SZ definition

We use this in various places to minimize or maximize pipe
size on Linux.  So keep it all in one place.

21 months agocindex: drop some unused functions
Eric Wong [Tue, 17 Oct 2023 23:38:01 +0000 (23:38 +0000)] 
cindex: drop some unused functions

They're no longer needed with the way PublicInbox::CidxLogP is
currently implemented.

21 months agods: get rid of SetLoopTimeout
Eric Wong [Tue, 17 Oct 2023 23:38:00 +0000 (23:38 +0000)] 
ds: get rid of SetLoopTimeout

It's not worth the code and memory to have a setter method we
never use outside of tests.

21 months agods: introduce and use do_fork helper
Eric Wong [Tue, 17 Oct 2023 23:37:59 +0000 (23:37 +0000)] 
ds: introduce and use do_fork helper

This ensures we handle RNG reseeding and resetting the event
loop properly in child processes after forking.

21 months agoxt/git-http-backend: remove Net::HTTP usage
Eric Wong [Tue, 17 Oct 2023 23:37:58 +0000 (23:37 +0000)] 
xt/git-http-backend: remove Net::HTTP usage

HTTP::Tiny is part of the Perl standard library since Perl 5.14
while Net::HTTP has never been (unlike Net::NNTP or Net::POP3).
For the test which forces server-side buffering, we'll just use
regular socket handle.

21 months agoxap_client: autodie for pipe and socketpair
Eric Wong [Tue, 17 Oct 2023 23:37:57 +0000 (23:37 +0000)] 
xap_client: autodie for pipe and socketpair

This saves us a few lines of code.

21 months agoxap_helper: autodie for getsockopt
Eric Wong [Tue, 17 Oct 2023 23:37:56 +0000 (23:37 +0000)] 
xap_helper: autodie for getsockopt

Only caveat is we can't use bareword filehandles, but that's
a minor inconvenience.

21 months agoxap_helper: simplify SIGTERM exit checks
Eric Wong [Tue, 17 Oct 2023 23:37:55 +0000 (23:37 +0000)] 
xap_helper: simplify SIGTERM exit checks

We can just close the socket FD to ensure things fail ASAP
when a SIGTERM hits instead of wasting time making getppid(2)
syscalls.

21 months agoxap_helper: die more easily in both implementations
Eric Wong [Tue, 17 Oct 2023 23:37:54 +0000 (23:37 +0000)] 
xap_helper: die more easily in both implementations

We don't need to tolerate bad requests since it's only handling
requests from the parent process.  So simplify error management
and just die||exit if we get a bad request.

21 months agoxap_helper*: use autodie in more places
Eric Wong [Tue, 17 Oct 2023 23:37:53 +0000 (23:37 +0000)] 
xap_helper*: use autodie in more places

This ought to lower the cognitive overhead of reading our code.

21 months agouse read_all in more places to improve safety
Eric Wong [Tue, 17 Oct 2023 23:37:52 +0000 (23:37 +0000)] 
use read_all in more places to improve safety

`readline' ops may not detect errors on partial reads.
This saves us some code to reduce cognitive overhead for
readers.  We'll also support reusing a destination buffers so it
can work more nicely with existing code.

21 months agolei_mirror: use read_all
Eric Wong [Tue, 17 Oct 2023 23:37:51 +0000 (23:37 +0000)] 
lei_mirror: use read_all

This gives us better error checking for regular files.

21 months agoimport: use read_all to detect short reads
Eric Wong [Tue, 17 Oct 2023 23:37:50 +0000 (23:37 +0000)] 
import: use read_all to detect short reads

Our Import package was depending on Git, anyways.

21 months agogit: introduce read_all function
Eric Wong [Tue, 17 Oct 2023 23:37:49 +0000 (23:37 +0000)] 
git: introduce read_all function

This makes it easier to improve error checking, since the
`do { local $/; readline(FH) }' construct does not detect
errors (autodie does not cover `readline' or `<FH>').

I'm not sure exactly where this should be, but PublicInbox::Git
is used nearly everywhere in our code base and it's probably
not worth creating a new package for it.

21 months agolei_mirror: use autodie for most `open' calls
Eric Wong [Tue, 17 Oct 2023 23:37:48 +0000 (23:37 +0000)] 
lei_mirror: use autodie for most `open' calls

We'll also drop most `print' checks since we need to rely on
`close' or IO::Handle->flush for error checking, anyways.

21 months agolei_mirror: autodie most `close' calls
Eric Wong [Tue, 17 Oct 2023 23:37:47 +0000 (23:37 +0000)] 
lei_mirror: autodie most `close' calls

Another step towards reducing our code burden and having
more consistent error messages.

21 months agolei_mirror: start converting to autodie
Eric Wong [Tue, 17 Oct 2023 23:37:46 +0000 (23:37 +0000)] 
lei_mirror: start converting to autodie

This code is too noisy and not critical for startup performance;
so autodie provides a nice noise reduction while improving error
reporting in most cases.

For places where failures are expected, the `CORE::' prefix
gives us an easy escape hatch to fall back to normal error
checking.

21 months agoinput_pipe: fix socket check
Eric Wong [Tue, 17 Oct 2023 21:47:13 +0000 (21:47 +0000)] 
input_pipe: fix socket check

`-S' is the correct file test op for sockets, `-s' is for st_size.

21 months agoinput_pipe: handle noncanonical TTY
Eric Wong [Tue, 17 Oct 2023 10:11:06 +0000 (10:11 +0000)] 
input_pipe: handle noncanonical TTY

lei could get a TTY in noncanonical mode for stdin, so rely on
VMIN+VTIME to get the desired non-blocking semantics we'd expect
from a pipe or socket.  This ought to prevent read(2) (Perl sysread)
from returning zero when we really want to hit EAGAIN.

21 months agoinput_pipe: improve error handling
Eric Wong [Tue, 17 Oct 2023 10:11:05 +0000 (10:11 +0000)] 
input_pipe: improve error handling

Ensure the callback is always guarded by `eval' to catch
exceptions and to force a ->close (EPOLL_CTL_DEL).

We also don't want to blindly set O_NONBLOCK on TTYs since their
O_NONBLOCK semantics aren't well-defined by POSIX.  We can also
drop EPOLLET (edge-triggered) use to reduce the need to make
->requeue calls on our end.

21 months agolei: consolidate stdin slurp, fix warnings
Eric Wong [Tue, 17 Oct 2023 10:11:04 +0000 (10:11 +0000)] 
lei: consolidate stdin slurp, fix warnings

We can share more code amongst stdin slurper (not streaming)
commands.  This also fixes uninitialized variable warnings when
feeding an empty stdin to these commands.

21 months agoinstall/README: improve wording
Eric Wong [Tue, 17 Oct 2023 06:43:18 +0000 (06:43 +0000)] 
install/README: improve wording

Reported-by: Štěpán Němec <stepnem@smrk.net>
21 months agosearch: rectify comment (rt: documented since 738c4a65719e)
Štěpán Němec [Mon, 16 Oct 2023 11:33:04 +0000 (13:33 +0200)] 
search: rectify comment (rt: documented since 738c4a65719e)

Fixes: 738c4a65719e ("www: various help text updates")
21 months agodoc: lei-q: drop stale TODO comment (fixed in 1f1b1f0e22f7)
Štěpán Němec [Mon, 16 Oct 2023 11:33:03 +0000 (13:33 +0200)] 
doc: lei-q: drop stale TODO comment (fixed in 1f1b1f0e22f7)

Fixes: 1f1b1f0e22f7 ("doc: lei-q: document SEARCH TERMS prefixes")
21 months agodoc: fix some typos and grammar
Štěpán Němec [Mon, 16 Oct 2023 11:33:02 +0000 (13:33 +0200)] 
doc: fix some typos and grammar

[ew: leave install/README unchanged pending wording changes]

21 months agolearn: respect indexlevel for v1 inboxes
Eric Wong [Sun, 15 Oct 2023 08:16:28 +0000 (08:16 +0000)] 
learn: respect indexlevel for v1 inboxes

v2 never suffered from this bug, apparently, but -learn didn't
seem able to handle indexlevel=basic (nor respect `medium')
for v1 inboxes.  I only noticed this bug because I converted
some ancient v1 inboxes to `basic' to save space.

21 months agoxap_helper_cxx: allow sharing XDG_CACHE_HOME across ABIs
Eric Wong [Fri, 13 Oct 2023 06:12:29 +0000 (06:12 +0000)] 
xap_helper_cxx: allow sharing XDG_CACHE_HOME across ABIs

For users sharing home directories (or just XDG_CACHE_HOME)
across hosts of different architectures, we must use a compiler
and architecture-specific destination directory for storing the
binary result.  Even on the same OS and architecture, different
C++ compilers may have different ABIs, so we must account for
that.

21 months agolei: quiet excessive write/seen messages
Eric Wong [Thu, 12 Oct 2023 00:21:00 +0000 (00:21 +0000)] 
lei: quiet excessive write/seen messages

We don't want to end up dumping nr_seen/nr_write when progress
is disabled, nor do we want forked off `lei note-event' workers
dump them when DS->Reset is called on fork.

21 months agoemergency: support hostname of `.'
Eric Wong [Wed, 11 Oct 2023 08:18:28 +0000 (08:18 +0000)] 
emergency: support hostname of `.'

I think I was too lazy when configuring my Dragonfly VM install.

21 months agolei import|tag|rm: support --commit-delay=SECONDS
Eric Wong [Wed, 11 Oct 2023 07:20:57 +0000 (07:20 +0000)] 
lei import|tag|rm: support --commit-delay=SECONDS

Delayed commits  allows users to trade off immediate safety for
throughput and reduced storage wear when running multiple
discreet commands.

This feature is currently useful for providing a way to make
t/lei-store-fail.t reliable and for ensuring `lei blob' can
retrieve messages which have not yet been committed.

In the future, it'll also be useful for the FUSE layer to batch
git activity.

21 months agolei blob: run cat_blob on lei/store for pending blobs
Eric Wong [Wed, 11 Oct 2023 07:20:56 +0000 (07:20 +0000)] 
lei blob: run cat_blob on lei/store for pending blobs

This can probably be made asynchronous in the future via
PublicInbox::InputPipe, but it's good enough for testing.

21 months agoimport: cat_blob is a no-op w/o live fast-import
Eric Wong [Wed, 11 Oct 2023 07:20:55 +0000 (07:20 +0000)] 
import: cat_blob is a no-op w/o live fast-import

cat_blob is a fallback for handling files which haven't made it
onto disk to be readable by `git cat-file'.  Thus spawning a new
fast-import process to retrieve a blob is pointless, as cat_blob
is only used as a last resort when `git cat-file' fails.

21 months agoimport: switch to Unix stream socket for fast-import
Eric Wong [Wed, 11 Oct 2023 07:20:54 +0000 (07:20 +0000)] 
import: switch to Unix stream socket for fast-import

We use fewer file descriptors and fewer lines of code this way.
I'm not aware of any place we rely on POSIX pipe semantics with
`git fast-import', and sockets have bigger buffers by default
in most cases (even if Linux allows larger pipe buffers).

21 months agotreewide: consolidate "From " line removal
Eric Wong [Wed, 11 Oct 2023 07:20:53 +0000 (07:20 +0000)] 
treewide: consolidate "From " line removal

Aside from our prior import bugs (fixed in a0c07cba0e5d8b6a
(mda: drop leading "From " lines again, 2016-06-26)), we'll
always have to be dealing with mutt piping messages to us and
`git format-patch' output.  So just share the regexp so we
can use it everywhere.

In may be desirable to allow importing messages with a leading
"From " line for FUSE, even.

Additionally, some instances of this regexp needlessly added
optional `\r?' (CR) checks ahead of the `\n' (LF) element; but
they're pointless anyways since [^\n]* is enough to exclude all
non-LF bytes.

21 months agomsgtime: simplify msg_timestamp and msg_datestamp
Eric Wong [Wed, 11 Oct 2023 07:20:52 +0000 (07:20 +0000)] 
msgtime: simplify msg_timestamp and msg_datestamp

We don't need multiple return points nor multiple time_response
calls in either function.

21 months agomsgtime: quiet warnings we can do nothing about
Eric Wong [Wed, 11 Oct 2023 07:20:51 +0000 (07:20 +0000)] 
msgtime: quiet warnings we can do nothing about

In retrospect, warning about bad times and dates is pointless
since there's nothing actionable about it.  We'll also drop an
unnecessary capture in msg_received_at while we're at it and
favor using $eml since as the input variable name to match
current usage.

The note to install Date::Parse as a fallback remains since it
can be helpful in some cases (and is actionable by the user).

21 months agolei_xsearch: improve curl progress reporting
Eric Wong [Wed, 11 Oct 2023 07:20:50 +0000 (07:20 +0000)] 
lei_xsearch: improve curl progress reporting

Instead of having tail(1) follow a file when we're in verbose
mode, unconditionally pipe stderr to a Perl 2-liner which tees
its output to a regular file with line buffering.

POSIX tee(1) isn't suitable for this task since it's required
to be completely unbuffered while we want line-buffering when
running parallel processes.  Fortunately, Perl makes this easy.

This also means we no longer leave curl-err.XXXX files around
on premature shutdown if we're hit by a SIGKILL or similar and
can't exit normally.

We do need to stop and respawn the Perl process if we hit a curl
error, though, since we need to be certain the output is
flushed.

21 months agolei rediff: use ProcessIO for --drq support
Eric Wong [Wed, 11 Oct 2023 07:20:49 +0000 (07:20 +0000)] 
lei rediff: use ProcessIO for --drq support

This required fixing binmode support a few commits ago, along
with properly enabling autoflush in popen_wr instead of setting
it on the wrapper ProcessIO class.

21 months agot/imap_searchqp.t: retry bad query test on failure
Eric Wong [Tue, 10 Oct 2023 10:42:48 +0000 (10:42 +0000)] 
t/imap_searchqp.t: retry bad query test on failure

I really don't understand why this fails, sometimes; but it does.

21 months agods: use a dummy poller during Reset
Eric Wong [Tue, 10 Oct 2023 10:09:04 +0000 (10:09 +0000)] 
ds: use a dummy poller during Reset

commit 1897c3be1ed644a05f96ed06cde4a9cc2ad0e5a4
(ds: Reset: replace Poller object early, 2023-10-04)
was not effective at eliminating the following message
at daemon shutdown:

Can't call method "FILENO" on an undefined value at
.../PublicInbox/Select.pm line 34 during global destruction.

This seems down to some tied objects having unpredictable
destruction order.  So use a dummy class to ensure its ep_*
methods never call the tied `FILENO' method at all since
dropping the Poller object will release any resources it holds.

21 months agoover*: avoid defined-or hash assignments with side-effects
Eric Wong [Tue, 10 Oct 2023 10:07:56 +0000 (10:07 +0000)] 
over*: avoid defined-or hash assignments with side-effects

These may've been causing strange errors[1] in t/imapd.t from
the -watch daemon, such as:

Cannot copy to HASH in scalar assignment ../PublicInbox/Over.pm

in the Over->dbh() sub.  I've only noticed this failure on
FreeBSD 13.2 (Perl 5.32.1, DBD::SQLite 1.72 (bundled SQLite
3.39.4), DBI 1.643) so far, so it could also be something to do
with the versions used and/or memory layout differences
with libc or build toolchain.

21 months agot/nntp.t: attempt to track source of undefined vars
Eric Wong [Tue, 10 Oct 2023 09:03:09 +0000 (09:03 +0000)] 
t/nntp.t: attempt to track source of undefined vars

Occasionally, t/nntp.t spews undefined variable warnings under
`make check-run'.  While the test doesn't fail, it's annoying
to see them and it could be a source of deeper problems.

21 months agospawn: reinstate directory existence check
Eric Wong [Mon, 9 Oct 2023 18:16:18 +0000 (18:16 +0000)] 
spawn: reinstate directory existence check

We must not attempt to use Inline::C unless a user requests
it (by creating the directory) or running lei.

Fixes: ebdccd6666f9 (spawn: drop checks for directory writability)
21 months agowww_coderepo: fix handling of non-UTF-8 git data
Eric Wong [Mon, 9 Oct 2023 17:56:23 +0000 (17:56 +0000)] 
www_coderepo: fix handling of non-UTF-8 git data

We can't assume git output is UTF-8, and we'll always have
legacy data in git coderepos.  So attempt to display some
some garbled text rather than nothing at all if Perl croaks
on it.

sox commit c38987e8d20505621b8d872863afa7d233ed1096
(Added raw inverse-bit u-law and A-law support.  Updated *.txt files., 2001-12-13)
is an example of a commit which caused problems for me.

21 months agointroduce ProcessIONBF for multiplexed non-blocking IO
Eric Wong [Sun, 8 Oct 2023 22:11:48 +0000 (22:11 +0000)] 
introduce ProcessIONBF for multiplexed non-blocking IO

This is required for reliable epoll/kevent/poll/select
wakeup notifications, since we have no visibility into
the buffer states used internally by Perl.

We can safely use sysread here since we never use the :utf8
nor any :encoding Perl IO layers for readable pipes.

I suspect this fixes occasional failures from t/solver_git.t
when retrieving the WwwCoderepo summary.

21 months agoprocess_io: fix binmode and use it in lei_xsearch
Eric Wong [Sun, 8 Oct 2023 22:11:47 +0000 (22:11 +0000)] 
process_io: fix binmode and use it in lei_xsearch

The `binmode' perlop can only take two scalars, so passing
`@_' blindly won't work since prototypes are checked.  This
means we can get IO::Uncompress::Gunzip working properly
with ProcessIO and use it for curl.

We'll also just autodie (instead of warn) on FS errors when
dealing with curl stderr; since the process will likely be
in bigger trouble soon, anyways.

21 months agooveridx: use croak/confess instead of die
Eric Wong [Sun, 8 Oct 2023 20:19:40 +0000 (20:19 +0000)] 
overidx: use croak/confess instead of die

Unlike `die', `croak' can be expanded to `confess' to give a
full backtrace.  We'll use `confess' on transaction failures
since that occasionally causes sporadic t/imapd.t failures on
FreeBSD (IO::Kqueue is installed, so signals are deferred).

21 months agocindex: start using autodie
Eric Wong [Sat, 7 Oct 2023 21:24:10 +0000 (21:24 +0000)] 
cindex: start using autodie

A small step towards making this code less noisy.

21 months agoprocess_io: pass args to awaitpid as list
Eric Wong [Sat, 7 Oct 2023 21:24:09 +0000 (21:24 +0000)] 
process_io: pass args to awaitpid as list

Specifying {cb_args} in the options hash felt awkward to me.
Instead, just use the Perl stack like we do with awaitpid()
and pass the list down directly.

21 months agorename ProcessPipe to ProcessIO
Eric Wong [Sat, 7 Oct 2023 21:24:08 +0000 (21:24 +0000)] 
rename ProcessPipe to ProcessIO

Since we deal with pipes (of either direction) and bidirectional
stream sockets for this class, it's better to remove the `Pipe'
from the name and replace it with `IO' to communicate that it
works for any form of IO::Handle-like object tied to a process.

21 months agoimport: use autodie, rely on PerlIO for retries
Eric Wong [Sat, 7 Oct 2023 21:24:07 +0000 (21:24 +0000)] 
import: use autodie, rely on PerlIO for retries

As documented in perlipc(1), the default :perlio layer retries
the `read' perlop on EINTR.  The :perlio layer also makes `read'
perform read-in-full behavior; so there's no need to loop
ourselves.  Our responsibility is now only to detect short reads
in case fast-import is killed mid-stream.

21 months agoipc: use autodie for most syscalls
Eric Wong [Sat, 7 Oct 2023 21:24:06 +0000 (21:24 +0000)] 
ipc: use autodie for most syscalls

I'm not sure how/if we should bother recovering from these,
so just croak and let some caller deal with it.  `autodie'
uses Carp internally, so setting `PERL5OPT=-MCarp=verbose'
in the environment gives us full stacktraces.

21 months agoipc: require fork+SOCK_SEQPACKET for wq_* functions
Eric Wong [Sat, 7 Oct 2023 21:24:05 +0000 (21:24 +0000)] 
ipc: require fork+SOCK_SEQPACKET for wq_* functions

None of the lei internals works properly without forking and
sockets.  The fallback code increases the potential to accidentally
call subs in the wrong process during the teardown phase.

We'll still support ipc_do w/o forking for now since it
forking doesn't benefit small indexing runs from -mda and
such.

21 months agolei: always use async `done' requests to store
Eric Wong [Sun, 8 Oct 2023 18:54:03 +0000 (18:54 +0000)] 
lei: always use async `done' requests to store

It's safer against deadlocks and we still get proper error
reporting by passing stderr across in addition to the lei
socket.

21 months agolei: fix implicit stdin support for pipes
Eric Wong [Sun, 8 Oct 2023 05:49:34 +0000 (05:49 +0000)] 
lei: fix implicit stdin support for pipes

Eric Wong <e@80x24.org> wrote:
> +++ b/t/lei-store-fail.t

> + my $cmd = [ qw(lei import -q -F mboxrd) ];
> + my $tp = start_script($cmd, undef, $opt);

Of course the lack of `-' or  `--stdin' only worked on Linux and
NetBSD, but not other BSDs.

-------8<------
Subject: [PATCH] lei: fix implicit stdin support for pipes

st_mode permission bits can't be used to determine if a file or
pipe we have on stdin readable or not.  Writable regular files
can be opened O_RDONLY, and permissions bits for pipes are
inconsistent across platforms.

On FreeBSD, OpenBSD, and Dragonfly, only the S_IFIFO bit is set
in st_mode with none of the permission bits are set.  Linux and
NetBSD have both the read and write permission bits set for both
ends of a the pipe, so they're just as inaccurate but allowed
the feature to work before this change.

For now, we'll just assume our users know that stdin is intended
for input and consider any pipe or regular file to be readable.

If we were to be pedantic, we'd check O_RDONLY or O_RDWR
description flags via the F_GETFL fcntl(2) op to determine if a
pipe or socket is readable.  However, I don't think it's worth
the code to do so.

21 months agolei: do not issue sto->done if socket is inactive
Eric Wong [Sat, 7 Oct 2023 21:24:03 +0000 (21:24 +0000)] 
lei: do not issue sto->done if socket is inactive

This fixes attempts to use an undefined value as an ARRAY reference
in PublicInbox::IPC::wq_io_do

21 months agoxt/httpd-async-stream: avoid waitpid call
Eric Wong [Sat, 7 Oct 2023 21:24:02 +0000 (21:24 +0000)] 
xt/httpd-async-stream: avoid waitpid call

We can just use the non-wantarray form of popen_rd to
save us some extra error checking.

21 months agofinalize DragonFlyBSD support
Eric Wong [Fri, 6 Oct 2023 09:46:04 +0000 (09:46 +0000)] 
finalize DragonFlyBSD support

require_bsd and require_mods(':fcntl_lock') are now
supported in TestCommon to make it easier to maintain
than a big list of regexps.

getsockopt for SO_ACCEPTFILTER seems to always succeed,
even if the retrieved struct is all zeroes.

21 months agot/dir_idle: dump event list on failure
Eric Wong [Fri, 6 Oct 2023 09:46:03 +0000 (09:46 +0000)] 
t/dir_idle: dump event list on failure

Hopefully this makes it easier to diagnose portability
problems on new OSes we use.

21 months agodevel/sysdefs-list: show more info regardless of OS
Eric Wong [Fri, 6 Oct 2023 09:46:02 +0000 (09:46 +0000)] 
devel/sysdefs-list: show more info regardless of OS

We'll show SO_ACCEPTFILTER since it's supported on three
of the BSDs we support.

21 months agoxap_helper.h: strdup keys for DragonFlyBSD hdestroy(3)
Eric Wong [Fri, 6 Oct 2023 09:46:01 +0000 (09:46 +0000)] 
xap_helper.h: strdup keys for DragonFlyBSD hdestroy(3)

DragonFlyBSD matches OpenBSD behavior in freeing every single key on
hdestroy(3).  I suppose hdestroy(3) is neglected enough these days that
nobody cares and we'll likely introduce a small C hash table such as
khash (also used within git).

21 months agokqnotify: drop EV_CLEAR (edge triggering)
Eric Wong [Fri, 6 Oct 2023 09:46:00 +0000 (09:46 +0000)] 
kqnotify: drop EV_CLEAR (edge triggering)

I'm not entirely certain how it works with the way we use
kevent.  I do know IO::KQueue has hard-coded kevent retrievals
to 1000 events so it's conceivable we'd end up missing wakeups
as we don't loop or requeue in callers.  So just rely on the
*BSD kernel to provided requeue behavior for us by using
level-triggering.

In any case, this seems to workaround t/dir_idle.t failures
on Dragonfly due to a tmpfs bug in all versions up to v6.4.

21 months agoipc: lower-level send_cmd/recv_cmd handle EINTR directly
Eric Wong [Fri, 6 Oct 2023 01:02:58 +0000 (01:02 +0000)] 
ipc: lower-level send_cmd/recv_cmd handle EINTR directly

This ensures script/lei $send_cmd usage is EINTR-safe (since
I prefer to avoid loading PublicInbox::IPC for startup time).
Overall, it saves us some code, too.

21 months agomakefile: symlink-install: do not depend on realpath
Eric Wong [Wed, 4 Oct 2023 17:46:35 +0000 (17:46 +0000)] 
makefile: symlink-install: do not depend on realpath

For the Makefile, we can use $(PWD) make macro from make(1posix)
as POSIX requires all environment variables be accessible as
macros, and $PWD is a standard sh(1) environment variable.

lei.sh must quiet the stderr of realpath before falling back to
readlink(1) which is available on NetBSD.

21 months agods: make %AWAIT_PIDS a hash, not hashref
Eric Wong [Wed, 4 Oct 2023 08:50:58 +0000 (08:50 +0000)] 
ds: make %AWAIT_PIDS a hash, not hashref

This is more persistent than some of the others and we don't
swap it on use (unlike $nextq or $ToClose).  In other words,
it's helpful for communicating its lifetime expectancy is
close to %DescriptorMap and not like to queue-type things
such as $ToClose.

21 months agods: cleanup fork + Reset support
Eric Wong [Wed, 4 Oct 2023 08:50:57 +0000 (08:50 +0000)] 
ds: cleanup fork + Reset support

We used to have many entries for %Stack, but nowadays it's just
the one used by next_tick, so just replace it a $cur_runq variable.

I'm reducing reliance on hash keys for things with global scope
to ensure typos can be detected (strict||v5.12 forces us to fix
uses of undeclared variables, but they can't detect typos in
hash keys.

21 months agods: Reset: replace Poller object early
Eric Wong [Wed, 4 Oct 2023 08:50:56 +0000 (08:50 +0000)] 
ds: Reset: replace Poller object early

Process shutdown can be chaotic and unpredictable.  Try to make
it more predictable by ensuring any PublicInbox::Select object
can't hold references to any objects.

This should fix the following error I saw in syslog during a deploy:

Can't call method "FILENO" on an undefined value at
.../PublicInbox/Select.pm line 34 during global destruction.

Replacing $Poller with PublicInbox::Select (instead of undef-ing
it) means we can avoid adding branches to ->epwait and ->close
before calls to ->ep_mod and ->ep_del, respectively.

21 months agosearchidx: fix redundant `in' in warning message
Eric Wong [Wed, 4 Oct 2023 03:49:33 +0000 (03:49 +0000)] 
searchidx: fix redundant `in' in warning message

Fortunately, I've never actually seen that message...

21 months agolei: document and local-ize $OPT hashref
Eric Wong [Wed, 4 Oct 2023 03:49:32 +0000 (03:49 +0000)] 
lei: document and local-ize $OPT hashref

This variable needs to be visible to a callback running inside
Getopt::Long, but we don't need to keep it around after
LEI->optparse runs.

21 months agospawn: drop checks for directory writability
Eric Wong [Wed, 4 Oct 2023 03:49:31 +0000 (03:49 +0000)] 
spawn: drop checks for directory writability

It's a TOUTTOC bug to do stat or access checks, anyways,
so just use the file and let autodie::sysopen PublicInbox::Lock
take care of the rest.

21 months agoxap_helper.pm: use EINTR-aware recv_cmd
Eric Wong [Wed, 4 Oct 2023 03:49:30 +0000 (03:49 +0000)] 
xap_helper.pm: use EINTR-aware recv_cmd

The code is already loaded, so there's no point in avoiding it.

21 months agoxap_helper: retry flock on EINTR
Eric Wong [Wed, 4 Oct 2023 03:49:29 +0000 (03:49 +0000)] 
xap_helper: retry flock on EINTR

While signals are currently blocked in these helpers,
they may not always be...

21 months agospawn: use autodie and PublicInbox::Lock
Eric Wong [Wed, 4 Oct 2023 03:49:28 +0000 (03:49 +0000)] 
spawn: use autodie and PublicInbox::Lock

It keeps Spawn.pm less noisy and ensures retries on EINTR.

21 months agogcf2: use PublicInbox::Lock
Eric Wong [Wed, 4 Oct 2023 03:49:27 +0000 (03:49 +0000)] 
gcf2: use PublicInbox::Lock

It auto-retries on EINTR and saves us the trouble of doing so.

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)