Skip to content

Commit

Permalink
fix: electron (#685)
Browse files Browse the repository at this point in the history
* 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

* fix gcc warning

* only enable workaround for linux and glibc
  • Loading branch information
Teo Koon Peng committed Aug 5, 2020
1 parent 9523d21 commit 5c7446d
Showing 1 changed file with 27 additions and 0 deletions.
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

0 comments on commit 5c7446d

Please sign in to comment.