]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
3 years agodoc: add lei-import(1)
Kyle Meyer [Thu, 11 Feb 2021 04:04:14 +0000 (23:04 -0500)]
doc: add lei-import(1)

3 years agodoc: lei: prefer 'location' and 'dirname'
Kyle Meyer [Thu, 11 Feb 2021 04:04:13 +0000 (23:04 -0500)]
doc: lei: prefer 'location' and 'dirname'

This follows the help output change in 52342875 (lei help: split out
into separate file, 2021-02-06).

3 years agodoc: lei q: use 'mfolder' as --output placeholder
Kyle Meyer [Thu, 11 Feb 2021 04:04:12 +0000 (23:04 -0500)]
doc: lei q: use 'mfolder' as --output placeholder

'mfolder' is familiar to mairix users, and 'path' isn't a good choice
because support will be added for IMAP.

Link: https://public-inbox.org/meta/YCBh62OqkYnr5cqw@dcvr
3 years agotests: skip properly with git <2.6
Eric Wong [Wed, 10 Feb 2021 21:50:48 +0000 (21:50 +0000)]
tests: skip properly with git <2.6

Tested with git 1.8.3.1 on CentOS 7.x

`plan skip_all => ...' doesn't work after some tests have run,
we have to call skip() instead.

3 years agosearch: fix argv handling of quoted phrases
Eric Wong [Wed, 10 Feb 2021 09:59:26 +0000 (08:59 -0100)]
search: fix argv handling of quoted phrases

This fixes both an old bug in "lei q" argv handling and one
recent regression introduced with the change to use approxidate.

Field prefixes are also handled correctly inside parenthesized
statements when the field follows "(" without a separation
character.

Fixes: fbb7ccabbf54a405 ("lei q: use git approxidate with d:, dt: and rt: ranges")
3 years agolei_external: fix+test handling of escaped braces
Eric Wong [Wed, 10 Feb 2021 08:38:39 +0000 (07:38 -0100)]
lei_external: fix+test handling of escaped braces

While '{' and '}' are rare in path names, somebody may still
use them or deal with software which does (e.g. GNU arch).

3 years agonet_reader: new package split from -watch
Eric Wong [Wed, 10 Feb 2021 07:07:49 +0000 (07:07 +0000)]
net_reader: new package split from -watch

We'll be using some of this for IMAP and NNTP support in lei,
too.  More will need to be done to improve code sharing and
reusability, soon, but this is a start.

3 years agolei: note some TODO items (curl, externals)
Eric Wong [Wed, 10 Feb 2021 07:07:48 +0000 (07:07 +0000)]
lei: note some TODO items (curl, externals)

I don't know if it's worth it to use libcurl directly
(nor the effort to support and maintain tests)

3 years agolei ls-external: support --local and --remote
Eric Wong [Wed, 10 Feb 2021 07:07:47 +0000 (07:07 +0000)]
lei ls-external: support --local and --remote

Similar to "lei q", "--local" means only local and "--remote"
means remote only.  I can't think of a reason to have --no-*
variants for these switches.

There's also updates to the TestCommon for more common lei
cases.

3 years agotest_common: support lei-daemon only testing
Eric Wong [Wed, 10 Feb 2021 07:07:46 +0000 (07:07 +0000)]
test_common: support lei-daemon only testing

Daemon-only tests can be significantly faster due to cached
configs; so give developers a chance to test only daemons to
improve productivity.

The differences between daemon and oneshot modes are minimal,
at this point.

3 years agolei_external: remove unnecessary Exporter use
Eric Wong [Wed, 10 Feb 2021 07:07:45 +0000 (07:07 +0000)]
lei_external: remove unnecessary Exporter use

We don't need to export for methods which are only called via
"->" or "->can".

3 years agolei *external: glob improvements, ls-external filtering
Eric Wong [Wed, 10 Feb 2021 07:07:44 +0000 (07:07 +0000)]
lei *external: glob improvements, ls-external filtering

The "ls-external" now accepts the same glob patterns used by
with lei q --{include,only,exclude}.  If no glob is detected, it
will be treated as a literal substring match (like "grep -F").

Inverting matches is also supported ("grep -v").

3 years agotests|lei: fixes for TEST_RUN_MODE=0 and lei oneshot
Eric Wong [Tue, 9 Feb 2021 08:09:37 +0000 (07:09 -0100)]
tests|lei: fixes for TEST_RUN_MODE=0 and lei oneshot

DESTROY callbacks can clobber $?, so we must take care to
preserve it when exiting.  We'll also try to make an effort to
ensure better DESTROY ordering and delete as much as possible
before x_it finishes.

We also need to load PublicInbox::Config when setting up
public inboxes.

3 years agolei: replace "I:"-prefixed info messages with "#"
Eric Wong [Tue, 9 Feb 2021 08:09:36 +0000 (07:09 -0100)]
lei: replace "I:"-prefixed info messages with "#"

The "#" is what TAP <https://testanything.org/> uses,
which is also consistent with what our (and many other)
test suites emit.

3 years agot/run.perl: drop Cwd dependency
Eric Wong [Tue, 9 Feb 2021 08:09:35 +0000 (07:09 -0100)]
t/run.perl: drop Cwd dependency

Perl 5.8.8/5.10.0+ can use fchdir(), and we depend on 5.10.1+

3 years agolei q: prefix --alert ops with ':' instead of '-'
Eric Wong [Tue, 9 Feb 2021 08:09:34 +0000 (07:09 -0100)]
lei q: prefix --alert ops with ':' instead of '-'

Using dashed keywords confuses the option parser without
"=" signs (and bash completion doesn't yet work with "=").

So use ":" instead of "-" as the prefix for internal ops,
since ":" is just as unlikely to be the first character of
an executable file in a user's $PATH.

3 years agouse MdirReader in -watch and InboxWritable
Eric Wong [Tue, 9 Feb 2021 08:09:33 +0000 (07:09 -0100)]
use MdirReader in -watch and InboxWritable

MdirReader now handles files in "$MAILDIR/new" properly and
is stricter about what it accepts.  eml_from_path is also
made robust against FIFOs while eliminating TOCTOU races with
between stat(2) and open(2) calls.

3 years agot/run.perl: fix for >128 tests
Eric Wong [Tue, 9 Feb 2021 08:09:32 +0000 (07:09 -0100)]
t/run.perl: fix for >128 tests

We need to explicitly close the write-end of the pipe in workers
to ensure they don't prevent each other from seeing EOF.

Also, make a note to keep using the pipe for now since
Linux <3.14 had broken read(2) semantics when file descriptions
are shared across threads/processes.

3 years agolei: split out MdirReader package, lazy-require earlier
Eric Wong [Tue, 9 Feb 2021 08:09:31 +0000 (07:09 -0100)]
lei: split out MdirReader package, lazy-require earlier

We'll do more requires in the top-level lei-daemon process to
save work in workers.  We can also work towards aborting on
user errors in lei-daemon rather than worker processes.

"lei import -f mbox*" is finally tested inside t/lei_to_mail.t

3 years agogit: ->qx: respect caller's $/ in array context
Eric Wong [Tue, 9 Feb 2021 08:09:30 +0000 (07:09 -0100)]
git: ->qx: respect caller's $/ in array context

This could lead to bad results when doing ls-tree -z
for v2 import in case there's multiple files.  In any case,
the `local $/ = "\0"' in Import.pm is also eliminated to
reduce potential confusion and surprises.

