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;
10 # undo systemd (and similar) ignoring SIGPIPE, since lei expects to be run
11 # from an interactive terminal:
12 # https://public-inbox.org/meta/20220227080422.gyqowrxomzu6gyin@sourcephile.fr/
13 my $oldSIGPIPE = $SIG{PIPE};
14 $SIG{PIPE} = 'DEFAULT';
15 my $cleanup = PublicInbox::OnDestroy->new($$, sub {
16 $SIG{PIPE} = $oldSIGPIPE;
20 my $f = "$ENV{HOME}/big.eml";
22 for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) {
23 pipe(my ($r, $w)) or BAIL_OUT $!;
25 if ($^O eq 'linux' && fcntl($w, 1031, 4096)) {
29 open my $fh, '>', $f or xbail "open $f: $!";
30 print $fh <<'EOM' or xbail;
32 Message-ID: <big@example.com>
35 print $fh (' '.('x' x 72)."\n") x (($size / 73) + 1);
37 close $fh or xbail "close: $!";
40 lei_ok(qw(import), $f) if $imported++ == 0;
41 open my $errfh, '+>>', "$ENV{HOME}/stderr.log" or xbail $!;
42 my $opt = { run_mode => 0, 2 => $errfh, 1 => $w };
43 my $cmd = [qw(lei q -q -t), @$out, 'z:1..'];
44 my $tp = start_script($cmd, undef, $opt);
46 vec(my $rvec = '', fileno($r), 1) = 1;
47 if (!select($rvec, undef, undef, 30)) {
48 seek($errfh, 0, 0) or xbail $!;
49 my $s = do { local $/; <$errfh> };
50 xbail "lei q had no output after 30s, stderr=$s";
52 is(sysread($r, my $buf, 1), 1, 'read one byte');
53 close $r; # trigger SIGPIPE
55 ok(WIFSIGNALED($?), "signaled @$out");
56 is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
57 seek($errfh, 0, 0) or xbail $!;
58 my $s = do { local $/; <$errfh> };
59 is($s, '', "quiet after sigpipe @$out");