Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: electron #685

Merged
merged 3 commits into from
Aug 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,34 @@
#include "rcutils/macros.h"
#include "shadow_node.hpp"

bool IsRunningInElectronRenderer() {
auto global = Nan::GetCurrentContext()->Global();
auto process =
Nan::To<v8::Object>(Nan::Get(global, Nan::New("process").ToLocalChecked())
.ToLocalChecked())
.ToLocalChecked();
auto process_type =
Nan::Get(process, Nan::New("type").ToLocalChecked()).ToLocalChecked();
return process_type->StrictEquals(Nan::New("renderer").ToLocalChecked());
}

void InitModule(v8::Local<v8::Object> exports) {
// workaround process name mangling by chromium
//
// rcl logging uses `program_invocation_name` to determine the log file,
// chromium mangles the program name to include all args, this causes a
// ENAMETOOLONG error when starting ros. Workaround is to replace the first
// occurence of ' -' with the null terminator. see:
// https://unix.stackexchange.com/questions/432419/unexpected-non-null-encoding-of-proc-pid-cmdline
#if defined(__linux__) && defined(__GLIBC__)
if (IsRunningInElectronRenderer()) {
auto prog_name = program_invocation_name;
auto end = strstr(prog_name, " -");
assert(end);
prog_name[end - prog_name] = 0;
}
#endif

v8::Local<v8::Context> context = exports->GetIsolate()->GetCurrentContext();

for (uint32_t i = 0; i < rclnodejs::binding_methods.size(); i++) {
Expand Down