bug#81604: [PATCH] truncate: don't hang with FIFO --reference
From:
Collin Funk
Subject:
bug#81604: [PATCH] truncate: don't hang with FIFO --reference
Date:
Wed, 12 Aug 2026 00:01:24 -0700
User-agent:
Gnus/5.13 (Gnus v5.13)
Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com> writes:
> When st_size is not usable, truncate opens the --reference operand and
> uses lseek(SEEK_END) to obtain a size. Opening a FIFO with O_RDONLY
> blocks until a writer appears, so "truncate --reference=fifo file"
> could hang indefinitely. Use O_NONBLOCK, matching the existing open of
> the output file and the approach taken in df.
>
> Introduced by commit v8.16-49-g9d308df13.
>
> * NEWS: Mention the fix.
> * src/truncate.c (main): Open the reference with O_NONBLOCK.
> * tests/truncate/truncate-fifo.sh: Also cover --reference=FIFO.
>
> Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com>
> ---
> NEWS | 3 +++
> src/truncate.c | 3 ++-
> tests/truncate/truncate-fifo.sh | 8 ++++++++
> 3 files changed, 13 insertions(+), 1 deletion(-)
This looks correct to me. I'll push it later to allow others a chance to
double-check.
Thanks!
Collin