diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-07-26 19:55:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-26 19:55:53 +0300 |
commit | cca0d2649c628a9fc4b9ee4502b501c821feac8b (patch) | |
tree | bf5b1e26e972666eb372dacc3f7ab54625f9314b /daemon | |
parent | 85d122f8a6c4709943825c1fcf9bffa784bd5620 (diff) |
detect the path the netdata-claim.sh script is in (#15556)
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/commands.c | 8 | ||||
-rw-r--r-- | daemon/daemon.c | 26 | ||||
-rw-r--r-- | daemon/daemon.h | 3 |
3 files changed, 21 insertions, 16 deletions
diff --git a/daemon/commands.c b/daemon/commands.c index ec99269f37..8ab45c1e6e 100644 --- a/daemon/commands.c +++ b/daemon/commands.c @@ -407,7 +407,7 @@ static void pipe_write_cb(uv_write_t* req, int status) uv_close((uv_handle_t *)client, pipe_close_cb); --clients; buffer_free(client->data); - netdata_log_info("Command Clients = %u\n", clients); + // netdata_log_info("Command Clients = %u", clients); } static inline void add_char_to_command_reply(BUFFER *reply_string, unsigned *reply_string_size, char character) @@ -557,7 +557,7 @@ static void pipe_read_cb(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf if (nread < 0 && UV_EOF != nread) { uv_close((uv_handle_t *)client, pipe_close_cb); --clients; - netdata_log_info("Command Clients = %u\n", clients); + // netdata_log_info("Command Clients = %u", clients); } } @@ -593,7 +593,7 @@ static void connection_cb(uv_stream_t *server, int status) } ++clients; - netdata_log_info("Command Clients = %u\n", clients); + // netdata_log_info("Command Clients = %u", clients); /* Start parsing a new command */ cmd_ctx->command_string_size = 0; cmd_ctx->command_string[0] = '\0'; @@ -603,7 +603,7 @@ static void connection_cb(uv_stream_t *server, int status) netdata_log_error("uv_read_start(): %s", uv_strerror(ret)); uv_close((uv_handle_t *)client, pipe_close_cb); --clients; - netdata_log_info("Command Clients = %u\n", clients); + // netdata_log_info("Command Clients = %u", clients); return; } } diff --git a/daemon/daemon.c b/daemon/daemon.c index 0d1d173246..c7f0b51c6d 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -4,11 +4,11 @@ #include <sched.h> char pidfile[FILENAME_MAX + 1] = ""; -char claimingdirectory[FILENAME_MAX + 1]; -char exepath[FILENAME_MAX + 1]; +char claiming_directory[FILENAME_MAX + 1]; +char netdata_exe_path[FILENAME_MAX + 1]; +char netdata_exe_file[FILENAME_MAX + 1]; -void get_netdata_execution_path(void) -{ +void get_netdata_execution_path(void) { int ret; size_t exepath_size = 0; struct passwd *passwd = NULL; @@ -17,14 +17,18 @@ void get_netdata_execution_path(void) passwd = getpwuid(getuid()); user = (passwd && passwd->pw_name) ? passwd->pw_name : ""; - exepath_size = sizeof(exepath) - 1; - ret = uv_exepath(exepath, &exepath_size); + exepath_size = sizeof(netdata_exe_file) - 1; + ret = uv_exepath(netdata_exe_file, &exepath_size); if (0 != ret) { - netdata_log_error("uv_exepath(\"%s\", %u) (user: %s) failed (%s).", exepath, (unsigned)exepath_size, user, - uv_strerror(ret)); + netdata_log_error("uv_exepath(\"%s\", %u) (user: %s) failed (%s).", netdata_exe_file, (unsigned)exepath_size, user, + uv_strerror(ret)); fatal("Cannot start netdata without getting execution path."); } - exepath[exepath_size] = '\0'; + + netdata_exe_file[exepath_size] = '\0'; + + strcpy(netdata_exe_path, netdata_exe_file); + dirname(netdata_exe_path); } static void chown_open_file(int fd, uid_t uid, gid_t gid) { @@ -99,7 +103,7 @@ void prepare_required_directories(uid_t uid, gid_t gid) { change_dir_ownership(netdata_configured_varlib_dir, uid, gid, false); change_dir_ownership(netdata_configured_lock_dir, uid, gid, false); change_dir_ownership(netdata_configured_log_dir, uid, gid, false); - change_dir_ownership(claimingdirectory, uid, gid, false); + change_dir_ownership(claiming_directory, uid, gid, false); char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s/registry", netdata_configured_varlib_dir); @@ -516,7 +520,7 @@ int become_daemon(int dont_fork, const char *user) sched_setscheduler_set(); // Set claiming directory based on user config directory with correct ownership - snprintfz(claimingdirectory, FILENAME_MAX, "%s/cloud.d", netdata_configured_varlib_dir); + snprintfz(claiming_directory, FILENAME_MAX, "%s/cloud.d", netdata_configured_varlib_dir); if(user && *user) { if(become_user(user, pidfd) != 0) { diff --git a/daemon/daemon.h b/daemon/daemon.h index 2a8a58ec66..7c4c2ce7e6 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -13,6 +13,7 @@ void send_statistics(const char *action, const char *action_result, const char * void get_netdata_execution_path(void); extern char pidfile[]; -extern char exepath[]; +extern char netdata_exe_file[]; +extern char netdata_exe_path[]; #endif /* NETDATA_DAEMON_H */ |