mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
Allow posix_spawn more often
Now that we no longer open files after fork, we can correctly report errors for failed file opens. So allow posix_spawn even if there's redirections.
This commit is contained in:
parent
2742267b9e
commit
084ff64f4f
1 changed files with 3 additions and 25 deletions
28
src/exec.cpp
28
src/exec.cpp
|
@ -115,18 +115,6 @@ static bool redirection_is_to_real_file(const io_data_t *io) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool chain_contains_redirection_to_real_file(const io_chain_t &io_chain) {
|
|
||||||
bool result = false;
|
|
||||||
for (size_t idx = 0; idx < io_chain.size(); idx++) {
|
|
||||||
const io_data_t *io = io_chain.at(idx).get();
|
|
||||||
if (redirection_is_to_real_file(io)) {
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the interpreter for the specified script. Returns NULL if file is not a script with a
|
/// Returns the interpreter for the specified script. Returns NULL if file is not a script with a
|
||||||
/// shebang.
|
/// shebang.
|
||||||
char *get_interpreter(const char *command, char *interpreter, size_t buff_size) {
|
char *get_interpreter(const char *command, char *interpreter, size_t buff_size) {
|
||||||
|
@ -330,11 +318,9 @@ void internal_exec_helper(parser_t &parser, parsed_source_ref_t parsed_source, t
|
||||||
job_reap(false);
|
job_reap(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns whether we can use posix spawn for a given process in a given job. Per
|
// Returns whether we can use posix spawn for a given process in a given job.
|
||||||
// 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
|
// 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
|
// 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).
|
// 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 std::shared_ptr<job_t> &job,
|
static bool can_use_posix_spawn_for_job(const std::shared_ptr<job_t> &job,
|
||||||
|
@ -348,15 +334,7 @@ static bool can_use_posix_spawn_for_job(const std::shared_ptr<job_t> &job,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
// Now see if we have a redirection involving a file. The only one we allow is /dev/null, which
|
|
||||||
// we assume will not fail.
|
|
||||||
bool result = true;
|
|
||||||
if (chain_contains_redirection_to_real_file(job->block_io_chain()) ||
|
|
||||||
chain_contains_redirection_to_real_file(process->io_chain())) {
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void internal_exec(env_stack_t &vars, job_t *j, const io_chain_t &all_ios) {
|
void internal_exec(env_stack_t &vars, job_t *j, const io_chain_t &all_ios) {
|
||||||
|
|
Loading…
Reference in a new issue