From f1a698b50e53e34db17e730c259cb60f023ccff2 Mon Sep 17 00:00:00 2001 From: Dilshod Mukhtarov Date: Tue, 14 Apr 2020 18:59:25 +0400 Subject: [PATCH] Forked subprocess not exited if execve failed (#54) * Fixed: forked subprocess not exited if execve failed In lengthy processes (daemons, etc) this bug keeps open this subprocess. The subprocess continues to work (parallel to parent process) from after failed command start * Fixed: deadlock on using multithreaded application For example if application uses spdlog logger library and set spdlog::flush_every(std::chrono::seconds(1)); then it starts it's own thread which flushes logs every 1 second. In this case if execve failed to execute given command, then parent and subprocess deadlocked. --- subprocess.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/subprocess.hpp b/subprocess.hpp index fb93766..e6485f2 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -670,7 +670,7 @@ struct input } input(IOTYPE typ) { assert (typ == PIPE && "STDOUT/STDERR not allowed"); -#ifndef _MSC_VER +#ifndef _MSC_VER std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec(); #endif } @@ -1668,12 +1668,11 @@ namespace detail { std::string err_msg(exp.what()); //ATTN: Can we do something on error here ? util::write_n(err_wr_pipe_, err_msg.c_str(), err_msg.length()); - throw; } // Calling application would not get this // exit failure - exit (EXIT_FAILURE); + _exit (EXIT_FAILURE); #endif }