X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Flei-sigpipe.t;h=7fab9aebb0ff0a1faae0a57b2532ff9d2853aa7b;hb=3eec2f7792040f75f3988c520f308e2445baf645;hp=d9738b07bd8e5ddce780e8125b1207a1686cc9ab;hpb=8fbb1e5d9430b9403679c5701e109d43ad979f3f;p=public-inbox.git diff --git a/t/lei-sigpipe.t b/t/lei-sigpipe.t index d9738b07..7fab9aeb 100644 --- a/t/lei-sigpipe.t +++ b/t/lei-sigpipe.t @@ -1,10 +1,25 @@ #!perl -w -# Copyright (C) 2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ use strict; use v5.10.1; use PublicInbox::TestCommon; -use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE); +use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE SIG_UNBLOCK SIG_SETMASK sigprocmask); +use PublicInbox::OnDestroy; + +# undo systemd (and similar) blocking SIGPIPE, since lei expects to be run +# from an interactive terminal: +# https://public-inbox.org/meta/20220227080422.gyqowrxomzu6gyin@sourcephile.fr/ +my $set = POSIX::SigSet->new; +my $old = POSIX::SigSet->new; +$set->emptyset or xbail "sigemptyset $!"; +$old->emptyset or xbail "sigemptyset $!"; +$set->addset(SIGPIPE); +sigprocmask(SIG_UNBLOCK, $set, $old) or xbail "SIG_UNBLOCK: $!"; +my $cleanup = PublicInbox::OnDestroy->new($$, sub { + sigprocmask(SIG_SETMASK, $old); +}); + test_lei(sub { my $f = "$ENV{HOME}/big.eml"; my $imported; @@ -27,11 +42,17 @@ EOM } lei_ok(qw(import), $f) if $imported++ == 0; - open my $errfh, '+>', "$ENV{HOME}/stderr.log" or xbail $!; + open my $errfh, '+>>', "$ENV{HOME}/stderr.log" or xbail $!; my $opt = { run_mode => 0, 2 => $errfh, 1 => $w }; my $cmd = [qw(lei q -q -t), @$out, 'z:1..']; my $tp = start_script($cmd, undef, $opt); close $w; + vec(my $rvec = '', fileno($r), 1) = 1; + if (!select($rvec, undef, undef, 30)) { + seek($errfh, 0, 0) or xbail $!; + my $s = do { local $/; <$errfh> }; + xbail "lei q had no output after 30s, stderr=$s"; + } is(sysread($r, my $buf, 1), 1, 'read one byte'); close $r; # trigger SIGPIPE $tp->join;