From d1f1da9ce54efa058681f2d78e427e08c1cb171b Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 7 Mar 2022 13:23:13 +0100 Subject: SystemCommand: Exit without cleanup on error and avoid logger --- src/buildtool/system/system.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/buildtool/system/system.cpp (limited to 'src/buildtool/system/system.cpp') diff --git a/src/buildtool/system/system.cpp b/src/buildtool/system/system.cpp new file mode 100644 index 00000000..5f389b9a --- /dev/null +++ b/src/buildtool/system/system.cpp @@ -0,0 +1,23 @@ +#include "src/buildtool/system/system.hpp" + +#include +#include +#include + +#include + +void System::ExitWithoutCleanup(int exit_code) { +#ifdef VALGRIND_BUILD + // Usually std::_Exit() is the right thing to do in child processes that do + // not need to perform any cleanup (static destructors etc.). However, + // Valgrind will trace child processes until exec(3) is called or otherwise + // complains about leaks. Therefore, exit child processes via execvpe(3) if + // VALGRIND_BUILD is defined. + auto cmd = + std::string{exit_code == EXIT_SUCCESS ? "/bin/true" : "/bin/false"}; + auto args = std::array{cmd.data(), nullptr}; + ::execvpe(args[0], args.data(), nullptr); +#else + std::_Exit(exit_code); +#endif +} -- cgit v1.2.3