diff options
author | vkalintiris <vasilis@netdata.cloud> | 2023-06-21 17:11:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-21 17:11:08 +0300 |
commit | 9325f2f0acda6a3c2c712e1b8c05e34ab54f05b7 (patch) | |
tree | 931abcdbbc3526102c0161cc5adca13ccd5e0d61 /daemon | |
parent | 97ed758f5bf84107b62d056abdb3e5a102fbc906 (diff) |
Allow overriding pipename from env (#15215)
This in turn will allow us to target specific agent processes
running with the commands cli.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/commands.c | 8 | ||||
-rw-r--r-- | daemon/commands.h | 6 | ||||
-rw-r--r-- | daemon/common.h | 1 | ||||
-rw-r--r-- | daemon/pipename.c | 17 | ||||
-rw-r--r-- | daemon/pipename.h | 8 |
5 files changed, 32 insertions, 8 deletions
diff --git a/daemon/commands.c b/daemon/commands.c index 0a4c655899..5e55ed5c2f 100644 --- a/daemon/commands.c +++ b/daemon/commands.c @@ -644,14 +644,18 @@ static void command_thread(void *arg) command_thread_error = ret; goto error_after_pipe_init; } - (void)uv_fs_unlink(loop, &req, PIPENAME, NULL); + + const char *pipename = daemon_pipename(); + + (void)uv_fs_unlink(loop, &req, pipename, NULL); uv_fs_req_cleanup(&req); - ret = uv_pipe_bind(&server_pipe, PIPENAME); + ret = uv_pipe_bind(&server_pipe, pipename); if (ret) { error("uv_pipe_bind(): %s", uv_strerror(ret)); command_thread_error = ret; goto error_after_pipe_bind; } + ret = uv_listen((uv_stream_t *)&server_pipe, SOMAXCONN, connection_cb); if (ret) { /* Fallback to backlog of 1 */ diff --git a/daemon/commands.h b/daemon/commands.h index 43a0ef96b6..368a70a0f4 100644 --- a/daemon/commands.h +++ b/daemon/commands.h @@ -3,12 +3,6 @@ #ifndef NETDATA_COMMANDS_H #define NETDATA_COMMANDS_H 1 -#ifdef _WIN32 -# define PIPENAME "\\\\?\\pipe\\netdata-cli" -#else -# define PIPENAME "/tmp/netdata-ipc" -#endif - #define MAX_COMMAND_LENGTH 4096 #define MAX_EXIT_STATUS_LENGTH 23 /* Can't ever be bigger than "X-18446744073709551616" */ diff --git a/daemon/common.h b/daemon/common.h index bd7efd3482..4736c61b17 100644 --- a/daemon/common.h +++ b/daemon/common.h @@ -89,6 +89,7 @@ #include "static_threads.h" #include "signals.h" #include "commands.h" +#include "pipename.h" #include "analytics.h" // global netdata daemon variables diff --git a/daemon/pipename.c b/daemon/pipename.c new file mode 100644 index 0000000000..70b6a25b42 --- /dev/null +++ b/daemon/pipename.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "pipename.h" + +#include <stdlib.h> + +const char *daemon_pipename(void) { + const char *pipename = getenv("NETDATA_PIPENAME"); + if (pipename) + return pipename; + +#ifdef _WIN32 + return "\\\\?\\pipe\\netdata-cli"; +#else + return "/tmp/netdata-ipc"; +#endif +} diff --git a/daemon/pipename.h b/daemon/pipename.h new file mode 100644 index 0000000000..6ca6e8d08d --- /dev/null +++ b/daemon/pipename.h @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef DAEMON_PIPENAME_H +#define DAEMON_PIPENAME_H + +const char *daemon_pipename(void); + +#endif /* DAEMON_PIPENAME_H */ |