New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use real pipes instead of sockets #462
Comments
|
Sorry for double posting. (my mistake). Of course some of you remember why KSH had to use sockets on some platforms: KSH needs to occasionally read only up to a new-line character and so it needs to PEEK into the input byte stream. Although older SysV type UNIXi allow for PEEKs on pipes, many newer systems (Linux?) do not allow for that (PEEK's on pipes). So KSH has to resort to sockets to get the PEEK capability on platforms that do not support PEEK for pipes. What KSH does now-a-days, exactly, on each platform, I do not know. I would like to think that it only resorts to sockets for shell "pipes" when needed, but I do not know if this is the case any longer (it might be using sockets on all platforms now, for all I know). |
The This means that For contrast, |
|
You can blame Linux for /dev/stdin not working right. Someone thought there was no need to make /dev/stdin, /dev/fd, etc work for sockets. The way the feature works on Linux seems a bit of a mess anyway: if the file descriptor in question is anything but a pipe, the file is reopened rather than dup'ed. Other than compatibility with Linux's broken /dev/fd implementation I don't think there's any compelling reason not to use sockets. There's nothing inherently virtuous about "real" pipes, and sockets provide a bunch of APIs that aren't available for pipes. As mentioned in the discussion for the other issue, one of these is the ability to peek at the socket buffer, which ksh takes advantage of. |
|
@kernigh You are right. I misinterpreted the expected test output. Also, the behavior does not change with locales but with using |
|
As @DavidMorano mentioned, Now the question is shall we switch to real pipes for saner behavior ? This may affect performance and features like returning early while reading from slow devices. |
|
Indeed. This is why I said they felt no need to make it work. /dev/stdin, etc. are used primarily as a shell programming convention but it's an awkward one in that it depends on OS support to make it work. The situation is also kind of messed up in that it's seen as a security issue, but the main use case is is just a convenience notation for dup() to allow a process to open a file that it already has open. That kind of makes the security concerns irrelevant - or at least it would if the implementation took this into account. I don't think it's worth switching to pipes just to support that. Though on the flip side I understand that from a user's point of view it looks like it's ksh that's broken, and not Linux. |
|
fwiw |
|
I think it's a bug that |
Yes, I think it is a bug (of a sort) also! But the situation is that some OSes, mostly those that did not follow the flavor of System V Release 3 (and following w/ SysV Release 4), -- like Linux! for example -- do not allow for "peeking" on pipes. As far as I remember, peeking in general and peeking on pipes was started out of research (from Research UNIX Eighth Edition) and into the commercial space w/ the introduction of STREAMS to UNIX starting w/ SysV R3. Although Linux added STREAMS some time ago (but now really gone altogether), they never brought over peeking on pipes. Yes, many of us have suffered (greatly I might add) due to this deficiency in Linux! |
|
I'm running OpenBSD and have the same problem -- it has MSG_PEEK for sockets, but doesn't have I_PEEK for pipes. |
I agree with @kernigh. Consider a ksh process that reads from a pipe (named or anonymous) setup by the process that spawned ksh on the read side of the pipe. Since that has to work correctly (and if it doesn't it needs to be fixed) there is no good reason for ksh to use sockets for the "pipes" it creates when building a pipeline. Yes, sockets have other pros compared to pipes. They can usually buffer more data. On some platforms they're faster. But I am skeptical either argument justifies the added code complexity from having to support both pipes and sockets. |
|
I think |
|
I see issue #1147 I opened a day ago is essentially a duplicate of this issue. The issue I opened noted that preprocessor symbol |
|
I've been working to make all unit tests pass on Cygwin (we're now down to 7 failures from 35 just a few weeks ago). But the object returned by |
siteshwar commentedApr 6, 2018
•
edited
Ksh uses sockets instead of real pipes to implement pipes in shell. This has caused issues on multiple occasions. For e.g.
I tried removing this code. It fixes above issue, but caused some of the
iotests to fail. Switching to real pipes may cause other regressions too. We should do a deeper analysis of how this is going to affect scripts.EDIT: Updated description.
The text was updated successfully, but these errors were encountered: