mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-15 09:27:38 +00:00
Eliminate global env_export_arr()
This assumes the set of exported variables is a global property; but we want it to be a local property.
This commit is contained in:
parent
a47f6859bd
commit
e6872b83b0
3 changed files with 11 additions and 16 deletions
|
@ -1444,8 +1444,6 @@ void env_pop() { env_stack_t::principal().pop(); }
|
|||
|
||||
void env_universal_barrier() { env_stack_t::principal().universal_barrier(); }
|
||||
|
||||
const char *const *env_export_arr() { return env_stack_t::principal().export_arr(); }
|
||||
|
||||
void env_set_argv(const wchar_t *const *argv) { return env_stack_t::principal().set_argv(argv); }
|
||||
|
||||
wcstring_list_t env_get_names(int flags) { return env_stack_t::principal().get_names(flags); }
|
||||
|
@ -1580,7 +1578,7 @@ void var_stack_t::update_export_array_if_necessary() {
|
|||
return;
|
||||
}
|
||||
|
||||
debug(4, L"env_export_arr() recalc");
|
||||
debug(4, L"export_arr() recalc");
|
||||
var_table_t vals;
|
||||
get_exported(this->top.get(), vals);
|
||||
|
||||
|
|
|
@ -173,9 +173,6 @@ void env_pop();
|
|||
/// Synchronizes all universal variable changes: writes everything out, reads stuff in.
|
||||
void env_universal_barrier();
|
||||
|
||||
/// Returns an array containing all exported variables in a format suitable for execv
|
||||
const char *const *env_export_arr();
|
||||
|
||||
/// Sets up argv as the given null terminated array of strings.
|
||||
void env_set_argv(const wchar_t *const *argv);
|
||||
|
||||
|
|
20
src/exec.cpp
20
src/exec.cpp
|
@ -202,14 +202,14 @@ static void safe_launch_process(process_t *p, const char *actual_cmd, const char
|
|||
|
||||
/// This function is similar to launch_process, except it is not called after a fork (i.e. it only
|
||||
/// calls exec) and therefore it can allocate memory.
|
||||
static void launch_process_nofork(process_t *p) {
|
||||
static void launch_process_nofork(env_stack_t &vars, process_t *p) {
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
ASSERT_IS_NOT_FORKED_CHILD();
|
||||
|
||||
null_terminated_array_t<char> argv_array;
|
||||
convert_wide_array_to_narrow(p->get_argv_array(), &argv_array);
|
||||
|
||||
const char *const *envv = env_export_arr();
|
||||
const char *const *envv = vars.export_arr();
|
||||
char *actual_cmd = wcs2str(p->actual_cmd);
|
||||
|
||||
// Ensure the terminal modes are what they were before we changed them.
|
||||
|
@ -358,7 +358,7 @@ static bool can_use_posix_spawn_for_job(const std::shared_ptr<job_t> &job,
|
|||
return result;
|
||||
}
|
||||
|
||||
void internal_exec(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) {
|
||||
// Do a regular launch - but without forking first...
|
||||
|
||||
// setup_child_process makes sure signals are properly set up.
|
||||
|
@ -380,7 +380,7 @@ void internal_exec(job_t *j, const io_chain_t &&all_ios) {
|
|||
env_set_one(L"SHLVL", ENV_GLOBAL | ENV_EXPORT, shlvl_str);
|
||||
|
||||
// launch_process _never_ returns.
|
||||
launch_process_nofork(j->processes.front().get());
|
||||
launch_process_nofork(vars, j->processes.front().get());
|
||||
} else {
|
||||
j->set_flag(job_flag_t::CONSTRUCTED, true);
|
||||
j->processes.front()->completed = 1;
|
||||
|
@ -648,8 +648,8 @@ static bool handle_builtin_output(const std::shared_ptr<job_t> &j, process_t *p,
|
|||
|
||||
/// Executes an external command.
|
||||
/// \return true on success, false if there is an exec error.
|
||||
static bool exec_external_command(const std::shared_ptr<job_t> &j, process_t *p,
|
||||
const io_chain_t &proc_io_chain) {
|
||||
static bool exec_external_command(env_stack_t &vars, const std::shared_ptr<job_t> &j,
|
||||
process_t *p, const io_chain_t &proc_io_chain) {
|
||||
assert(p->type == EXTERNAL && "Process is not external");
|
||||
// Get argv and envv before we fork.
|
||||
null_terminated_array_t<char> argv_array;
|
||||
|
@ -663,7 +663,7 @@ static bool exec_external_command(const std::shared_ptr<job_t> &j, process_t *p,
|
|||
make_fd_blocking(STDIN_FILENO);
|
||||
|
||||
const char *const *argv = argv_array.get();
|
||||
const char *const *envv = env_export_arr();
|
||||
const char *const *envv = vars.export_arr();
|
||||
|
||||
std::string actual_cmd_str = wcs2string(p->actual_cmd);
|
||||
const char *actual_cmd = actual_cmd_str.c_str();
|
||||
|
@ -919,7 +919,7 @@ static bool exec_process_in_job(parser_t &parser, process_t *p, std::shared_ptr<
|
|||
set_proc_had_barrier(true);
|
||||
env_universal_barrier();
|
||||
}
|
||||
env_export_arr();
|
||||
parser.vars().export_arr();
|
||||
}
|
||||
|
||||
// Set up fds that will be used in the pipe.
|
||||
|
@ -975,7 +975,7 @@ static bool exec_process_in_job(parser_t &parser, process_t *p, std::shared_ptr<
|
|||
}
|
||||
|
||||
case EXTERNAL: {
|
||||
if (!exec_external_command(j, p, process_net_io_chain)) {
|
||||
if (!exec_external_command(parser.vars(), j, p, process_net_io_chain)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
@ -1028,7 +1028,7 @@ bool exec_job(parser_t &parser, shared_ptr<job_t> j) {
|
|||
}
|
||||
|
||||
if (j->processes.front()->type == INTERNAL_EXEC) {
|
||||
internal_exec(j.get(), std::move(all_ios));
|
||||
internal_exec(parser.vars(), j.get(), all_ios);
|
||||
DIE("this should be unreachable");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue