mirror of
https://github.com/electron/electron.git
synced 2026-01-10 16:08:06 -05:00
fix: enable crashpad for ELECTRON_RUN_AS_NODE processes (#36460)
* wip: enable crashpad for node processes
fix: add PID testing method
wip: plumb fd into child_process in node
* node::ProcessInitializationFlags::kNoDefaultSignalHandling
* chore: clean up debug logging
* chore: gate platform includes
* test: clean up node process test
* fix: pass pid in node_main
* chore: cleanup impl
* chore: fixup patch method definition
* fix: expose bound methods to node_main
* fix: remove bound methods
* fix: crashpad connection for all ELECTRON_RUN_AS_NODE processes
* chore: fix typo
* chore: address review feedback
* chore: delay crashpad initialization
* chore: ensure options.env, code hygiene
* chore: add argv test, check for process.env over {}
* fix: fix test, return options.env immutability
Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
Co-authored-by: Jeremy Rose <jeremya@chromium.org>
Co-authored-by: VerteDinde <vertedinde@electronjs.org>
This commit is contained in:
@@ -34,6 +34,14 @@
|
||||
#include "chrome/child/v8_crashpad_support_win.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
#include "base/environment.h"
|
||||
#include "base/posix/global_descriptors.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "components/crash/core/app/crash_switches.h" // nogncheck
|
||||
#include "content/public/common/content_descriptors.h"
|
||||
#endif
|
||||
|
||||
#if !IS_MAS_BUILD()
|
||||
#include "components/crash/core/app/crashpad.h" // nogncheck
|
||||
#include "shell/app/electron_crash_reporter_client.h"
|
||||
@@ -110,15 +118,20 @@ int NodeMain(int argc, char* argv[]) {
|
||||
v8_crashpad_support::SetUp();
|
||||
#endif
|
||||
|
||||
// TODO(deepak1556): Enable crashpad support on linux for
|
||||
// ELECTRON_RUN_AS_NODE processes.
|
||||
// Refs https://github.com/electron/electron/issues/36030
|
||||
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_MAC) && !IS_MAS_BUILD())
|
||||
ElectronCrashReporterClient::Create();
|
||||
crash_reporter::InitializeCrashpad(false, "node");
|
||||
crash_keys::SetCrashKeysFromCommandLine(
|
||||
*base::CommandLine::ForCurrentProcess());
|
||||
crash_keys::SetPlatformCrashKey();
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
auto os_env = base::Environment::Create();
|
||||
std::string fd_string, pid_string;
|
||||
if (os_env->GetVar("CRASHDUMP_SIGNAL_FD", &fd_string) &&
|
||||
os_env->GetVar("CRASHPAD_HANDLER_PID", &pid_string)) {
|
||||
int fd = -1, pid = -1;
|
||||
DCHECK(base::StringToInt(fd_string, &fd));
|
||||
DCHECK(base::StringToInt(pid_string, &pid));
|
||||
base::GlobalDescriptors::GetInstance()->Set(kCrashDumpSignal, fd);
|
||||
// Following API is unsafe in multi-threaded scenario, but at this point
|
||||
// we are still single threaded.
|
||||
os_env->UnSetVar("CRASHDUMP_SIGNAL_FD");
|
||||
os_env->UnSetVar("CRASHPAD_HANDLER_PID");
|
||||
}
|
||||
#endif
|
||||
|
||||
int exit_code = 1;
|
||||
@@ -158,6 +171,29 @@ int NodeMain(int argc, char* argv[]) {
|
||||
return result->exit_code();
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
// On Linux, initialize crashpad after Nodejs init phase so that
|
||||
// crash and termination signal handlers can be set by the crashpad client.
|
||||
if (!pid_string.empty()) {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
command_line->AppendSwitchASCII(
|
||||
crash_reporter::switches::kCrashpadHandlerPid, pid_string);
|
||||
ElectronCrashReporterClient::Create();
|
||||
crash_reporter::InitializeCrashpad(false, "node");
|
||||
crash_keys::SetCrashKeysFromCommandLine(
|
||||
*base::CommandLine::ForCurrentProcess());
|
||||
crash_keys::SetPlatformCrashKey();
|
||||
// Ensure the flags and env variable does not propagate to userland.
|
||||
command_line->RemoveSwitch(crash_reporter::switches::kCrashpadHandlerPid);
|
||||
}
|
||||
#elif BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_MAC) && !IS_MAS_BUILD())
|
||||
ElectronCrashReporterClient::Create();
|
||||
crash_reporter::InitializeCrashpad(false, "node");
|
||||
crash_keys::SetCrashKeysFromCommandLine(
|
||||
*base::CommandLine::ForCurrentProcess());
|
||||
crash_keys::SetPlatformCrashKey();
|
||||
#endif
|
||||
|
||||
gin::V8Initializer::LoadV8Snapshot(
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user