fix: record helper error messages in electron_main_mac (#37807)
This commit is contained in:
parent
e31f101712
commit
f40bd2da23
1 changed files with 26 additions and 8 deletions
|
@ -18,6 +18,14 @@
|
|||
#include "sandbox/mac/seatbelt_exec.h" // nogncheck
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
// abort_report_np() records the message in a special section that both the
|
||||
// system CrashReporter and Crashpad collect in crash reports. Using a Crashpad
|
||||
// Annotation would be preferable, but this executable cannot depend on
|
||||
// Crashpad directly.
|
||||
void abort_report_np(const char* fmt, ...);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
[[maybe_unused]] bool IsEnvSet(const char* name) {
|
||||
|
@ -25,6 +33,20 @@ namespace {
|
|||
return indicator && indicator[0] != '\0';
|
||||
}
|
||||
|
||||
#if defined(HELPER_EXECUTABLE) && !IS_MAS_BUILD()
|
||||
[[noreturn]] void FatalError(const char* format, ...) {
|
||||
va_list valist;
|
||||
va_start(valist, format);
|
||||
char message[4096];
|
||||
if (vsnprintf(message, sizeof(message), format, valist) >= 0) {
|
||||
fputs(message, stderr);
|
||||
abort_report_np("%s", message);
|
||||
}
|
||||
va_end(valist);
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
@ -42,27 +64,23 @@ int main(int argc, char* argv[]) {
|
|||
uint32_t exec_path_size = 0;
|
||||
int rv = _NSGetExecutablePath(NULL, &exec_path_size);
|
||||
if (rv != -1) {
|
||||
fprintf(stderr, "_NSGetExecutablePath: get length failed\n");
|
||||
abort();
|
||||
FatalError("_NSGetExecutablePath: get length failed.");
|
||||
}
|
||||
|
||||
auto exec_path = std::make_unique<char[]>(exec_path_size);
|
||||
rv = _NSGetExecutablePath(exec_path.get(), &exec_path_size);
|
||||
if (rv != 0) {
|
||||
fprintf(stderr, "_NSGetExecutablePath: get path failed\n");
|
||||
abort();
|
||||
FatalError("_NSGetExecutablePath: get path failed.");
|
||||
}
|
||||
sandbox::SeatbeltExecServer::CreateFromArgumentsResult seatbelt =
|
||||
sandbox::SeatbeltExecServer::CreateFromArguments(exec_path.get(), argc,
|
||||
argv);
|
||||
if (seatbelt.sandbox_required) {
|
||||
if (!seatbelt.server) {
|
||||
fprintf(stderr, "Failed to create seatbelt sandbox server.\n");
|
||||
abort();
|
||||
FatalError("Failed to create seatbelt sandbox server.");
|
||||
}
|
||||
if (!seatbelt.server->InitializeSandbox()) {
|
||||
fprintf(stderr, "Failed to initialize sandbox.\n");
|
||||
abort();
|
||||
FatalError("Failed to initialize sandbox.");
|
||||
}
|
||||
}
|
||||
#endif // defined(HELPER_EXECUTABLE) && !IS_MAS_BUILD
|
||||
|
|
Loading…
Reference in a new issue