]> Sergey Matveev's repositories - public-inbox.git/log
public-inbox.git
3 years agolei: completion: fix filename completion
Eric Wong [Tue, 5 Jan 2021 09:04:34 +0000 (09:04 +0000)]
lei: completion: fix filename completion

"-o default" is what we want from "complete", "-o filename" just
tells readline the result from the "_lei" function might be a
filename and quote appropriately.

3 years agoimap: fix uninitialized var on MSN search miss
Eric Wong [Tue, 5 Jan 2021 18:19:48 +0000 (18:19 +0000)]
imap: fix uninitialized var on MSN search miss

It seems only triggered by bots trying to steal information.

3 years agolei: improve idempotent "init" error message
Eric Wong [Mon, 4 Jan 2021 04:16:24 +0000 (04:16 +0000)]
lei: improve idempotent "init" error message

Showing "leistore.dir= already initialized" because $cur is
undefined isn't useful.

3 years agolei: fix opt_dash to pass non-dash args to @argv
Eric Wong [Mon, 4 Jan 2021 04:16:23 +0000 (04:16 +0000)]
lei: fix opt_dash to pass non-dash args to @argv

The special "<>" handling in Getopt::Long actually invokes the
callback for every single command-line arg, not just those
prefixed by "-".  This will let us pass arbitrary non-dashed
words for search queries so users can type queries naturally
without quoting (unless they want phrase search).

3 years agolei: prefer IO::FDPass over our Inline::C recv_3fds
Eric Wong [Sun, 3 Jan 2021 20:58:29 +0000 (20:58 +0000)]
lei: prefer IO::FDPass over our Inline::C recv_3fds

While our recv_3fds() implementation is more efficient
syscall-wise, loading Inline takes nearly 50ms on my machine
even after Inline::C memoizes the build.  The current ~20ms in
the fast path is barely acceptable to me, and 50ms would be
unusable.

Eventually, script/lei may invoke tcc(1) or cc(1) directly in
the fast path, but it needs @INC for the slow path, at least.

We'll encode the number of FDs into the socket name allow
parallel installations, for now.

3 years agosearchidxshard: use add_xapian directly for v2
Eric Wong [Sun, 3 Jan 2021 02:06:17 +0000 (02:06 +0000)]
searchidxshard: use add_xapian directly for v2

We can more clearly distinguish between v1 and v2-only code
paths this way, and may be able to save a few cycles this way.

3 years agoipc: switch to one-way pipes
Eric Wong [Sun, 3 Jan 2021 02:06:16 +0000 (02:06 +0000)]
ipc: switch to one-way pipes

This fixes a performance regression in multi-process v2 indexing
due to the switch to PublicInbox::IPC.  While Unix sockets are
fewer FDs to manage, pipes allow unprivileged processes to use
larger buffers (up to 1M) on out-of-the-box Linux instances.

A larger buffer via F_SETPIPE_SZ afforded by pipes was proven
valuable during v2 development in 2018 and continues to be
valuable when we get significant amounts of one-way traffic from
the producer parent to worker children.

Compression may be an option for systems without F_SETPIPE_SZ;
but it increases CPU usage with no memory bandwidth savings on
hosts where larger buffers are available.

3 years agouse Eml (or MIME) objects for all indexing paths
Eric Wong [Sun, 3 Jan 2021 02:06:15 +0000 (02:06 +0000)]
use Eml (or MIME) objects for all indexing paths

We don't need to be keeping the raw message around after it hits
git.  Shard work now relies on Storable (or Sereal) and all of
the indexing code relies on the Email::MIME-like API of Eml to
access interesting parts of the message.

Similarly, smsg->{raw_bytes} is no longer carried around and we
do the CRLF adjustment when setting smsg->{bytes}.

There's also a small simplification to t/import.t while
we're in the area to use xqx instead of spawn/popen_rd.

3 years agosearchidxshard: replace index_raw with index_eml
Eric Wong [Sun, 3 Jan 2021 02:06:14 +0000 (02:06 +0000)]
searchidxshard: replace index_raw with index_eml

Since Storable and Sereal are designed for lossless
serialization, we'll just pass $eml objects to whatever process
is running SearchIdx.

3 years agosearchidxshard: IPC conversion, part 2
Eric Wong [Sun, 3 Jan 2021 02:06:13 +0000 (02:06 +0000)]
searchidxshard: IPC conversion, part 2

We can remove some now-pointless wrapper functions by using
->ipc_do in even more places.

3 years agosearchidxshard: use PublicInbox::IPC to kill lots of code
Eric Wong [Sun, 3 Jan 2021 02:06:12 +0000 (02:06 +0000)]
searchidxshard: use PublicInbox::IPC to kill lots of code

It's nice to prove the new code works by swapping it into
the current V2Writable / SearchIdxShard packages.  This is
only the first step for the core bits, and we'll be able
to delete more code in a subsequent patch.

3 years agoipc: some documentation comments
Eric Wong [Sun, 3 Jan 2021 02:06:11 +0000 (02:06 +0000)]
ipc: some documentation comments

Fix some comments and add some short summary descriptions to
hopefully make things easier-to-follow.

3 years agogcf2client: split out request API from regular git
Eric Wong [Sun, 3 Jan 2021 02:12:06 +0000 (12:12 -1400)]
gcf2client: split out request API from regular git

While Gcf2Client is designed to mimic what git-cat-file writes
to stdout, its request format is different to support requests
with a git repository path included.

We'll highlight the distinction and make the GitAsyncCat support
code easier-to-follow as a result.

