| Summary: | Pipe error with csh/tcsh | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | rkanfwwatgxavmdmen | ||||
| Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> | ||||
| Status: | New --- | ||||||
| Severity: | Affects Some People | CC: | kevans, martin, rkanfwwatgxavmdmen | ||||
| Priority: | --- | ||||||
| Version: | 13.1-RELEASE | ||||||
| Hardware: | amd64 | ||||||
| OS: | Any | ||||||
| Attachments: |
|
||||||
(In reply to Niko Nastonen from comment #0) I could reproduce what you describe, but are you sure it is pipes that are the problem? If I try with other commands such as: df -h | head -n 1 && df -h | grep tmp I do not see this behavior at all, while on the other hand sockstat | head -n 1 && sockstat | grep root always shows this behavior. As you said, using ; makes it work every time in all cases. To me it seems like the && operator is somehow causing this (though I do not have any idea why). Also found out that vmstat -m | head -n 1 || vmstat -m | grep kstat_data sometimes shows output from both commands and also only as root. As an unprivileged user the output is only headers of vmstat, as it should be. So I presume there is something wrong with the output of the pipe. Mr Kyle Evans had an idea that there is a race condition inside shell / pipe handling. That is if I understood correctly what he meant. (In reply to Niko Nastonen from comment #2) Filed a bug in tcsh bugtracker: https://bugs.astron.com/view.php?id=368 Not a FreeBSD issue. (In reply to Niko Nastonen from comment #2) My opinion is that it is not a bug at all, simply how it works. Head will finish very quickly and close stdin sometimes while vmstat is still trying to write to stdout, so you will naturally see an error where that happens. Actually, I could probably see an argument that head(1) should drain the rest of stdin even with -n constraint. |
Created attachment 235222 [details] Screenshot of shell output vmstat -m | head -n 1 && vmstat -m | grep kstat_data when ran as root on csh/tcsh, does not _always_ show the output of the second command, but prints only the headers. The main word here is "always", as sometimes it works fine, but sometimes shows only the headers of vmstat. When commands are separated with a semicolon, everything works fine. Reproducible on 2 separate machines via ssh and on physical console. Bug shows itself only when the command is ran by root, everything works fine with normal user.