mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-24 13:35:57 +08:00
6f682c8405
This is a large change to how io_buffers are filled. The essential problem comes about with code like (example): echo ( /bin/pwd ) The output of /bin/pwd must go to fish, not the tty. To arrange for this, fish does the following: 1. Invoke pipe() to create a pipe. 2. Add an io_bufferfill_t redirection that owns the write end of the pipe. 3. After fork (or equiv), call dup2() to replace pwd's stdout with this pipe. Now when /bin/pwd writes, it will send output to the read end of the pipe. But who reads it? Prior to this fix, fish would do the following in a loop: 1. select() on the pipe with a 10 msec timeout 2. waitpid(WNOHANG) on the pwd proc This polling is ugly and confusing and is what is replaced here. With this new change, fish now reads from the pipe via a background thread: 1. Spawn a background pthread, which select()s on the pipe's read end with a long (100 msec) timeout. 2. In the foreground, waitpid() (allowing hanging) on the pwd proc. The big win here is a major simplification of job_t::continue_job() since it no longer has to worry about filling buffers. This will make things easier for concurrent execution. It may not be obvious why the background thread still needs a poll (100 msec). The answer is for cases where the write end of the fd escapes, in particular background processes invoked inside command substitutions. psub is perhaps the only important case of this (other shells typically just hang here).
24 lines
224 B
Plaintext
24 lines
224 B
Plaintext
|
|
####################
|
|
# no args
|
|
0
|
|
|
|
####################
|
|
# one args
|
|
1
|
|
|
|
####################
|
|
# two args
|
|
2
|
|
|
|
####################
|
|
# args that look like flags or are otherwise special
|
|
1
|
|
1
|
|
1
|
|
2
|
|
3
|
|
|
|
####################
|
|
# big counts
|