Since Gcf2Client relies on DS, we can rely on DS-specific code
here, too, and use a single Unix socket instead of separate
input and output pipes, reducing memory overhead in both users
and kernel space.  Due to the interactive nature of requests and
responses, the buffer size limitations of Unix sockets on Linux
seems inconsequential here (just like it is for existing "git
cat-file --batch" use).

3 years agolei: fix output race in client/daemon mode
Eric Wong [Sun, 3 Jan 2021 11:24:51 +0000 (11:24 +0000)]
lei: fix output race in client/daemon mode

The daemon needs to flush stdout before disconnecting or killing
clients, otherwise they may reread empty data on redirected
outputs.  We also don't want to unbuffer stdout too early in
case we have lots of small chunks of data to output.

The received ($self->{2}) will always have autoflush, matching normal
STDERR behavior.

3 years agosend and receive all 3 FDs at once
Eric Wong [Sun, 3 Jan 2021 11:24:50 +0000 (11:24 +0000)]
send and receive all 3 FDs at once

We'll always be transferring stdin, stdout, and stderr together
for lei.  Perhaps I lack imagination or foresight, but I can't
think of a reason to send more or less FDs.

3 years agospawn: support send_fd+recv_fd w/o IO::FDPass
Eric Wong [Sun, 3 Jan 2021 09:48:42 +0000 (09:48 +0000)]
spawn: support send_fd+recv_fd w/o IO::FDPass

IO::FDPass may be an extra installation burden I don't want to
impose on users.  We only support Linux and *BSDs, however.

3 years agotestcommon: prepare_redirects: fix error message
Eric Wong [Sun, 3 Jan 2021 09:48:41 +0000 (09:48 +0000)]
testcommon: prepare_redirects: fix error message

I never hit these die() calls, but noticed it while debugging
another problem on FreeBSD.

3 years agot/lei: use $lei->() callback wrapper
Eric Wong [Sun, 3 Jan 2021 09:48:40 +0000 (09:48 +0000)]
t/lei: use $lei->() callback wrapper

This shortens the test and should make it easier to debug and
add new tests.

3 years agoqspawn: switch to ProcessPipe via popen_rd
Eric Wong [Sat, 2 Jan 2021 09:13:44 +0000 (19:13 -1400)]
qspawn: switch to ProcessPipe via popen_rd

ProcessPipe has a built-in mechanism to prevent siblings from
reaping children.

3 years agogit: manifest_entry: use ProcessPipe via popen_rd
Eric Wong [Sat, 2 Jan 2021 09:13:43 +0000 (19:13 -1400)]
git: manifest_entry: use ProcessPipe via popen_rd

Only saves us one line of code, but that's better than nothing.

3 years agoimport: switch to using ProcessPipe
Eric Wong [Sat, 2 Jan 2021 09:13:42 +0000 (19:13 -1400)]
import: switch to using ProcessPipe

This saves us a few lines of code, but also prevents misreaping
by sibling processes.

3 years agogit: qx: waitpid synchronously via ProcessPipe->CLOSE
Eric Wong [Sat, 2 Jan 2021 09:13:41 +0000 (19:13 -1400)]
git: qx: waitpid synchronously via ProcessPipe->CLOSE

If we're using ->qx, we're operating synchronously anyways,
so there's little point in relying on the event loop for
waitpid.

3 years agoprocesspipe: lazy-require PublicInbox::DS for dwaitpid
Eric Wong [Sat, 2 Jan 2021 09:13:40 +0000 (19:13 -1400)]
processpipe: lazy-require PublicInbox::DS for dwaitpid

This saves over 20ms with scripts that only use PublicInbox::Spawn.

3 years agoprocesspipe: allow synchronous close to set $?
Eric Wong [Sat, 2 Jan 2021 09:13:39 +0000 (19:13 -1400)]
processpipe: allow synchronous close to set $?

To get rid of the ugly $PublicInbox::DS::in_loop localization
in MboxReader, we'll distinguish between ->CLOSE and ->DESTROY
with ProcessPipe.

If we end up closing via ->DESTROY, we'll assume the caller will
want to deal with $? asynchronously via the event loop (or not
even care about $?).

If we hit ->CLOSE directly, we'll assume the caller called
close() and wants to check $? synchronously.

Note: wantarray doesn't seem to propagate into tied methods,
otherwise I'd be relying on that.

3 years agolei_store: alternative unconfigured "git var" workaround
Eric Wong [Sat, 2 Jan 2021 08:32:04 +0000 (08:32 +0000)]
lei_store: alternative unconfigured "git var" workaround

While the changes to git->qx/git->popen from commit 171a9c24022ad7ef
will be useful for the lei daemon, hiding git error messages from
actual users is probably wrong and we'll just localize GIT_*
vars for testing.

3 years agotreewide: reduce load_xapian* callsites
Eric Wong [Fri, 1 Jan 2021 05:47:50 +0000 (17:47 -1200)]
treewide: reduce load_xapian* callsites

Hopefully this will make it easier to spot dependency
bugs in the future.

3 years agoimport: unset GIT_CONFIG with `git config --global'
Eric Wong [Fri, 1 Jan 2021 05:47:49 +0000 (17:47 -1200)]
import: unset GIT_CONFIG with `git config --global'

GIT_CONFIG is set by -convert, and user may have it set
for other reasons.  In either case, it conflicts with
any any attempt to use `git config --global` so we have
to unset it.

This fixes t/multi-mid.t under TEST_RUN_MODE=0

3 years agot/lei: fix TEST_RUN_MODE=0, simplify oneshot fallback
Eric Wong [Fri, 1 Jan 2021 05:47:48 +0000 (17:47 -1200)]
t/lei: fix TEST_RUN_MODE=0, simplify oneshot fallback

We need to use an absolute path after chdir in run modes
where scripts aren't loaded into in-memory subs.

The oneshot test was also failing under TEST_RUN_MODE=0 due to
no "lei-oneshot" command existing on the FS.  So we force a
socket failure by making XDG_RUNTIME_DIR too large to fit into
the 108-byte .sun_path field of "struct sockaddr_un".  This
even lets us simplify lei-oneshot significantly.

3 years agosearch: do not use $QP_FLAGS until Xapian is loaded
Eric Wong [Fri, 1 Jan 2021 05:47:47 +0000 (17:47 -1200)]
search: do not use $QP_FLAGS until Xapian is loaded

The default $QP_FLAGS won't be set until after Xapian is
loaded, duh...

This fixes t/imapd.t with TEST_RUN_MODE=0

3 years agolei_store: quiet down "git var" failures
Eric Wong [Fri, 1 Jan 2021 09:20:59 +0000 (19:20 -1400)]
lei_store: quiet down "git var" failures

$git->qx and $git->popen now $env and $opt for redirects
like lower-level popen_rd.  This may be beneficial in other
places.

3 years agoupdate copyrights for 2021
Eric Wong [Fri, 1 Jan 2021 05:13:18 +0000 (05:13 +0000)]
update copyrights for 2021

Using "make update-copyrights" after setting GNULIB_PATH in my
config.mak

3 years agoMakefile.PL: add update-copyrights target
Eric Wong [Fri, 1 Jan 2021 05:10:57 +0000 (05:10 +0000)]
Makefile.PL: add update-copyrights target

It might save me a few cycles every year to not have to
scroll through git history to see how it's run.

3 years agoon_destroy: support PID owner guard
Eric Wong [Thu, 31 Dec 2020 13:51:54 +0000 (13:51 +0000)]
on_destroy: support PID owner guard

Since we'll be forking for Xapian indexing and maybe
other places, having a simple guard in place to ensure
OnDestroy doesn't unexpectedly unlink files or similar
is a safer option.

3 years agods: clobber $in_loop first at reset
Eric Wong [Thu, 31 Dec 2020 13:51:53 +0000 (13:51 +0000)]
ds: clobber $in_loop first at reset

This may help ensure DESTROY callbacks will see in_loop
before the others.

3 years agoavoid calling waitpid from children in DESTROY
Eric Wong [Thu, 31 Dec 2020 13:51:52 +0000 (13:51 +0000)]
avoid calling waitpid from children in DESTROY

Objects with DESTROY callbacks get propagated to children, so we
must be careful to not invoke waitpid from children on their
sibling processes.  Only parents (and their parents...) can reap
child processes.

3 years agolei: avoid Spawn package when starting daemon
Eric Wong [Thu, 31 Dec 2020 13:51:51 +0000 (13:51 +0000)]
lei: avoid Spawn package when starting daemon

Spawn was designed to speed up process spawning inside
long-lived daemons with largish memory usage.  It does not help
for short-lived scripts which only exist to start and connect to
a daemon.

This change actually speeds up initial lei startup from
~190ms to ~140ms(!).  Normal usage once the daemon is running
is unaffected, at <20ms for help text.

While we're in the area, simplify Cwd error message generation,
too.

3 years agosyscall: SFD_NONBLOCK can be a constant, again
Eric Wong [Thu, 31 Dec 2020 13:51:50 +0000 (13:51 +0000)]
syscall: SFD_NONBLOCK can be a constant, again

Since Perl exposes O_NONBLOCK as a constant, we can safely make
SFD_NONBLOCK a constant, too.  This is not the case for
SFD_CLOEXEC, since O_CLOEXEC is not exposed by Perl despite
being used internally in the interpreter.

3 years agouse PublicInbox::DS for dwaitpid
Eric Wong [Thu, 31 Dec 2020 13:51:49 +0000 (13:51 +0000)]
use PublicInbox::DS for dwaitpid

This simplifies our code and provides a more consistent API for
error handling.  PublicInbox::DS can be loaded nowadays on all
*BSDs and Linux distros easily without extra packages to
install.

The downside is possibly increased startup time, but it's
probably not as a big problem with lei being a daemon
(and -mda possibly following suite).

3 years agot/ipc.t: test for references via `die'
Eric Wong [Thu, 31 Dec 2020 13:51:48 +0000 (13:51 +0000)]
t/ipc.t: test for references via `die'

We'll probably start using references as exceptions in
some places for more exact matching.

3 years agosearchidxshard: call DS->Reset at worker start
Eric Wong [Thu, 31 Dec 2020 13:51:47 +0000 (13:51 +0000)]
searchidxshard: call DS->Reset at worker start

The daemon for the local email interface will be inside
the DS->EventLoop.  -watch currently doesn't trigger this
bug since it doesn't enable parallelism, but it may in
the future.

3 years agolei_to_mail: open FIFOs O_WRONLY so we block
Eric Wong [Thu, 31 Dec 2020 13:51:46 +0000 (13:51 +0000)]
lei_to_mail: open FIFOs O_WRONLY so we block

Opening a FIFO with O_RDWR always succeeds on Linux, which
cause the cat(1) process invoked by t/lei_to_mail.t to get
stuck.  Furthermore O_APPEND makes no sense on FIFOs and
perhaps there's some kernel out there which will reject it.

3 years agogcf2client: reap process on DESTROY
Eric Wong [Thu, 31 Dec 2020 13:51:45 +0000 (13:51 +0000)]
gcf2client: reap process on DESTROY

We don't want to leave Xapcmd waitpid(-1, ...) call to hit it.

3 years agot/run: avoid uninitialized var on incomplete test
Eric Wong [Thu, 31 Dec 2020 13:51:44 +0000 (13:51 +0000)]
t/run: avoid uninitialized var on incomplete test

Diagnosing an occasional FIFO failure in t/lei_to_mail.t...

3 years agoinit: remove embedded UnlinkMe package
Eric Wong [Thu, 31 Dec 2020 13:51:43 +0000 (13:51 +0000)]
init: remove embedded UnlinkMe package

PublicInbox::OnDestroy can do the same thing

3 years agospawn: move run_die here from PublicInbox::Import
Eric Wong [Thu, 31 Dec 2020 13:51:42 +0000 (13:51 +0000)]
spawn: move run_die here from PublicInbox::Import

It seems like a more logical place for it, but we'll favor the
newly-added xsys_e() in tests for BAIL_OUT use.

3 years agolei: add --mfolder as an --output alias
Eric Wong [Thu, 31 Dec 2020 13:51:41 +0000 (13:51 +0000)]
lei: add --mfolder as an --output alias

This will be helpful for mairix users.

3 years agolei_to_mail: unlink mboxes if not augmenting
Eric Wong [Thu, 31 Dec 2020 13:51:40 +0000 (13:51 +0000)]
lei_to_mail: unlink mboxes if not augmenting

This matches mairix(1) behavior and may be safer if there's
concurrent readers on the existing mbox, especially since
we don't do currently implement mbox locking (nor does mairix).

3 years agoipc: use shutdown(2), base atfork* callback
Eric Wong [Thu, 31 Dec 2020 13:51:39 +0000 (13:51 +0000)]
ipc: use shutdown(2), base atfork* callback

shutdown(2) on a socket can be preferable if there's multiple
forked processes writing to a single worker and we really want
to shut things down ASAP.

It may also be good to provide an ipc_worker_exit method which
subclasses can override if needed for graceful shutdown.  But we
won't need equivalents to atexit(3) since we can rely on DESTROY
handlers given this is Perl5.

3 years agolei_store: handle messages without Message-ID at all
Eric Wong [Thu, 31 Dec 2020 13:51:38 +0000 (13:51 +0000)]
lei_store: handle messages without Message-ID at all

For personal mail, unsent drafts messages are a common source of
messages without Message-IDs.

3 years agomid: hoist out mids_in sub
Eric Wong [Thu, 31 Dec 2020 13:51:37 +0000 (13:51 +0000)]
mid: hoist out mids_in sub

We'll be using it for Resent-Message-ID with lei, and possibly
other places.

3 years agomid: use defined-or with `push' for uniqueness check
Eric Wong [Thu, 31 Dec 2020 13:51:36 +0000 (13:51 +0000)]
mid: use defined-or with `push' for uniqueness check

As shown recently in commit a05445fb400108e60ede7d377cf3b26a0392eb24
("config: config_fh_parse: micro-optimize"), the relying on
the return value of `push' and defined-or operators can avoid
modifying a the hash value scalar with an increment.

3 years agolei: rename "extinbox" => "external"
Eric Wong [Thu, 31 Dec 2020 13:51:35 +0000 (13:51 +0000)]
lei: rename "extinbox" => "external"

The words "extinbox" and "extindex" are too close and easy to
confuse with the other.  Rename "extinbox" to "external", since
these could be IMAP, JMAP or other non-public-inbox search APIs.

Link: https://public-inbox.org/meta/20201226112649.GB6226@dcvr/
3 years agolei_store: add ->set_eml, ->add_eml can return smsg
Eric Wong [Thu, 31 Dec 2020 13:51:34 +0000 (13:51 +0000)]
lei_store: add ->set_eml, ->add_eml can return smsg

Add a ->set_eml method which can be a useful fire-and-forget
way of either adding new files to store OR setting keywords
on them.

When seeing brand-new messages, add_eml can afford to return
more information in the smsg instead of just the OID.

3 years agoipc: support Sereal
Eric Wong [Thu, 31 Dec 2020 13:51:33 +0000 (13:51 +0000)]
ipc: support Sereal

Some testing will be needed to see if it's worth the code
and maintenance overhead, but it seems easy-enough to get
working.

3 years agoipc: generic IPC dispatch based on Storable
Eric Wong [Thu, 31 Dec 2020 13:51:32 +0000 (13:51 +0000)]
ipc: generic IPC dispatch based on Storable

I intend to use this with LeiStore when importing from multiple
slow sources at once (e.g. curl, IMAP, etc).  This is because
over.sqlite3 can only have a single writer, and we'll have
several slow readers running in parallel.

Watch and SearchIdxShard should also be able to use this code
in the future, but this will be proven with LeiStore, first.

3 years agolei_to_mail: support Maildir, fix+test --augment
Eric Wong [Thu, 31 Dec 2020 13:51:31 +0000 (13:51 +0000)]
lei_to_mail: support Maildir, fix+test --augment

Maildir should be plenty fine for short-lived output folders.

3 years agolei_to_mail: support for non-seekable outputs
Eric Wong [Thu, 31 Dec 2020 13:51:30 +0000 (13:51 +0000)]
lei_to_mail: support for non-seekable outputs

Users may wish to pipe output to "git am", "spamc",
or similar, so we need to support those cases and
not bail out on lseek(2) or ftruncate(2) failures.

3 years agolei_to_mail: lazy-require LeiDedupe
Eric Wong [Thu, 31 Dec 2020 13:51:29 +0000 (13:51 +0000)]
lei_to_mail: lazy-require LeiDedupe

LeiDedupe requires SQLite, so we may want to be able to test
writing mail without DBI or SQLite down the line.

3 years agolei: implement various deduplication strategies
Eric Wong [Thu, 31 Dec 2020 13:51:28 +0000 (13:51 +0000)]
lei: implement various deduplication strategies

For writing mboxes and Maildirs, users may wish to use
stricter or looser deduplication strategies.  This
gives them more control.

3 years agolei_to_mail: start --augment, dedupe, bz2 and xz
Eric Wong [Thu, 31 Dec 2020 13:51:27 +0000 (13:51 +0000)]
lei_to_mail: start --augment, dedupe, bz2 and xz

--augment will match the mairix(1) option of the same
name to augment existing search results.  We'll need
to implement deduplication for a better user experience.

mutt ships with compressed mbox support for bz2 and xz,
at least, so we'll support those out-of-the-box.

3 years agomboxreader: new class for reading various mbox formats
Eric Wong [Thu, 31 Dec 2020 13:51:26 +0000 (13:51 +0000)]
mboxreader: new class for reading various mbox formats

This is only lightly-tested against stuff LeiToMail generates
and will need real-world tests to validate.

3 years agolei_to_mail: start atomic and compressed mbox writing
Eric Wong [Thu, 31 Dec 2020 13:51:25 +0000 (13:51 +0000)]
lei_to_mail: start atomic and compressed mbox writing

We'll allow using multiple workers to write to a single
mbox (which could be compressed).  This is can be done
safely with O_APPEND + syswrite for uncompressed files,
and using a lock when piping to pigz/gzip/bzip2/xz.

3 years agosharedkv: split out index_values
Eric Wong [Thu, 31 Dec 2020 13:51:24 +0000 (13:51 +0000)]
sharedkv: split out index_values

In most cases, we won't need to index by value, so
don't waste cycles or space on it.

3 years agosharedkv: fork()-friendly key-value store
Eric Wong [Thu, 31 Dec 2020 13:51:23 +0000 (13:51 +0000)]
sharedkv: fork()-friendly key-value store

This is intended for maintaining Maildir states, mbox message
deduplication, but may be useful for other purposes...

3 years agolei_to_mail: initial implementation for writing mbox formats
Eric Wong [Thu, 31 Dec 2020 13:51:22 +0000 (13:51 +0000)]
lei_to_mail: initial implementation for writing mbox formats

No Maildir, support, yet, but it'll come.

3 years agorevert "lei_store: use per-machine refname as git HEAD"
Eric Wong [Thu, 31 Dec 2020 13:51:21 +0000 (13:51 +0000)]
revert "lei_store: use per-machine refname as git HEAD"

In retrospect, per-machine HEADs was a bad idea because users
of removable storage would be thrown off when moving storage
between different machines.

This is only a partial revert, the Import::init_bare change to
support alternate head names still exists because we may use it
for other reasons.

3 years agolei_store: use per-machine refname as git HEAD
Eric Wong [Thu, 31 Dec 2020 13:51:20 +0000 (13:51 +0000)]
lei_store: use per-machine refname as git HEAD

It may be helpful to identify the source of messages
and perhaps avoid conflicting history.

On the other hand, this may be a terrible idea for users who
move portable storage (e.g. USB sticks) across computers...

3 years agoimport: respect init.defaultBranch
Eric Wong [Thu, 31 Dec 2020 13:51:19 +0000 (13:51 +0000)]
import: respect init.defaultBranch

This matches git v2.28.0+ behavior in case users prefer
a different name.

3 years agoMerge remote-tracking branch 'origin/lei' into eidx
Eric Wong [Fri, 1 Jan 2021 04:58:39 +0000 (04:58 +0000)]
Merge remote-tracking branch 'origin/lei' into eidx

* origin/lei: (28 commits)
  lei: rename proposed "query" command to "q", add JSON output
  lei_xsearch: cross-(inbox|extindex) search
  lei: extinbox: start implementing in config file
  lei: revise output routines
  lei: support for -$DIGIT and -$SIG CLI switches
  build: add lei.sh + "make symlink-install" target
  lei: start working on bash completion
  lei: drop $SIG{__DIE__}, add oneshot fallbacks
  lei: restore default __DIE__ handler for event loop
  on_destroy: generic localized END
  lei_store: keyword extraction from mbox and Maildir
  lei_store: relax GIT_COMMITTER_IDENT check
  lei: micro-optimize startup time
  lei: rename $client => $self and bless
  lei: help: show actual paths being operated on
  lei: support pass-through for `lei config'
  rename LeiDaemon package to PublicInbox::LEI
  search: simplify initialization, add ->xdb_shards_flat
  lei_store: simplify git_epoch_max, slightly
  lei: support `daemon-env' for modifying long-lived env
  ...

3 years agoMerge tag 'v1.6.1' into eidx
Eric Wong [Fri, 1 Jan 2021 04:51:46 +0000 (04:51 +0000)]
Merge tag 'v1.6.1' into eidx

public-inbox 1.6.1 - minor bugfix release

* tag 'v1.6.1': (31 commits)
  public-inbox 1.6.1 - minor bugfix release
  import: drop X-Status in addition to Status
  eml: fix undefined vars on <Perl 5.28
  t/config: test --get-urlmatch for git <2.26
  inboxidle: avoid needless syscalls on refresh
  inboxidle: clue users into resolving ENOSPC from inotify
  inbox: name variable for values loop iterator
  public-inbox-v[12]-format.pod: make lexgrog happy
  manifest.js.gz: fix per-inbox /$INBOX/manifest.js.gz
  Fix manpage section of perl module documentation
  t/psgi_v2: ignore warnings on missing P::M::ReverseProxy
  daemon: support --daemonize without Net::Server::Daemonize
  doc: v2-format: drop repeated word
  over: ensure old, merged {tid} is really gone
  wwwattach: prevent deep-linking via Referer match
  t/eml.t: workaround newer Email::MIME* behavior
  nntp: attempt RFC 5536 3.1.5-conformant Path: headers
  nntp: delimit Newsgroup: header with commas
  tls: epollbit: account for miscellaneous OpenSSL errors
  scripts/dupe-finder: restore $dbh variable
  ...

3 years agopublic-inbox 1.6.1 - minor bugfix release v1.6.1
Eric Wong [Thu, 31 Dec 2020 20:15:28 +0000 (20:15 +0000)]
public-inbox 1.6.1 - minor bugfix release

3 years agoMerge remote-tracking branch 'origin/master' into lorelei
Eric Wong [Thu, 31 Dec 2020 13:24:36 +0000 (13:24 +0000)]
Merge remote-tracking branch 'origin/master' into lorelei

* origin/master: (58 commits)
  ds: flatten + reuse @events, epoll_wait style fixes
  ds: simplify EventLoop implementation
  check defined return value for localized slurp errors
  import: check for git->qx errors, clearer return values
  git: qx: avoid extra "local" for scalar context case
  search: remove {mset} option for ->mset method
  search: remove pointless {relevance} setting
  miscsearch: take reopen from Search and use it
  extsearch: unconditionally reopen on access
  extindex: allow using --all without EXTINDEX_DIR
  extindex: add undocumented --no-scan switch
  extindex: enable autoflush on STDOUT/STDERR
  extindex: various --watch signal handling fixes
  extindex: --watch for inotify-based updates
  eml: fix undefined vars on <Perl 5.28
  t/config: test --get-urlmatch for git <2.26
  default to CORE::warn in $SIG{__WARN__} handlers
  inbox: name variable for values loop iterator
  inboxidle: avoid needless syscalls on refresh
  inboxidle: clue users into resolving ENOSPC from inotify
  ...

3 years agolei: rename proposed "query" command to "q", add JSON output
Eric Wong [Sat, 26 Dec 2020 11:13:11 +0000 (11:13 +0000)]
lei: rename proposed "query" command to "q", add JSON output

Using "query" as a verb may be confusing when we'll also refer to
them as nouns with the "<ls|rm|mv>-query" sub commands.  "query"
is also many characters to type without tab-completion on what I
expect to be one of the most commonly used sub-commands

Furthermore, "q" is also the common query parameter name used by
our PSGI interface, as is the case with several major web search
engines; so there's an element of familiarity there.

The name "search" was disregarded because "show" could be a
commonly used lei sub-command, too, and typing "se" for
tab-completion may be slow since two-handed typists on QWERTY
keyboards won't be able to use alternating hands.

"f" or "find" could be a possibility here, too; but we're
currently using the term "forget" as a weaker version of
"remove" or "rm", though "ignore" could be substituted for
"forget", perhaps...

Kyle Meyer noted the lack of (proposed) JSON output support
so that's been added to the proposed UI.

3 years agolei_xsearch: cross-(inbox|extindex) search
Eric Wong [Sun, 27 Dec 2020 20:02:51 +0000 (20:02 +0000)]
lei_xsearch: cross-(inbox|extindex) search

While a single extindex combines multiple inboxes into a single
search index, extindex still requires up-front indexing on items
which can be searched.  XSearch has no on-disk footprint itself
and uses Xapian DBs of existing publicinbox and extindex
("extinbox") exclusively.

XSearch still suffers from the multi-shard Xapian scalability
problems which led to the creation of extindex, but I expect the
number of shards to remain relatively low.

I envision users hosting public-inbox instances on their
workstations will only have two extindex combined by this, one
read-only extindex for serving public archives, and one
read-write extindex managed by LeiStore for private mail.

3 years agoimport: drop X-Status in addition to Status
Eric Wong [Thu, 17 Dec 2020 09:14:48 +0000 (09:14 +0000)]
import: drop X-Status in addition to Status

It's actually supported by mutt, dovecot[1], and likely some other
software to augment the Status: header.  While dovecot doesn't
expose X-Status to clients, mutt will write 'A' (answered) and
'F' to X-Status (but not T (draft)).

So we'll drop it like we do Status since it's not suitable for
public mail, but stick it in an @UNWANTED_HEADERS array will
allow us to configure an override if needed.

[1]  https://doc.dovecot.org/configuration_manual/mail_location/mbox/

3 years agods: flatten + reuse @events, epoll_wait style fixes
Eric Wong [Sun, 27 Dec 2020 02:53:07 +0000 (02:53 +0000)]
ds: flatten + reuse @events, epoll_wait style fixes

Consistently returning the equivalent of pollfd.revents in a
portable manner was never worth the effort for us, as we use the
same ->event_step callback regardless of POLLIN/POLLOUT/POLLHUP.

Being a Perl, @events knows it size and we don't have to return
a maximum index for the caller to iterate on.

We can also avoid redundant integer coercion ("+0") since we
ensure everything is an IV in other places.

Finally, vec() is preferable to ("\0" x $size) for resizing
buffers because it only needs to write the extended portion
and not overwrite the entire buffer.

3 years agods: simplify EventLoop implementation
Eric Wong [Sun, 27 Dec 2020 02:53:06 +0000 (02:53 +0000)]
ds: simplify EventLoop implementation

More importantly, make it easier-to-find the sub by avoiding
runtime manipulation of subroutine names.  There's no point in
avoiding a potential call to _InitPoller in EventLoop since
entering EventLoop is rare.

On the contrary, PublicInbox::DS->new is called often and this
change to avoid entering _InitPoller there may have more
benefits (which may still be unmeasurable).

3 years agocheck defined return value for localized slurp errors
Eric Wong [Sun, 27 Dec 2020 02:53:05 +0000 (02:53 +0000)]
check defined return value for localized slurp errors

Reading from regular files (even on STDIN) can fail
when dealing with flakey storage.

3 years agoimport: check for git->qx errors, clearer return values
Eric Wong [Sun, 27 Dec 2020 02:53:04 +0000 (02:53 +0000)]
import: check for git->qx errors, clearer return values

Those git commands can fail and git->qx will set $? when it
fails.  There's no need for the extra indirection of the @ret
array, either.

Improve git->qx coverage to check for $? while we're at it.

3 years agogit: qx: avoid extra "local" for scalar context case
Eric Wong [Sun, 27 Dec 2020 02:53:03 +0000 (02:53 +0000)]
git: qx: avoid extra "local" for scalar context case

We can use the ternary operator to avoid an early return, here

3 years agosearch: remove {mset} option for ->mset method
Eric Wong [Sun, 27 Dec 2020 19:38:29 +0000 (19:38 +0000)]
search: remove {mset} option for ->mset method

The ->mset method always returns a Xapian mset nowadays, so
naming a parameter {mset} is too confusing.  As it does with
MiscSearch, setting the {relevance} parameter to -1 now sorts by
ascending docid order.  -2 is now supported for descending
docid order, too, since it may be useful for lei users.

3 years agosearch: remove pointless {relevance} setting
Eric Wong [Sun, 27 Dec 2020 19:38:28 +0000 (19:38 +0000)]
search: remove pointless {relevance} setting

SearchView will set it to `undef', others will set the 'mset'
option (for the ->mset method :P) to 2 which causes {relevance}
to be ignored.

And the 'mset' option is poorly named now that the message
is named ->mset...

3 years agomiscsearch: take reopen from Search and use it
Eric Wong [Sun, 27 Dec 2020 11:01:42 +0000 (11:01 +0000)]
miscsearch: take reopen from Search and use it

As with ExtSearch, MiscSearch lacks a janky cleanup timer of
PublicInbox::Inbox objects, leading to info about
inboxes/newsgroups going stale.  Fortunately, we don't use
MiscSearch very heavily, yet.

In the future, we may be able to detect new inboxes without
having to SIGHUP or restart daemons using MiscSearch.

3 years agoextsearch: unconditionally reopen on access
Eric Wong [Sun, 27 Dec 2020 11:01:41 +0000 (11:01 +0000)]
extsearch: unconditionally reopen on access

Since ExtSearch lacks the janky cleanup timer of
PublicInbox::Inbox objects, its search results get stale.

Reopen the Xapian DB on every ->search call for now, as
reducing reopen calls doesn't seem worth the complexity.

The Xapian::Database::reopen operation itself takes only ~50us
on my old workstation with 3 shards totaling <200GB.  Other
parts of Xapian dominates the search time, so the reopen seems
inconsequential with single-digit shard counts.

3 years agoextindex: allow using --all without EXTINDEX_DIR
Eric Wong [Sat, 26 Dec 2020 10:16:24 +0000 (10:16 +0000)]
extindex: allow using --all without EXTINDEX_DIR

If "--all" is specified to index all inboxes, implicitly choose
the configured [extindex "all"] external index since "--all" is
incompatible with specifying inbox directories on the
command-line.

3 years agoextindex: add undocumented --no-scan switch
Eric Wong [Sat, 26 Dec 2020 10:16:23 +0000 (10:16 +0000)]
extindex: add undocumented --no-scan switch

This makes diagnosing --watch problems easier when there's
50K inboxes by avoiding the lengthy scan (which is the reason
--watch exists in the first place).

3 years agoextindex: enable autoflush on STDOUT/STDERR
Eric Wong [Sat, 26 Dec 2020 10:16:22 +0000 (10:16 +0000)]
extindex: enable autoflush on STDOUT/STDERR

With --watch, the output may be redirected to a pipe or socket
which Perl may decide to buffer.  Ensure Perl doesn't buffer
these outputs since they can provide real-time status updates
in response to signals or FS activity.

3 years agoextindex: various --watch signal handling fixes
Eric Wong [Sat, 26 Dec 2020 10:16:21 +0000 (10:16 +0000)]
extindex: various --watch signal handling fixes

We need to clobber the SIGUSR1 resync queue on SIGHUP to
invalidate old inbox objects.  Furthermore, the lengthy
initial scan needs to ignore signals intended for the
event loop to avoid unexpected behavior.  Finally, add
some progress output to inform users on the terminal
to inform users' of progress.

3 years agoextindex: --watch for inotify-based updates
Eric Wong [Sat, 26 Dec 2020 01:44:37 +0000 (01:44 +0000)]
extindex: --watch for inotify-based updates

This reuses existing InboxIdle infrastructure to update external
indices based on per-inbox updates.  This is an alternative to
auto-updating external indices via the -index command and also
works with existing uses of -mda and public-inbox-watch.

Using inotify (or EVFILT_VNODE) allows watching thousands of
inboxes without having to scan every single one at every
invocation.

This is especially beneficial in cases where an external index
is not writable to the users writing to per-inbox indices.

3 years agoeml: fix undefined vars on <Perl 5.28
Eric Wong [Sat, 26 Dec 2020 12:25:42 +0000 (12:25 +0000)]
eml: fix undefined vars on <Perl 5.28

Encode::MIME::Header::_decode_octets did not correctly default
to Encode::FB_DEFAULT until Encode 2.93 (perl5.git commit
0c541dc5633a341cf44b818014b58e7f8be532e9).  Provide the default
again to work with older Perls.

Reported-by: Ali Alnubani <alialnu@nvidia.com>
Link: https://public-inbox.org/meta/DM6PR12MB49106F8E3BD697B63B943A22DADB0@DM6PR12MB4910.namprd12.prod.outlook.com/
Tested-by: Ali Alnubani <alialnu@nvidia.com>
(cherry picked from commit 46bd595f57cc3d425754b0d0770c125616e74448)

3 years agot/config: test --get-urlmatch for git <2.26
Eric Wong [Sat, 26 Dec 2020 12:30:35 +0000 (12:30 +0000)]
t/config: test --get-urlmatch for git <2.26

While git 1.8.5 learned --get-urlmatch, git did not learn to
match URLs against wildcards until 2.26.  So only depend on
1.8.5 for this test since 2.26 is too new.

Reported-by: Ali Alnubani <alialnu@nvidia.com>
Link: https://public-inbox.org/meta/DM6PR12MB49106F8E3BD697B63B943A22DADB0@DM6PR12MB4910.namprd12.prod.outlook.com/
Tested-by: Ali Alnubani <alialnu@nvidia.com>
(cherry picked from commit 382a2bdd54cfb6c28a935c2b9fe4f1b1c2f469c4)

3 years agoinboxidle: avoid needless syscalls on refresh
Eric Wong [Sat, 26 Dec 2020 09:34:39 +0000 (09:34 +0000)]
inboxidle: avoid needless syscalls on refresh

We don't have to replace a bunch of existing watches
with identical new ones.  On Linux with Linux::Inotify2
installed, this avoids a storm of inotify_add_watch(2)
and inotify_rm_watch(2) syscalls on SIGHUP with -imapd
and "-extindex --watch"

(cherry picked from commit 10bf54305da8422d9ece6b809996092c1c4b1786)

Note: this seems to fix missed wakeups with many watches,
so it's in the stable branch.

Link: https://public-inbox.org/meta/20201226201115.GA30142@dcvr/
3 years agoinboxidle: clue users into resolving ENOSPC from inotify
Eric Wong [Sat, 26 Dec 2020 05:59:22 +0000 (05:59 +0000)]
inboxidle: clue users into resolving ENOSPC from inotify

It may not be obvious to users a ENOSPC error is from hitting
a (tunable) kernel-imposed limit on inotify watches, and not
some storage device running out of space.  Give them a hint
here to reduce our own support burden.

(cherry picked from commit 5e05c2eb58a450849f1826f3d02ed62b814b6617)

3 years agoinbox: name variable for values loop iterator
Eric Wong [Sat, 26 Dec 2020 08:12:52 +0000 (08:12 +0000)]
inbox: name variable for values loop iterator

->on_inbox_unlock callbacks could clobber $_, and this seems to
fix a problem with -extindex --watch failing to index some
inboxes after SIGHUP reload.

(cherry picked from commit b5e960f50289434025f5904c8c1311e4c8a02b82)

3 years agopublic-inbox-v[12]-format.pod: make lexgrog happy
Uwe Kleine-König [Tue, 22 Dec 2020 17:18:10 +0000 (18:18 +0100)]
public-inbox-v[12]-format.pod: make lexgrog happy

The Debian package linter (lintian) emits the following warning:

W: bad-whatis-entry
N:
N:   A manual page should start with a NAME section, which lists the
N:   program name and a brief description. The NAME section is used to
N:   generate a database that can be queried by commands like apropos and
N:   whatis. You are seeing this tag because lexgrog was unable to parse
N:   the NAME section.
N:
N:   Manual pages for multiple programs, functions, or files should list
N:   each separated by a comma and a space, followed by \- and a common
N:   description.
N:
N:   Listed items may not contain any spaces. A manual page for a two-level
N:   command such as fs listacl must look like fs_listacl so the list is
N:   read correctly.
N:
N:   Refer to the lexgrog(1) manual page, the groff_man(7) manual page, and
N:   the groff_mdoc(7) manual page for details.
N:
N:   Severity: warning
N:
N:   Check: documentation/manual
N:
N:   Renamed from: manpage-has-bad-whatis-entry
N:

for public-inbox-v1-format and public-inbox-v2-format.

Adapt the descriptions to make lexgrog and so lintian happy.

(cherry picked from commit 1350f5ab09f72c75ac2cd6c88f6a2b9e198fef55)

3 years agomanifest.js.gz: fix per-inbox /$INBOX/manifest.js.gz
Eric Wong [Mon, 21 Dec 2020 19:41:21 +0000 (19:41 +0000)]
manifest.js.gz: fix per-inbox /$INBOX/manifest.js.gz

/$INBOX/manifest.js.gz should not attempt to match every inbox
in the domain (or every inbox); that is for /manifest.js.gz
(without a /$INBOX prefix).

Fixes: f303b4add8ea1883 ("wwwlisting: avoid hogging event loop")
(cherry picked from commit 3ce4c38119f13d419bb865a0aa9b66feff339308)

3 years agoFix manpage section of perl module documentation
Uwe Kleine-König [Fri, 18 Dec 2020 11:56:14 +0000 (12:56 +0100)]
Fix manpage section of perl module documentation

On Debian (at least) perl documentation is supposed to be installed in
section 3pm. With the build system hardcoding this to 3 instead this
results in a warning by the Debian package linter:

W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::Git.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::Import.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section usr/share/man/man3/PublicInbox::SaPlugin::ListMirror.3.gz:74 3 != 3pm
W: public-inbox: wrong-manual-section ... use --no-tag-display-limit to see all (or pipe to a file/program)

So use "$(MAN3EXT)" instead of "3".

(cherry picked from commit cd12cf22c4d161b7aec819f45628b983f0bd675d)

3 years agot/psgi_v2: ignore warnings on missing P::M::ReverseProxy
Eric Wong [Wed, 16 Dec 2020 04:39:37 +0000 (04:39 +0000)]
t/psgi_v2: ignore warnings on missing P::M::ReverseProxy

Plack::Test::ExternalServer doesn't depend on
Plack::Middleware::ReverseProxy, so we need to account for
some warnings in stderr if P::M::RP is missing.

(cherry picked from commit d26c2837f479b41182946a6540aad95d34b2b594)

3 years agodaemon: support --daemonize without Net::Server::Daemonize
Eric Wong [Tue, 15 Dec 2020 11:47:16 +0000 (11:47 +0000)]
daemon: support --daemonize without Net::Server::Daemonize

We don't actually need Net::Server::Daemonize to support
the --daemonize flag, since the daemonize() sub provided
by N::S::D doesn't exactly do the things we want.

(cherry picked from commit ab11caeb8ae114087636748df4c956d0e625b237)

3 years agodoc: v2-format: drop repeated word
Kyle Meyer [Sat, 12 Dec 2020 18:24:48 +0000 (18:24 +0000)]
doc: v2-format: drop repeated word

(cherry picked from commit 4df1904582c4d7bec64e05d1566cd48c8c2e888e)