-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
[core/process] Fix redirections #723
Conversation
Thanks! It's not that surprising to me that there are still bugs left, since even after restructuring I don't grok every part of this code... I remember I mainly wrote it with strace :-/ The FD manipulations are still confusing to me. I'm strace-ing bash and zsh, and they don't seem to do this check? bash:
zsh:
mksh has 2 different errors:
OK I guess that's why it already fails for descriptor 99, but not 100... ? But I guess the test cases are good so I should merge this and figure out the code again later ... |
Here is what Oil does now... So I think there could be a pure check that I'm not entirely sure about it, but I think that is what mksh does.
|
Thank you. I think I should have explained what happens here. The problem of not-failing
Even if I checked Bash
Bash behaves like this:
Because Bash explicitly specifies X := max(N+1,10) (which is ensured to be larger than N) as Zsh
Zsh behaves like this:
When N is invalid, zsh can detect it on the first step, so zsh can produce the error message. But this approach involves additional fd moves. Mksh
Mksh uses the same approach as this PR. It first checks if N is valid or not. Only when N is valid it tries to save M and copy N to M.
In addition, mksh prohibits access to fds greater or equal to
If you restrict the value of $ exec {fd}> a.txt # <-- $fd becomes _SHELL_MIN_FD or larger.
$ echo hello >&$fd # <-- we need to access $fd (>= _SHELL_MIN_FD)
$ exec {fd}>&- |
I added a test case 48474aa. |
OK thank you for the detailed answers! I merged it. I feel like the check could be optimized away in some cases but since I don't fully understand it yet, it's better to move forward. The tests will help with future refactoring! |
Thank you!
Actually, it will work without the check when |
: 2>/dev/null >&30
"{fd}>&-
does not close the fd">&100
does not fail even if fd 100 does not exist.