diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2013-04-07 12:40:08 -0700 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2013-04-07 12:40:08 -0700 |
commit | 437b4397b9cf273922ce7b414bf6626845f15ad0 (patch) | |
tree | 8c5fbb6a7196146b5656629f8c37f4eb1d3ecd80 /exec.cpp | |
parent | 3a7ab3f030eda29ecbe54c0f44732e471300a3ed (diff) |
Mark stdin as nonblocking if we get EWOULDBLOCK, and before handing it off to child processes when either starting them or moving them to the foreground.
Diffstat (limited to 'exec.cpp')
-rw-r--r-- | exec.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -502,10 +502,10 @@ static void internal_exec_helper(parser_t &parser, } /* Returns whether we can use posix spawn for a given process in a given job. - Per https://github.com/fish-shell/fish-shell/issues/364 , error handling for file redirections is too difficult with posix_spawn - So in that case we use fork/exec + Per https://github.com/fish-shell/fish-shell/issues/364 , error handling for file redirections is too difficult with posix_spawn, + so in that case we use fork/exec. - Furthermore, to avoid the race between the caller calling tcsetpgrp() and the client checking the foreground process group, we don't use posix_spawn if we're going to foreground the process. (If we use fork(), we can call tcsetpgrp after the fork, before the exec, and avoid the racse). + Furthermore, to avoid the race between the caller calling tcsetpgrp() and the client checking the foreground process group, we don't use posix_spawn if we're going to foreground the process. (If we use fork(), we can call tcsetpgrp after the fork, before the exec, and avoid the race). */ static bool can_use_posix_spawn_for_job(const job_t *job, const process_t *process) { @@ -1312,6 +1312,9 @@ void exec(parser_t &parser, job_t *j) /* Get argv and envv before we fork */ null_terminated_array_t<char> argv_array; convert_wide_array_to_narrow(p->get_argv_array(), &argv_array); + + /* Ensure that stdin is blocking before we hand it off (see issue #176). It's a little strange that we only do this with stdin and not with stdout or stderr. However in practice, setting or clearing O_NONBLOCK on stdin also sets it for the other two fds, presumably because they refer to the same underlying file (/dev/tty?) */ + make_fd_blocking(STDIN_FILENO); const char * const *argv = argv_array.get(); const char * const *envv = env_export_arr(false); |