]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_to_mail: open FIFOs O_WRONLY so we block
authorEric Wong <e@80x24.org>
Thu, 31 Dec 2020 13:51:46 +0000 (13:51 +0000)
committerEric Wong <e@80x24.org>
Fri, 1 Jan 2021 05:00:39 +0000 (05:00 +0000)
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.

lib/PublicInbox/LeiToMail.pm

index 5b80eb2706ac0fba9d5f756b178b09638e09f38d..be3380065fbda299c6048338572225d9b719d17e 100644 (file)
@@ -231,10 +231,11 @@ sub _mbox_write_cb ($$$$) {
        if ($dst eq '/dev/stdout') {
                $out = $lei->{1};
        } else { # TODO: mbox locking (but mairix doesn't...)
-               if (!$lei->{opt}->{augment} && -f $dst and !unlink($dst)) {
+               my $mode = -p $dst ? '>' : '+>>';
+               if (-f _ && !$lei->{opt}->{augment} and !unlink($dst)) {
                        die "unlink $dst: $!" if $! != ENOENT;
                }
-               open $out, '+>>', $dst or die "open $dst: $!";
+               open $out, $mode, $dst or die "open $dst: $!";
                # Perl does SEEK_END even with O_APPEND :<
                $seekable = seek($out, 0, SEEK_SET);
                die "seek $dst: $!\n" if !$seekable && $! != ESPIPE;