bug#81604: [PATCH] truncate: don't hang with FIFO --reference

Collin Funk <[email protected]>
Newsgroups gmane.comp.gnu.core-utils.bugs
Message-ID <[email protected]>
Iván Ezequiel Rodriguez <[email protected]> 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 <[email protected]>
> ---
>  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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.