@cryptotaxi247 / netdata-1 / commits / 9325f2f0a

Allow overriding pipename from env (#15215)

This in turn will allow us to target specific agent processes running with the commands cli.

vkalintiris committed Jun 21, 2023 at 17:11 UTC 9325f2f0acda6a3c2c712e1b8c05e34ab54f05b7
7 files changed +40 -9
Makefile.am
+4
@@ -936,6 +936,8 @@ DAEMON_FILES = \
936 daemon/static_threads.c \
937 daemon/commands.c \
938 daemon/commands.h \
939 + daemon/pipename.c \
940 + daemon/pipename.h \
941 daemon/unit_test.c \
942 daemon/unit_test.h \
943 $(NULL)
@@ -1140,6 +1142,8 @@ endif
1142
1143 NETDATACLI_FILES = \
1144 daemon/commands.h \
1145 + daemon/pipename.c \
1146 + daemon/pipename.h \
1147 libnetdata/buffer/buffer.c \
1148 libnetdata/buffer/buffer.h \
1149 cli/cli.c \
cli/cli.c
+4 -1
@@ -1,6 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "cli.h"
4 +#include "daemon/pipename.h"
5
6 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, ... ) {
7 FILE *fp = stderr;
@@ -288,7 +289,9 @@ int main(int argc, char **argv)
289 }
290
291 req.data = buffer_create(128, NULL);
291 - uv_pipe_connect(&req, &client_pipe, PIPENAME, connect_cb);
292 +
293 + const char *pipename = daemon_pipename();
294 + uv_pipe_connect(&req, &client_pipe, pipename, connect_cb);
295
296 uv_run(loop, UV_RUN_DEFAULT);
297
daemon/commands.c
+6 -2
@@ -644,14 +644,18 @@ static void command_thread(void *arg)
644 command_thread_error = ret;
645 goto error_after_pipe_init;
646 }
647 - (void)uv_fs_unlink(loop, &req, PIPENAME, NULL);
647 +
648 + const char *pipename = daemon_pipename();
649 +
650 + (void)uv_fs_unlink(loop, &req, pipename, NULL);
651 uv_fs_req_cleanup(&req);
649 - ret = uv_pipe_bind(&server_pipe, PIPENAME);
652 + ret = uv_pipe_bind(&server_pipe, pipename);
653 if (ret) {
654 error("uv_pipe_bind(): %s", uv_strerror(ret));
655 command_thread_error = ret;
656 goto error_after_pipe_bind;
657 }
658 +
659 ret = uv_listen((uv_stream_t *)&server_pipe, SOMAXCONN, connection_cb);
660 if (ret) {
661 /* Fallback to backlog of 1 */
daemon/commands.h
-6
@@ -3,12 +3,6 @@
3 #ifndef NETDATA_COMMANDS_H
4 #define NETDATA_COMMANDS_H 1
5
6 -#ifdef _WIN32
7 -# define PIPENAME "\\\\?\\pipe\\netdata-cli"
8 -#else
9 -# define PIPENAME "/tmp/netdata-ipc"
10 -#endif
11 -
6 #define MAX_COMMAND_LENGTH 4096
7 #define MAX_EXIT_STATUS_LENGTH 23 /* Can't ever be bigger than "X-18446744073709551616" */
8
daemon/common.h
+1
@@ -89,6 +89,7 @@
89 #include "static_threads.h"
90 #include "signals.h"
91 #include "commands.h"
92 +#include "pipename.h"
93 #include "analytics.h"
94
95 // global netdata daemon variables
daemon/pipename.c new
+17
@@ -0,0 +1,17 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#include "pipename.h"
4 +
5 +#include <stdlib.h>
6 +
7 +const char *daemon_pipename(void) {
8 + const char *pipename = getenv("NETDATA_PIPENAME");
9 + if (pipename)
10 + return pipename;
11 +
12 +#ifdef _WIN32
13 + return "\\\\?\\pipe\\netdata-cli";
14 +#else
15 + return "/tmp/netdata-ipc";
16 +#endif
17 +}
daemon/pipename.h new
+8
@@ -0,0 +1,8 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef DAEMON_PIPENAME_H
4 +#define DAEMON_PIPENAME_H
5 +
6 +const char *daemon_pipename(void);
7 +
8 +#endif /* DAEMON_PIPENAME_H */