diff --git a/src/exec.cpp b/src/exec.cpp index 0cda24b00..2e5a9760e 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -118,7 +118,7 @@ char *get_interpreter(const char *command, char *interpreter, size_t buff_size) } /// This function is executed by the child process created by a call to fork(). It should be called -/// after \c setup_child_process. It calls execve to replace the fish process image with the command +/// after \c child_setup_process. It calls execve to replace the fish process image with the command /// specified in \c p. It never returns. Called in a forked child! Do not allocate memory, etc. static void safe_launch_process(process_t *p, const char *actual_cmd, const char *const *cargv, const char *const *cenvv) { @@ -293,14 +293,14 @@ static bool can_use_posix_spawn_for_job(const std::shared_ptr &job) { 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. + // child_setup_process makes sure signals are properly set up. // PCA This is for handling exec. Passing all_ios here matches what fish 2.0.0 and 1.x did. // It's known to be wrong - for example, it means that redirections bound for subsequent // commands in the pipeline will apply to exec. However, using exec in a pipeline doesn't // really make sense, so I'm not trying to fix it here. auto redirs = dup2_list_t::resolve_chain(all_ios); - if (redirs && !setup_child_process(0, *redirs)) { + if (redirs && !child_setup_process(0, *redirs)) { // Decrement SHLVL as we're removing ourselves from the shell "stack". auto shlvl_var = vars.get(L"SHLVL", ENV_GLOBAL | ENV_EXPORT); wcstring shlvl_str = L"0"; @@ -445,7 +445,7 @@ static bool fork_child_for_process(const std::shared_ptr &job, process_t // stdout and stderr, and then exit. p->pid = getpid(); child_set_group(job.get(), p); - setup_child_process(p, dup2s); + child_setup_process(p, dup2s); child_action(); DIE("Child process returned control to fork_child lambda!"); } diff --git a/src/postfork.cpp b/src/postfork.cpp index 0e57d0c7a..9550bc7c1 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -59,7 +59,7 @@ bool child_set_group(job_t *j, process_t *p) { continue; } else if (errno == EINTR) { // I don't think signals are blocked here. The parent (fish) redirected the - // signal handlers and `setup_child_process()` calls `signal_reset_handlers()` + // signal handlers and `child_setup_process()` calls `signal_reset_handlers()` // after we're done here (and not `signal_unblock()`). We're already in a loop, // so let's just handle EINTR just in case. continue; @@ -154,13 +154,14 @@ bool maybe_assign_terminal(const job_t *j) { return true; } -int setup_child_process(process_t *p, const dup2_list_t &dup2s) { +int child_setup_process(process_t *p, const dup2_list_t &dup2s) { + // Note we are called in a forked child. for (const auto &act : dup2s.get_actions()) { int err = act.target < 0 ? close(act.src) : dup2(act.src, act.target); if (err < 0) { // We have a null p if this is for the exec (non-fork) path. if (p != nullptr) { - debug_safe(4, "redirect_in_child_after_fork failed in setup_child_process"); + debug_safe(4, "redirect_in_child_after_fork failed in child_setup_process"); exit_without_destructors(1); } return err; diff --git a/src/postfork.h b/src/postfork.h index f09efd8af..51bc1afca 100644 --- a/src/postfork.h +++ b/src/postfork.h @@ -28,12 +28,9 @@ bool maybe_assign_terminal(const job_t *j); /// inside the exec function, which blocks all signals), and all IO redirections and other file /// descriptor actions are performed. /// -/// \param p the child process to set up -/// \param dup2 the dup2 list to apply -/// /// \return 0 on sucess, -1 on failiure. When this function returns, signals are always unblocked. /// On failiure, signal handlers, io redirections and process group of the process is undefined. -int setup_child_process(process_t *p, const dup2_list_t &dup2s); +int child_setup_process(process_t *p, const dup2_list_t &dup2s); /// Call fork(), optionally waiting until we are no longer multithreaded. If the forked child /// doesn't do anything that could allocate memory, take a lock, etc. (like call exec), then it's