3 years agot/cgi.t: modernizations and style updates
Eric Wong [Tue, 9 Feb 2021 08:09:29 +0000 (07:09 -0100)]
t/cgi.t: modernizations and style updates

We prefer BAIL_OUT or fail to die in tests (I didn't know
BAIL_OUT existed when I started the project).  We can also
depend on IO::Uncompress::Gunzip being available,

We'll keep the cgi_run wrapper since the .cgi could
use some coverage and remove the FIXME note.  run_script
makes tests fast enough.

3 years agotest_common: disable fsync on the CLI where possible
Eric Wong [Tue, 9 Feb 2021 08:09:28 +0000 (07:09 -0100)]
test_common: disable fsync on the CLI where possible

This makes tests faster for users on slow TMPDIR (or not using
eatmydata) and forces coverage on a non-default switch.

Unfortunately, this doesn't yet cover InboxWritable usage.

3 years agot/thread-index-gap.t: avoid unnecessary map
Eric Wong [Tue, 9 Feb 2021 08:09:27 +0000 (07:09 -0100)]
t/thread-index-gap.t: avoid unnecessary map

We only care abount the number of results.

3 years agowww: stream mboxrd in descending docid order
Eric Wong [Mon, 8 Feb 2021 18:33:39 +0000 (08:33 -1000)]
www: stream mboxrd in descending docid order

Order doesn't matter when users are completely downloading
mboxrds onto the FS and then opening them with an MUA.  The
MUA is expected to sort the results in the user's preferred
order.

However, lei can start streaming the results to its destination
Maildir (or eventually IMAP/JMAP mailbox) with an MUA already
open.  This will let users see recent results sooner in their
MUA, as those tend to have a higher docid.  This matches the
behavior of the HTML results, as well.

As a bonus, this is around ~5% faster in a one-off, informal
test case with 66k results.  I expect this to hold true in all
all cases since git has always optimized storage to favor recent
objects.

3 years agospawnpp: raise exception on E2BIG errors
Eric Wong [Mon, 8 Feb 2021 09:05:21 +0000 (23:05 -1000)]
spawnpp: raise exception on E2BIG errors

This matches the Inline::C version, and lets us test
argv overflow with $search->query_argv_to_string;

3 years agosearch: use one git-rev-parse process for all dates
Eric Wong [Mon, 8 Feb 2021 09:05:20 +0000 (23:05 -1000)]
search: use one git-rev-parse process for all dates

This is necessary to avoid slowdowns with pathological cases
with many dates in the query, since each rev-parse invocation
takes ~5ms.

This is immeasurably slower with one open-ended range, but
already faster with any closed range featuring two dates which
require parsing via git.

3 years agolei q: use git approxidate with d:, dt: and rt: ranges
Eric Wong [Mon, 8 Feb 2021 09:05:19 +0000 (23:05 -1000)]
lei q: use git approxidate with d:, dt: and rt: ranges

Instead of having --(sent|received)-(before|after)=s
command-line switches, we'll just try to make sense of argv so
it's usable within parenthesized statements and such.

Given the negligible performance penalty with Inline::C
process spawning, we'll probably wire this up to the
WWW interface, too.

"d:" is for mairix compatibility.  I don't know if "dt:" and
"rt:" will be too useful, but they exist because of IMAP
(and JMAP).

3 years agogit: implement date_parse method
Eric Wong [Mon, 8 Feb 2021 09:05:18 +0000 (23:05 -1000)]
git: implement date_parse method

Users are expected to be familiar with git's "approxidate"
functionality for parsing dates, so we'll expose that
in our UIs.  Xapian itself has limited date parsing functionality
and I can't expect users to learn it.

This takes around 4-5ms on my aging workstation, so it'll
probably be made acceptable for the WWW UI, even.

libgit2 has a git__date_parse function which I expect to have
less overhead, but it's only for internal use at the moment.

3 years agolei: drop BSD::Resource usage
Eric Wong [Mon, 8 Feb 2021 09:05:17 +0000 (23:05 -1000)]
lei: drop BSD::Resource usage

It's no longer necessary with the changes to stop doing
FD passing in our backend.

cf. commits 5180ed0a1cd65139 and 7d440bf3667b8ef5
    ("lei q: eliminate $not_done temporary git dir hack")
    ("lei q: reorder internals to reduce FD passing")

3 years agolei: avoid racing on unlink + bind + listen
Eric Wong [Mon, 8 Feb 2021 09:05:16 +0000 (23:05 -1000)]
lei: avoid racing on unlink + bind + listen

When multiple lei(1) processes are starting in parallel without
lei-daemon already running, it's possible for them to trample
each others' socket path trying to start lei-daemon.  Lock
errors.log before unlink/bind/listen.  We'll add an extra
connect(2) attempt to check if the starter lost the race.

Without this change, a stress script like the following could
easily cause problems:

lei q -o ~/tmp/a foo ... &
lei q -o ~/tmp/b bar ... &
lei q -o ~/tmp/c quux ... &
lei q -o ~/tmp/d baz ... &

3 years agolei: start_pager: drop COLUMNS default
Eric Wong [Mon, 8 Feb 2021 09:05:15 +0000 (23:05 -1000)]
lei: start_pager: drop COLUMNS default

It shouldn't be needed since none of our subcommands will care
or attempt to format output.  Once "lei show" is implemented,
we'll run "git show" directly on the result.

3 years agods: improve add_timer usability
Eric Wong [Mon, 8 Feb 2021 09:05:14 +0000 (23:05 -1000)]
ds: improve add_timer usability

Packing args into an arrayref is awkward and we may be using
this API more in lei.

3 years agotests: favor IPv6
Eric Wong [Mon, 8 Feb 2021 09:05:13 +0000 (23:05 -1000)]
tests: favor IPv6

IPv4 gets plenty of real-world coverage, and apparently there's
Debian buildd hosts which lack IPv4(*).  So ensure everything
can work on IPv6 and not cause problems for odd setups.

(*) https://bugs.debian.org/979432

3 years agolei q: support --alert=CMD for early MUA users
Eric Wong [Mon, 8 Feb 2021 09:05:12 +0000 (23:05 -1000)]
lei q: support --alert=CMD for early MUA users

For --mua users writing to lock-free -o MFOLDER destinations;
we'll keep -WINCH and send an ASCII terminal bell when results
are complete.  This is intended to let early MUA spawners know
when lei2mail is done writing results.

We'll also support running arbitrary commands.  It may be used
to run play(1) (from SoX), handle pipelines+redirects
(e.g. "/bin/sh -c 'echo search done | wall'") or other commands.

3 years agolei q: SIGWINCH process group with the terminal
Eric Wong [Mon, 8 Feb 2021 09:05:11 +0000 (23:05 -1000)]
lei q: SIGWINCH process group with the terminal

While using utime on the destination Maildir is enough for mutt
to eventually notice new mail, "eventually" isn't good enough.

Send a SIGWINCH to wake mutt (and likely other MUAs)
immediately.  This is more portable than relying on MUAs to
support inotify or EVFILT_VNODE.

3 years agolei_xsearch: quiet Eml warnings from remote mboxrds
Eric Wong [Mon, 8 Feb 2021 09:05:10 +0000 (23:05 -1000)]
lei_xsearch: quiet Eml warnings from remote mboxrds

This will probably cover full Atom/HTML feed generation or any
outputs which are order-dependent, but those aren't prioritized
at the moment.

3 years agolei q: improve remote mboxrd UX + MUA
Eric Wong [Mon, 8 Feb 2021 09:05:09 +0000 (23:05 -1000)]
lei q: improve remote mboxrd UX + MUA

For early MUA spawners using lock-free outputs, we we need to
on the startq pipe to silence progress reporting.  For
--augment users, we can start the MUA even earlier by
creating Maildirs in the pre-augment phase.

To improve progress reporting for non-MUA (or late-MUA)
spawners, we'll no longer blindly append "--compressed" to the
curl(1) command when POST-ing for the gzipped mboxrd.
Furthermore, we'll overload stringify ('""') in LeiCurl to
ensure the empty -d '' string shows up properly.

v2: fix startq waiting with --threads
    mset_progress is never shown with early MUA spawning,
    The plan is to still show progress when augmenting and
    deduping.  This fixes all local search cases.
    A leftover debug bit is dropped, too

3 years agoINSTALL: depend on Text::ParseWords
Eric Wong [Mon, 8 Feb 2021 09:11:03 +0000 (09:11 +0000)]
INSTALL: depend on Text::ParseWords

It's been distributed with Perl since 1994, and we use it for
both -imapd and lei.  It's split out as a separate package in
CentOS 7.x, so we'll depend on it to avoid surprising users
of RPM-based distros.

3 years agolei q: fix arbitrary --mua command handling
Eric Wong [Sun, 7 Feb 2021 10:40:02 +0000 (09:40 -0100)]
lei q: fix arbitrary --mua command handling

Perl doesn't seem to warn for shadowed variables, here :x

3 years agolei import: support Maildirs
Eric Wong [Mon, 8 Feb 2021 06:06:51 +0000 (05:06 -0100)]
lei import: support Maildirs

It seems to be working trivially, though I'm probably
going to split out Maildir reading into a separate
package rather than using LeiToMail.

3 years agohttpd/async: avoid unnecessary on-stack delete
Eric Wong [Sun, 7 Feb 2021 08:52:01 +0000 (08:52 +0000)]
httpd/async: avoid unnecessary on-stack delete

While this doesn't fix a known problem, this was a risky
construct in case somebody uses confess/longmess inside
the user-supplied callback.

cf. commit 0795b0906cc81f40
    ("ds: guard against stack-not-refcounted quirk of Perl 5")

3 years agoimap: avoid unnecessary on-stack delete
Eric Wong [Sun, 7 Feb 2021 08:52:00 +0000 (08:52 +0000)]
imap: avoid unnecessary on-stack delete

None of the Content-Type attributes are long-lived
(and unlikely to be memory intensive).  While these
callsites won't trigger $DB::args segfaults via
confess or longmess, it'll make future code audits
easier.

cf. commit 0795b0906cc81f40
    ("ds: guard against stack-not-refcounted quirk of Perl 5")

3 years agolei: replace --thread with --threads
Eric Wong [Sun, 7 Feb 2021 08:51:56 +0000 (08:51 +0000)]
lei: replace --thread with --threads

Nobody is expected to use long options, but for consistency
with mairix(1), we'll use the pluralized option throughout
(including existing PublicInbox::{Search,SearchView}).

Link: https://public-inbox.org/meta/20210206090119.GA14519@dcvr/
3 years agolei: remove --mua-cmd alias for --mua
Eric Wong [Sun, 7 Feb 2021 08:51:55 +0000 (08:51 +0000)]
lei: remove --mua-cmd alias for --mua

While "mua-cmd" may be more accurate, nobody is expected
to type 4 extra characters.  It's a needless ambiguity
with no precedence or prior art to follow.

Link: https://public-inbox.org/meta/20210206090119.GA14519@dcvr/
3 years agolei: more consistent IPC exit and error handling
Eric Wong [Sun, 7 Feb 2021 08:51:54 +0000 (08:51 +0000)]
lei: more consistent IPC exit and error handling

We're able to propagate $? from wq_workers in a consistent
manner, now.

3 years agoipc: wq_do => wq_io_do
Eric Wong [Sun, 7 Feb 2021 08:51:53 +0000 (08:51 +0000)]
ipc: wq_do => wq_io_do

We will have a ->wq_do that doesn't pass FDs for I/O.

3 years agoRevert "ipc: add support for asynchronous callbacks"
Eric Wong [Sun, 7 Feb 2021 08:51:52 +0000 (08:51 +0000)]
Revert "ipc: add support for asynchronous callbacks"

This reverts commit a7e6a8cd68fb6d700337d8dbc7ee2c65ff3d2fc1.

It turns out to be unworkable in the face of multiple producer
processes, since the lock we make has no effect when calculating
pipe capacity.

