From b149f47e32580958f4e89220be26f2129562dddf Mon Sep 17 00:00:00 2001 From: Bastian Krol Date: Sat, 22 Jun 2024 11:56:44 +0200 Subject: [PATCH] refactor(preload): init map in constructor instead of lazy init --- .../preload/src/libdash0envhook.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/images/dash0-instrumentation/preload/src/libdash0envhook.c b/images/dash0-instrumentation/preload/src/libdash0envhook.c index 928eed11..4c8710a5 100644 --- a/images/dash0-instrumentation/preload/src/libdash0envhook.c +++ b/images/dash0-instrumentation/preload/src/libdash0envhook.c @@ -19,23 +19,17 @@ secure_getenv_fun_ptr original_secure_getenv; int num_map_entries = 1; Entry map[1]; -bool init = false; char* default_node_options_value = "--require /opt/dash0/instrumentation/node.js/node_modules/@dash0/opentelemetry/src/index.js"; -void init_map() { - if (init) { - return; - } + +__attribute__((constructor)) static void setup(void) { Entry node_options_entry = { .key = "NODE_OPTIONS", .value = NULL }; map[0] = node_options_entry; - init = true; } char* _getenv(char* (*original_function)(const char* name), const char* name) { - init_map(); - if (strcmp(name, "NODE_OPTIONS") != 0) { return original_function(name); }