summaryrefslogtreecommitdiff
path: root/src/buildtool/system/system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildtool/system/system.cpp')
-rw-r--r--src/buildtool/system/system.cpp23
1 files changed, 23 insertions, 0 deletions
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 <array>
+#include <cstdlib>
+#include <string>
+
+#include <unistd.h>
+
+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<char*, 2>{cmd.data(), nullptr};
+ ::execvpe(args[0], args.data(), nullptr);
+#else
+ std::_Exit(exit_code);
+#endif
+}