summaryrefslogtreecommitdiff
path: root/src/buildtool/system/system.cpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-03-07 13:23:13 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2022-03-08 13:46:45 +0100
commitd1f1da9ce54efa058681f2d78e427e08c1cb171b (patch)
tree2ee1d2f1d78615134c4b303d9ba6379a9243632f /src/buildtool/system/system.cpp
parent28abe1bf4d8c16af92e1ef3dc1f267399f0690b9 (diff)
downloadjustbuild-d1f1da9ce54efa058681f2d78e427e08c1cb171b.tar.gz
SystemCommand: Exit without cleanup on error and avoid logger
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
+}