aboutsummaryrefslogtreecommitdiffhomepage
path: root/exec.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-04-07 12:40:08 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-04-07 12:40:08 -0700
commit437b4397b9cf273922ce7b414bf6626845f15ad0 (patch)
tree8c5fbb6a7196146b5656629f8c37f4eb1d3ecd80 /exec.cpp
parent3a7ab3f030eda29ecbe54c0f44732e471300a3ed (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.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/exec.cpp b/exec.cpp
index 633a16e4..3c5d74ed 100644
--- a/exec.cpp
+++ b/exec.cpp
@@ -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);