2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
8 use PublicInbox::OnDestroy;
9 use PublicInbox::Syscall qw($F_SETPIPE_SZ);
10 use autodie qw(close open pipe seek sysread);
11 use PublicInbox::IO qw(write_file);
12 my $inboxdir = $ENV{GIANT_INBOX_DIR};
14 $inboxdir // skip 'GIANT_INBOX_DIR unset to test large results', 1;
15 require PublicInbox::Inbox;
16 my $ibx = PublicInbox::Inbox->new({
17 name => 'unconfigured-test',
18 address => [ "test\@example.com" ],
19 inboxdir => $inboxdir,
21 $ibx->search or xbail "GIANT_INBOX_DIR=$inboxdir has no search";
24 # undo systemd (and similar) ignoring SIGPIPE, since lei expects to be run
25 # from an interactive terminal:
26 # https://public-inbox.org/meta/20220227080422.gyqowrxomzu6gyin@sourcephile.fr/
27 my $oldSIGPIPE = $SIG{PIPE};
28 $SIG{PIPE} = 'DEFAULT';
29 my $cleanup = on_destroy(sub { $SIG{PIPE} = $oldSIGPIPE });
32 my $f = "$ENV{HOME}/big.eml";
34 for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) {
36 my $size = ($F_SETPIPE_SZ && fcntl($w, $F_SETPIPE_SZ, 4096)) ||
39 my $fh = write_file '>', $f, <<'EOM';
41 Message-ID: <big@example.com>
44 print $fh (' '.('x' x 72)."\n") x (($size / 73) + 1);
49 lei_ok(qw(import), $f) if $imported++ == 0;
50 open my $errfh, '+>>', "$ENV{HOME}/stderr.log";
51 my $opt = { run_mode => 0, 2 => $errfh, 1 => $w };
52 my $cmd = [qw(lei q -q -t), @$out, 'z:1..'];
53 push @$cmd, '--only='.$inboxdir if defined $inboxdir;
54 my $tp = start_script($cmd, undef, $opt);
56 vec(my $rvec = '', fileno($r), 1) = 1;
57 if (!select($rvec, undef, undef, 30)) {
59 my $s = do { local $/; <$errfh> };
60 xbail "lei q had no output after 30s, stderr=$s";
62 is(sysread($r, my $buf, 1), 1, 'read one byte');
63 close $r; # trigger SIGPIPE
65 ok(WIFSIGNALED($?), "signaled @$out");
66 is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
68 my $s = do { local $/; <$errfh> };
69 is($s, '', "quiet after sigpipe @$out");