tail: reuse existing pipe when stdout is already a pipe#12463
tail: reuse existing pipe when stdout is already a pipe#12463dragutreis wants to merge 2 commits into
Conversation
|
It is not what I was expected at the linked PR. I meant |
|
But it seems still useful for supressing other syscalls at some cases. Right? |
|
Oh, thanks for clarifying, I'm not really sure what to do however, should I keep this pr and open a new one to fix the actual issue? |
|
We should try |
|
GNU testsuite comparison: |
|
Actually, I was not able to fix it by |
|
Hmmm, I'll look into it and try to fix it. |
This comment was marked as resolved.
This comment was marked as resolved.
|
( to clarify, |
|
Used strace -k to track it down. The pipe2 call was coming from splice_unbounded_broker in pipes.rs, which unconditionally creates a broker pipe even when stdout is already a pipe. There's even a comment around line 109 noting it shouldn't be used when one side is already a pipe. Replacing it with splice_unbounded_auto fixes it, not sure why it didn't work when you tried. |
|
|
|
Awesome, glad that fixed it. |
|
Would you revert 1st change, make diff 1line, and edit description to note about |
|
Will do. |
Use splice_unbounded_auto instead of splice_unbounded_broker to avoid creating a broker pipe when stdout is already a pipe (e.g., when piping to another command with |).
153753c to
da5a633
Compare
Summary
Fixes #12413
tail -c +1 /dev/nullmade an unnecessarypipe2syscall becausesplice_unbounded_brokerunconditionally created a pipe before attemptingany data transfer.
Root cause
bounded_tailcalledprint_target_sectionunconditionally even when thefile had no data to output. On Linux,
print_target_sectioncallssplice_unbounded_broker, which always created a pipe regardless of whetherthere was any data to transfer.
Fix
Add an
is_file_exhaustedhelper and check it before callingprint_target_sectionin the unbounded case:write the byte directly to stdout since char devices don't support seeking.