summaryrefslogtreecommitdiff
path: root/src/buildtool/system/system.cpp
blob: 5f389b9a05e17e9719451942355add2827d40daf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
}