3 years agotests: guard setup_public_inboxes for SQLite and Xapian
Eric Wong [Sun, 7 Feb 2021 08:51:51 +0000 (08:51 +0000)]
tests: guard setup_public_inboxes for SQLite and Xapian

This will need some work to before it's generally applicable
to the rest of our code base.

3 years agoxapcmd: avoid potential die surprise in children
Eric Wong [Sun, 7 Feb 2021 08:51:50 +0000 (08:51 +0000)]
xapcmd: avoid potential die surprise in children

Make some notes about sub usage, this may be converted
to use workqueues once the cmsg dependency is dropped.

3 years agoMakefile.PL: depend on IO::Uncompress::Gunzip
Eric Wong [Sun, 7 Feb 2021 08:51:49 +0000 (08:51 +0000)]
Makefile.PL: depend on IO::Uncompress::Gunzip

It's another part of the Perl standard library and rarely
split out from Perl (though we can't depend on that fact).

3 years agoipc: trim down the Storable checks
Eric Wong [Sun, 7 Feb 2021 08:51:48 +0000 (08:51 +0000)]
ipc: trim down the Storable checks

It's distributed with Perl and our Makefile.PL even declares a
dependency on it, just like Encode and all the Compress::*
stuff.

3 years agoipc: do not die inside wq_worker child process
Eric Wong [Sun, 7 Feb 2021 08:51:47 +0000 (08:51 +0000)]
ipc: do not die inside wq_worker child process

die() in a child zips up the stack into the parent, which is
undesirable behavior.  We're going to exit anyways, just warn
and let exit(1) happen due to $@ being set.

3 years agospawn_pp: die more consistently in child
Eric Wong [Sun, 7 Feb 2021 08:51:46 +0000 (08:51 +0000)]
spawn_pp: die more consistently in child

The default $SIG{__DIE__} inside a forked child doesn't actually
do what we want it to do.  We don't want it to zip up the stack
the parent used, but instead want to exit the child process
after warning.

3 years agolei add-external: handle interrupts with --mirror
Eric Wong [Sun, 7 Feb 2021 08:51:45 +0000 (08:51 +0000)]
lei add-external: handle interrupts with --mirror

This also updates lei_xsearch to follow the same pattern for
stopping curl(1) and tail(1) processes it spawns.

3 years agospawn: pi_fork_exec: support "pgid"
Eric Wong [Sun, 7 Feb 2021 08:51:44 +0000 (08:51 +0000)]
spawn: pi_fork_exec: support "pgid"

We'll be using this to allow the "git clone" process hierarchy
to be killed via Ctrl-C.  This also fixes a long-standing bug
in error reporting for the Inline::C version, because we're
actually testing for errors, now!

n.b. strlen(3) is officially async-signal-safe as of
POSIX.1-2016, but I can't think of a reason any previous
implementation prior to that wouldn't be.

3 years agospawn: pi_fork_exec: restore parent sigmask in child
Eric Wong [Sun, 7 Feb 2021 08:51:43 +0000 (08:51 +0000)]
spawn: pi_fork_exec: restore parent sigmask in child

We continue to unblock SIGCHLD unconditionally, but also
any signals not blocked by the parent (wq_worker).

This will allow Ctrl-C (SIGINT) to stop "git clone" and allow
git-clone cleanup to be performed and other long-running
processes when pi_fork_exec supports setpgid(2).  This won't
affect existing daemons on systems with signalfd(2) or
EVFILT_SIGNAL at all, since those run with signals blocked
anyways.

3 years agolei: remove short switch support for curl(1) options
Eric Wong [Sat, 6 Feb 2021 12:18:44 +0000 (12:18 +0000)]
lei: remove short switch support for curl(1) options

In particular, -U and -u switches may conflict with diff(1)
options we may need for "lei show" which will use solver
remotely or locally.

3 years agolei_curl: replace -K/--config with --curl-config
Eric Wong [Sat, 6 Feb 2021 12:18:43 +0000 (12:18 +0000)]
lei_curl: replace -K/--config with --curl-config

Seeing --config in the command-line for lei may mislead users
into thinking we support config file overrides that way.  Rename
the option to --curl-config and drop the short switch for now.

3 years agolei add-external: reject index and remote opts w/o mirror
Eric Wong [Sat, 6 Feb 2021 12:18:42 +0000 (12:18 +0000)]
lei add-external: reject index and remote opts w/o mirror

Option combinations which make no sense should fail
to prevent misunderstandings and avoid surprises.

3 years agolei help: split out into separate file
Eric Wong [Sat, 6 Feb 2021 12:18:41 +0000 (12:18 +0000)]
lei help: split out into separate file

We'll reword and improve formatting with non-breaking spaces
("\xa0") which is only replaced with SP after wrapping.

Some terminology is shortened (e.g. "URL_OR_PATHNAME" => "LOCATION")
to improve formatting.

This also enables completion for -h/--help and lets us
prioritize favored switch names while attempting to
satisfy users relying on muscle memory from other tools.

3 years agolei: add-external --mirror support
Eric Wong [Sat, 6 Feb 2021 12:18:40 +0000 (12:18 +0000)]
lei: add-external --mirror support

This can be useful for users who want to clone and
mirror an existing public-inbox.  This doesn't have
update support, yet, so users will need to run
"git fetch && public-inbox-index" for now.

3 years agoscript/lei: avoid waitpid(-1, ...) to keep tests fast
Eric Wong [Sat, 6 Feb 2021 12:18:39 +0000 (12:18 +0000)]
script/lei: avoid waitpid(-1, ...) to keep tests fast

We only spawn one process to be reaped at the moment.  tests
will run the contents of script/* in the same process if
possible, so any test scripts which spawn -httpd or other
read-only can cause us to stall with waitpid(-1, ...)

3 years agotreewide: replace confess with croak
Eric Wong [Sat, 6 Feb 2021 12:18:38 +0000 (12:18 +0000)]
treewide: replace confess with croak

The PublicInbox::Eml (and previously Email::MIME) use of confess
was the primary (or only) culprit behind the lei2mail segfaults
fixed by commit 0795b0906cc81f40.
("ds: guard against stack-not-refcounted quirk of Perl 5").

We never care about a backtrace when dealing with Eml objects
anyways, so it was just a worthless waste of CPU cycles.

We can also drop confess in a few other places.  Since we only
use Perl and Inline::C, users will never be without source
and can replace s/croak/Carp::confess/ on a per-callsite basis
to help report problems.

It's also possible to use PERL5OPT=-MCarp=verbose in the
environment though still potentially risky.

Link: https://public-inbox.org/meta/20210201082833.3293-1-e@80x24.org/
3 years agotests: split out lei-daemon.t from lei.t
Eric Wong [Sat, 6 Feb 2021 12:18:37 +0000 (12:18 +0000)]
tests: split out lei-daemon.t from lei.t

This makes it easier for hackers to find daemon-specific
tests and forces us to always test both daemon and
oneshot mode.

3 years agot/tests: split out setup_public_inboxes sub
Eric Wong [Sat, 6 Feb 2021 12:18:36 +0000 (12:18 +0000)]
t/tests: split out setup_public_inboxes sub

We'll probably use this in many more existing places
and likely change non-lei tests to use it.

3 years agot/lei-externals: split out into separate test
Eric Wong [Sat, 6 Feb 2021 12:18:35 +0000 (12:18 +0000)]
t/lei-externals: split out into separate test

This is still overloaded with "lei q" stuff, but that's
somewhat inevitable.

3 years agotests: add test_lei wrapper, split out t/lei-import.t
Eric Wong [Sat, 6 Feb 2021 12:18:34 +0000 (12:18 +0000)]
tests: add test_lei wrapper, split out t/lei-import.t

This will make it easier to maintain and test lei going forward,
we need to be testing against existing read-only daemons.  We'll
also save ourselves some boilerplate by exporting all the
Test::More methods directly in TestCommon

We'll start using this by splitting out the latest "lei import"
tests into its own file.

3 years agolei_query: trim curl options
Eric Wong [Sat, 6 Feb 2021 12:18:33 +0000 (12:18 +0000)]
lei_query: trim curl options

Get rid of short options which will or may conflict with
some of our own.  We may switch over to "git -c http.*"
options since we need to run "git clone" and "git fetch"
anyways.

3 years agoinit: lowercase -j for --jobs
Eric Wong [Sat, 6 Feb 2021 12:18:32 +0000 (12:18 +0000)]
init: lowercase -j for --jobs

This is taken from common implementations of make(1)
and only affected people using the command-line help
output.

3 years agolei: abort lei_import worker on client abort
Eric Wong [Sat, 6 Feb 2021 12:18:31 +0000 (12:18 +0000)]
lei: abort lei_import worker on client abort

We'll stuff all the common wq key fields into the
@WQ_KEYS array so it's easier to keep track of what
to kill or reap.

3 years agolei: fix completion of --no-kw / --no-keywords
Eric Wong [Sat, 6 Feb 2021 12:18:30 +0000 (12:18 +0000)]
lei: fix completion of --no-kw / --no-keywords

We did not complete --no-* flags properly when multiple options
are allowed.

3 years agolei: favor "keywords" over "flags", test --no-kw
Eric Wong [Sat, 6 Feb 2021 12:18:29 +0000 (12:18 +0000)]
lei: favor "keywords" over "flags", test --no-kw

JMAP brain says "keywords", IMAP brain says "flags";
JMAP brain wins today.

Since "keywords" is a bit long, support "kw" as a shortcut since
there's no conflict and "kw:" will be our search prefix for
looking up messages by keyword.

3 years agolei_overview: drop unnecessary autoflush call
Eric Wong [Sat, 6 Feb 2021 12:18:28 +0000 (12:18 +0000)]
lei_overview: drop unnecessary autoflush call

This was actually causing xt/lei-sigpipe.t failures,
presumably due to reused/recycled workers with many
externals.

3 years agohttpd/async: set O_NONBLOCK correctly
Eric Wong [Fri, 5 Feb 2021 00:13:54 +0000 (05:13 +0500)]
httpd/async: set O_NONBLOCK correctly

While Perl tie is nice for some things, getting
IO::Handle->blocking to work transparently with it doesn't
seem possible at the moment.

Add some examples in t/spawn.t for future hackers.

Fixes: 22e51bd9da476fa9 ("qspawn: switch to ProcessPipe via popen_rd")
3 years agolei import: initial implementation
Eric Wong [Thu, 4 Feb 2021 09:59:30 +0000 (00:59 -0900)]
lei import: initial implementation

Only tested with .eml files so far, but Maildir + IMAP
will be supported.

3 years agolei_xsearch: drop unused imports
Eric Wong [Thu, 4 Feb 2021 09:59:29 +0000 (00:59 -0900)]
lei_xsearch: drop unused imports

Reaping is handled by the parent PublicInbox::IPC, and we
have no business using PublicInbox::Import since LeiXSearch
won't write to git directly (it will write via LeiStore).

3 years agolei_query: remove uneeded dwaitpid import
Eric Wong [Thu, 4 Feb 2021 09:59:28 +0000 (00:59 -0900)]
lei_query: remove uneeded dwaitpid import

All process management is handled elsewhere.

3 years agolei q: eliminate $not_done temporary git dir hack
Eric Wong [Thu, 4 Feb 2021 09:59:27 +0000 (00:59 -0900)]
lei q: eliminate $not_done temporary git dir hack

Another step towards simplifying lei internals.

None of our current uses of ->wq_do involve FD passing, and the
plan is only rely on FD passing between lei-daemon and lei(1).
Internally, it ought to be possible for lei-daemon internal bits
to be ordered properly to not need FD passing.

3 years agoeml: handle warning ignores for lei
Eric Wong [Thu, 4 Feb 2021 09:59:26 +0000 (00:59 -0900)]
eml: handle warning ignores for lei

There's nothing we can do about bad emails in our search
results, so quiet things down and don't fight the MUA for
the terminal.

3 years agolei q: reinstate early MUA spawn for Maildir
Eric Wong [Thu, 4 Feb 2021 09:59:25 +0000 (00:59 -0900)]
lei q: reinstate early MUA spawn for Maildir

Once all files are written, we can use utime() to poke Maildirs
to wake up MUAs that fail to account for nanosecond timestamps
resolution.

3 years agolei q: only start pager if output is to stdout
Eric Wong [Thu, 4 Feb 2021 09:59:24 +0000 (00:59 -0900)]
lei q: only start pager if output is to stdout

No need to be starting a pager if we're writing to a regular file.

3 years agolei q: reorder internals to reduce FD passing
Eric Wong [Thu, 4 Feb 2021 09:59:23 +0000 (00:59 -0900)]
lei q: reorder internals to reduce FD passing

While FD passing is critical for script/lei <=> lei-daemon,
lei-daemon doesn't need to use it internally if FDs are
created in the proper order before forking.

3 years agoipc: localize fields assignment
Eric Wong [Thu, 4 Feb 2021 09:59:22 +0000 (00:59 -0900)]
ipc: localize fields assignment

We don't want circular references giving surprising behavior
during worker exit.

3 years agolei q: delay worker spawn
Eric Wong [Thu, 4 Feb 2021 09:59:21 +0000 (00:59 -0900)]
lei q: delay worker spawn

Now that --stdin support is sorted, we can delay spawning
workers until we know the query is ready-to-run.

3 years agot/lei: skip "lei q" tests on missing dependencies
Eric Wong [Thu, 4 Feb 2021 02:10:07 +0000 (02:10 +0000)]
t/lei: skip "lei q" tests on missing dependencies

... for now.  It's probably possible to just use send()
recv() without CMSG_* eventually.

3 years agopkt_op: do not exit subroutine via "next"
Eric Wong [Thu, 4 Feb 2021 02:06:54 +0000 (02:06 +0000)]
pkt_op: do not exit subroutine via "next"

"next" apparently doesn't work in "do {} while" loops,
so just use "while" as it makes no difference, here.

3 years agowwwaltid: add missing word to instructions
Kyle Meyer [Thu, 4 Feb 2021 02:54:46 +0000 (21:54 -0500)]
wwwaltid: add missing word to instructions

3 years agowww: call curl with -d '' in the altid instructions
Kyle Meyer [Thu, 4 Feb 2021 02:54:45 +0000 (21:54 -0500)]
www: call curl with -d '' in the altid instructions

Nginx doesn't appear to be happy with just -XPOST, so use -d '' to
avoid potential confusion about why the instructions aren't working.

cf. commit 533e1234bc03a1ca8754d249aa8c2ce157e26780
    (lei_xsearch: use curl -d '' for nginx compatibility, 2021-01-24)

3 years agotests: guard against missing DBD::SQLite
Eric Wong [Wed, 3 Feb 2021 21:51:44 +0000 (15:51 -0600)]
tests: guard against missing DBD::SQLite

The features we use for SharedKV could probably be implemented
with GDBM_File or SDBM_File, but that doesn't seem worth it at
the moment since we depend on SQLite elsewhere.

3 years agodoc: update dependencies (+Storable, Data::Dumper)
Eric Wong [Wed, 3 Feb 2021 21:51:43 +0000 (15:51 -0600)]
doc: update dependencies (+Storable, Data::Dumper)

The new IPC stuff doesn't work without Storable or Sereal.
Storable is part of the standard library since Perl 5.8, so
we'll put a hard dependency on it for distros that package
it separately.

Data::Dumper is also part of the standard library, and
PublicInbox::MboxReader uses it, and it's frequently useful
during development.

We'll also trim down INSTALL for standard library modules so
it's hopefully less daunting for new users.

Development dependencies are noted in HACKING, now.

Email::MIME is only used for maintainer tests, so it's only
documented in HACKING.

3 years agospawn: merge common C code together
Eric Wong [Wed, 3 Feb 2021 21:51:42 +0000 (15:51 -0600)]
spawn: merge common C code together

There'll probably be more things which work on both GNU and
*BSD systems which we don't need separate strings for.

3 years agoHACKING: use "just-ahead-of-time" to describe Inline::C
Eric Wong [Wed, 3 Feb 2021 21:51:41 +0000 (15:51 -0600)]
HACKING: use "just-ahead-of-time" to describe Inline::C

Inline::C works during module load time, so "just-ahead-of-time"
is a better description of it than "just-in-time".  I don't
think "JAOT" is a well-known enough acronym, so it's worth
spelling it out.

3 years agolei q: support reading queries from stdin
Eric Wong [Wed, 3 Feb 2021 08:11:43 +0000 (22:11 -1000)]
lei q: support reading queries from stdin

This will be useful on shared machines when a user doesn't want
search queries visible to other users looking at the ps(1)
output or similar.

3 years agolei: use sleep(1) loop for infinite sleep
Eric Wong [Wed, 3 Feb 2021 08:11:42 +0000 (22:11 -1000)]
lei: use sleep(1) loop for infinite sleep

Perl may internally race and miss signals due to a lack of
self-pipe / eventfd / signalfd / EVFILT_SIGNAL usage.  While our
event loop paths avoid these problems by using signalfd or
EVFILT_SIGNAL, thse sleep() calls are not within the event loop.

3 years agolei add-external: completion for existing URL basenames
Eric Wong [Wed, 3 Feb 2021 08:11:41 +0000 (22:11 -1000)]
lei add-external: completion for existing URL basenames

Given the presence of one external on a certain host or prefix
path, it's logical other inboxes would share a common prefix.
For bash users, attempt to complete that using the "-o nospace"
option of bash

3 years agolei: help starts pager
Eric Wong [Wed, 3 Feb 2021 08:11:40 +0000 (22:11 -1000)]
lei: help starts pager

Because some commands have many options which take up
multiple screens.

3 years agolei: complete basenames for include|exclude|only
Eric Wong [Wed, 3 Feb 2021 08:11:39 +0000 (22:11 -1000)]
lei: complete basenames for include|exclude|only

This will make it even easier for RSI-afflicted users to use,
since many externals may share a common prefix.

3 years agolei q: -I/--exclude/--only support globs and basenames
Eric Wong [Wed, 3 Feb 2021 08:11:38 +0000 (22:11 -1000)]
lei q: -I/--exclude/--only support globs and basenames

We can do basename matching when it's unambiguous.  Since '*?[]'
characters are rare in URLs and pathnames, we'll do glob
matching by default to support a (curl-inspired) --globoff/-g
option to disable globbing.

And fix --exclude while we're at it

3 years agolei: propagate curl errors, improve internal consistency
Eric Wong [Wed, 3 Feb 2021 08:11:37 +0000 (22:11 -1000)]
lei: propagate curl errors, improve internal consistency

IO::Uncompress::Gunzip seems to be losing $? when closing
PublicInbox::ProcessPipe.  To workaround this, do a synchronous
waitpid ourselves to force proper $? reporting update tests to
use the new --only feature for testing invalid URLs.

This improves internal code consistency by having {pkt_op}
parse the same ASCII-only protocol script/lei understands.

We no longer pass {sock} to worker processes at all,
further reducing FD pressure on per-user limits.

3 years agolei: err: avoid uninitialized variable warnings
Eric Wong [Wed, 3 Feb 2021 08:11:36 +0000 (22:11 -1000)]
lei: err: avoid uninitialized variable warnings