diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | cli/cli.c | 5 | ||||
-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 |
7 files changed, 40 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am index 666847dc32..510fbb3e55 100644 --- a/Makefile.am +++ b/Makefile.am @@ -936,6 +936,8 @@ DAEMON_FILES = \ daemon/static_threads.c \ daemon/commands.c \ daemon/commands.h \ + daemon/pipename.c \ + daemon/pipename.h \ daemon/unit_test.c \ daemon/unit_test.h \ $(NULL) @@ -1140,6 +1142,8 @@ endif NETDATACLI_FILES = \ daemon/commands.h \ + daemon/pipename.c \ + daemon/pipename.h \ libnetdata/buffer/buffer.c \ libnetdata/buffer/buffer.h \ cli/cli.c \ @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "cli.h" +#include "daemon/pipename.h" void error_int(int is_collector __maybe_unused, const char *prefix __maybe_unused, const char *file __maybe_unused, const char *function __maybe_unused, const unsigned long line __maybe_unused, const char *fmt, ... ) { FILE *fp = stderr; @@ -288,7 +289,9 @@ int main(int argc, char **argv) } req.data = buffer_create(128, NULL); - uv_pipe_connect(&req, &client_pipe, PIPENAME, connect_cb); + + const char *pipename = daemon_pipename(); + uv_pipe_connect(&req, &client_pipe, pipename, connect_cb); uv_run(loop, UV_RUN_DEFAULT); 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 */ |