From a74fc7ef6d9f8728f7816362c7f4875f505386aa Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 23 Nov 2019 12:36:44 -0800 Subject: [PATCH] Remove the wait_for_threads_to_die parameter to execute_fork This is always set to false so we can get rid of it. --- src/exec.cpp | 7 +++---- src/postfork.cpp | 4 ++-- src/postfork.h | 7 ++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index ae033abba..a6596b6f8 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -435,10 +435,9 @@ static bool run_internal_process(process_t *p, std::string outdata, std::string /// Call fork() as part of executing a process \p p in a job \j. Execute \p child_action in the /// context of the child. Returns true if fork succeeded, false if fork failed. static bool fork_child_for_process(const std::shared_ptr &job, process_t *p, - const dup2_list_t &dup2s, bool drain_threads, - const char *fork_type, + const dup2_list_t &dup2s, const char *fork_type, const std::function &child_action) { - pid_t pid = execute_fork(drain_threads); + pid_t pid = execute_fork(); if (pid == 0) { // This is the child process. Setup redirections, print correct output to // stdout and stderr, and then exit. @@ -760,7 +759,7 @@ static bool exec_external_command(parser_t &parser, const std::shared_ptr } else #endif { - if (!fork_child_for_process(j, p, *dup2s, false, "external command", + if (!fork_child_for_process(j, p, *dup2s, "external command", [&] { safe_launch_process(p, actual_cmd, argv, envv); })) { return false; } diff --git a/src/postfork.cpp b/src/postfork.cpp index 9a5866b35..680625bf1 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -168,10 +168,10 @@ int child_setup_process(pid_t new_termowner, bool is_forked, const dup2_list_t & /// This function is a wrapper around fork. If the fork calls fails with EAGAIN, it is retried /// FORK_LAPS times, with a very slight delay between each lap. If fork fails even then, the process /// will exit with an error message. -pid_t execute_fork(bool wait_for_threads_to_die) { +pid_t execute_fork() { ASSERT_IS_MAIN_THREAD(); - if (wait_for_threads_to_die || JOIN_THREADS_BEFORE_FORK) { + if (JOIN_THREADS_BEFORE_FORK) { // Make sure we have no outstanding threads before we fork. This is a pretty sketchy thing // to do here, both because exec.cpp shouldn't have to know about iothreads, and because the // completion handlers may do unexpected things. diff --git a/src/postfork.h b/src/postfork.h index aeac13c0b..442e666f3 100644 --- a/src/postfork.h +++ b/src/postfork.h @@ -33,11 +33,8 @@ bool child_set_group(job_t *j, process_t *p); // called by child /// On failure, signal handlers, io redirections and process group of the process is undefined. int child_setup_process(pid_t new_termowner, bool is_forked, 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 -/// not necessary to wait for threads to die. If the forked child may do those things, it should -/// wait for threads to die. -pid_t execute_fork(bool wait_for_threads_to_die); +/// Call fork(), retrying on failure a few times. +pid_t execute_fork(); /// Report an error from failing to exec or posix_spawn a command. void safe_report_exec_error(int err, const char *actual_cmd, const char *const *argv,