Skip to content

Commit 3eb5077

Browse files
Teo Koon PengMinggang Wang
authored andcommitted
fix: electron (#685)
* 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
1 parent 4b4761b commit 3eb5077

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/addon.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,34 @@
2222
#include "rcutils/macros.h"
2323
#include "shadow_node.hpp"
2424

25+
bool IsRunningInElectronRenderer() {
26+
auto global = Nan::GetCurrentContext()->Global();
27+
auto process =
28+
Nan::To<v8::Object>(Nan::Get(global, Nan::New("process").ToLocalChecked())
29+
.ToLocalChecked())
30+
.ToLocalChecked();
31+
auto process_type =
32+
Nan::Get(process, Nan::New("type").ToLocalChecked()).ToLocalChecked();
33+
return process_type->StrictEquals(Nan::New("renderer").ToLocalChecked());
34+
}
35+
2536
void InitModule(v8::Local<v8::Object> exports) {
37+
// workaround process name mangling by chromium
38+
//
39+
// rcl logging uses `program_invocation_name` to determine the log file,
40+
// chromium mangles the program name to include all args, this causes a
41+
// ENAMETOOLONG error when starting ros. Workaround is to replace the first
42+
// occurence of ' -' with the null terminator. see:
43+
// https://unix.stackexchange.com/questions/432419/unexpected-non-null-encoding-of-proc-pid-cmdline
44+
#if defined(__linux__) && defined(__GLIBC__)
45+
if (IsRunningInElectronRenderer()) {
46+
auto prog_name = program_invocation_name;
47+
auto end = strstr(prog_name, " -");
48+
assert(end);
49+
prog_name[end - prog_name] = 0;
50+
}
51+
#endif
52+
2653
v8::Local<v8::Context> context = exports->GetIsolate()->GetCurrentContext();
2754

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

0 commit comments

Comments
 (0)