static bool BreakpadInitInternal() {
    int fdServer, fdClient;
    if (!CreateReportChannel(fdServer, fdClient)) {
        crashDumpLogs.Warn("Failed to start crash logging server");
        return false;
    }
    // allocate exec arguments before forking to avoid malloc use
    std::string fdServerStr = std::to_string(fdServer);
    std::string crashDir = CrashDumpPath();
    std::string exePath = CrashServerPath();

    crashDumpLogs.Debug("Starting crash server with the following command line: %s %s %s <child pid>",
                        exePath.c_str(),
                        fdServerStr.c_str(),
                        crashDir.c_str());

    pid_t pid = fork();
    if (pid == -1) {
        crashDumpLogs.Warn("Failed to start crash logging server: %s", strerror(errno));
        return false;
    } else if (pid != 0) { // Breakpad server MUST be in parent of engine process
        char pidStr[16];
        snprintf(pidStr, sizeof(pidStr), "%d", pid);
        const char* args[] = { exePath.c_str(), fdServerStr.c_str(), crashDir.c_str(), pidStr, nullptr };
        execv(exePath.c_str(), const_cast<char * const *>(args));
        _exit(1);
    }

    crashHandler.reset(new google_breakpad::ExceptionHandler(
                           google_breakpad::MinidumpDescriptor{}, nullptr, nullptr,
                           nullptr, true, fdClient));
    return true;
}
Beispiel #2
0
static bool BreakpadInitInternal() {
    std::string crashDir = CrashDumpPath();
    std::string executable = CrashServerPath();
    std::string pipeName = GetSingletonSocketPath() + "-crash";
    DWORD pid = GetCurrentProcessId();
    std::string cmdLine = "\"" + executable + "\" " + pipeName + " \"" + crashDir + " \" " + std::to_string(pid);
    crashDumpLogs.Debug("Starting crash server with the following command line: %s", cmdLine);

    STARTUPINFOA startInfo{};
    startInfo.cb = sizeof(startInfo);
    startInfo.dwFlags = 0;

    PROCESS_INFORMATION procInfo;
    if (!CreateProcessA(&executable[0], &cmdLine[0],
        NULL, NULL, FALSE, 0, NULL, NULL,
        &startInfo, &procInfo))
    {
        crashDumpLogs.Warn("Failed to start crash logging server: %s", Win32StrError(GetLastError()));
        return false;
    }

    CloseHandle(procInfo.hProcess);
    CloseHandle(procInfo.hThread);

    std::wstring wPipeName = Str::UTF8To16(pipeName);
    crashHandler.reset(new google_breakpad::ExceptionHandler(
        Str::UTF8To16(crashDir),
        nullptr,
        nullptr,
        nullptr,
        google_breakpad::ExceptionHandler::HANDLER_ALL,
        MiniDumpNormal,
        wPipeName.c_str(),
        nullptr));
    return true;
}