Skip to content

tail: fix panic on header write error#12279

Open
gabrielhnf wants to merge 1 commit into
uutils:mainfrom
gabrielhnf:fix-tail-header-write-error
Open

tail: fix panic on header write error#12279
gabrielhnf wants to merge 1 commit into
uutils:mainfrom
gabrielhnf:fix-tail-header-write-error

Conversation

@gabrielhnf
Copy link
Copy Markdown

Fixes #11993

Problem

When running tail on multiple files and redirecting output to a full device (e.g. /dev/full), uutils panics instead of exiting gracefully:

thread 'main' panicked at …/std/src/io/stdio.rs:1165:9:
failed printing to stdout: No space left on device (os error 28)

Instead of the correct GNU behavior:

tail: write error: No space left on device

Cause

HeaderPrinter::print used println! to write the ==> file <== headers to stdout. println! panics on write failure rather than returning a Result, so any write error (such as ENOSPC from /dev/full) caused an unhandled panic instead of a clean error message.

Fix

Replaced println! in HeaderPrinter with write_all and flush on a locked stdout, both of which return io::Result. The methods now return UResult<()> and propagate write errors upstream instead of panicking.

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Congrats! The gnu test tests/printf/printf-surprise is now passing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tail file2 file2 >/dev/full panics

1 participant