Bug 221976 - tail(1) can report an incorrect error if stdout becomes a broken pipe
Summary: tail(1) can report an incorrect error if stdout becomes a broken pipe
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.3-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Conrad Meyer
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2017-09-01 11:26 UTC by martin
Modified: 2017-09-01 22:37 UTC (History)
1 user (show)

See Also:


Attachments
Patch to avoid calling oerr if there is no errno set. (438 bytes, patch)
2017-09-01 11:26 UTC, martin
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description martin 2017-09-01 11:26:03 UTC
Created attachment 185973 [details]
Patch to avoid calling oerr if there is no errno set.

If stdout becomes a broken pipe while tail(1) is writing to it, then an incorrect error message can be displayed.  E.g.

$ seq -f '%128g' 1 1000 > /tmp/ints
$ tail -n 856 /tmp/ints | awk '{ exit }'
tail: stdout: No such file or directory
$ 

The problem is that WR in src/usr.bin/tail/extern.h can call oerr() if write returned a non negative value indicating a partial write, in which case errno is not set.

The attached patch fixes the test case.