summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:04 +0000
commita836a244a3d2bdd4da1ee2641e3e957850668cea (patch)
treecb87c75b3677fab7144f868435243f864048a1e6 /cli
parentAdding upstream version 1.38.1. (diff)
downloadnetdata-a836a244a3d2bdd4da1ee2641e3e957850668cea.tar.xz
netdata-a836a244a3d2bdd4da1ee2641e3e957850668cea.zip
Adding upstream version 1.39.0.upstream/1.39.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cli')
-rw-r--r--cli/README.md16
-rw-r--r--cli/cli.c49
2 files changed, 27 insertions, 38 deletions
diff --git a/cli/README.md b/cli/README.md
index 09f201745..8dd9cce88 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -1,14 +1,6 @@
-<!--
-title: "Netdata CLI"
-description: "The Netdata Agent includes a command-line experience for reloading health configuration, reopening log files, halting the daemon, and more."
-custom_edit_url: "https://github.com/netdata/netdata/edit/master/cli/README.md"
-sidebar_label: "Agent CLI"
-learn_status: "Published"
-learn_topic_type: "References"
-learn_rel_path: "References"
--->
+# Netdata Agent CLI
-# Netdata CLI
+The `netdatacli` executable provides a simple way to control the Netdata agent's operation.
You can see the commands `netdatacli` supports by executing it with `netdatacli` and entering `help` in
standard input. All commands are given as standard input to `netdatacli`.
@@ -37,8 +29,10 @@ ping
Return with 'pong' if agent is alive.
aclk-state [json]
Returns current state of ACLK and Cloud connection. (optionally in json)
+dumpconfig
+ Returns the current netdata.conf on stdout.
```
-Those commands are the same that can be sent to netdata via [signals](https://github.com/netdata/netdata/blob/master/daemon/README.md#command-line-options).
+See also the Netdata daemon [command line options](https://github.com/netdata/netdata/blob/master/daemon/README.md#command-line-options).
diff --git a/cli/cli.c b/cli/cli.c
index c14653f37..108c77626 100644
--- a/cli/cli.c
+++ b/cli/cli.c
@@ -10,9 +10,6 @@ static uv_shutdown_t shutdown_req;
static char command_string[MAX_COMMAND_LENGTH];
static unsigned command_string_size;
-static char response_string[MAX_COMMAND_LENGTH];
-static unsigned response_string_size;
-
static int exit_status;
struct command_context {
@@ -24,8 +21,10 @@ struct command_context {
cmd_status_t status;
};
-static void parse_command_reply(void)
+static void parse_command_reply(BUFFER *buf)
{
+ char *response_string = (char *) buffer_tostring(buf);
+ unsigned response_string_size = buffer_strlen(buf);
FILE *stream = NULL;
char *pos;
int syntax_error = 0;
@@ -64,28 +63,21 @@ static void parse_command_reply(void)
static void pipe_read_cb(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf)
{
- if (0 == nread) {
+ BUFFER *response = client->data;
+
+ if (0 == nread)
fprintf(stderr, "%s: Zero bytes read by command pipe.\n", __func__);
- } else if (UV_EOF == nread) {
-// fprintf(stderr, "EOF found in command pipe.\n");
- parse_command_reply();
- } else if (nread < 0) {
- fprintf(stderr, "%s: %s\n", __func__, uv_strerror(nread));
+ else if (UV_EOF == nread)
+ parse_command_reply(response);
+ else if (nread < 0) {
+ fprintf(stderr, "%s: %s\n", __func__, uv_strerror(nread));
+ (void)uv_read_stop((uv_stream_t *)client);
}
+ else
+ buffer_fast_rawcat(response, buf->base, nread);
- if (nread < 0) { /* stop stream due to EOF or error */
- (void)uv_read_stop((uv_stream_t *)client);
- } else if (nread) {
- size_t to_copy;
-
- to_copy = MIN((unsigned int) nread, MAX_COMMAND_LENGTH - 1 - response_string_size);
- memcpy(response_string + response_string_size, buf->base, to_copy);
- response_string_size += to_copy;
- response_string[response_string_size] = '\0';
- }
- if (buf && buf->len) {
+ if (buf && buf->len)
free(buf->base);
- }
}
static void alloc_cb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
@@ -104,8 +96,7 @@ static void shutdown_cb(uv_shutdown_t* req, int status)
(void)status;
/* receive reply */
- response_string_size = 0;
- response_string[0] = '\0';
+ client_pipe.data = req->data;
ret = uv_read_start((uv_stream_t *)&client_pipe, alloc_cb, pipe_read_cb);
if (ret) {
@@ -113,16 +104,17 @@ static void shutdown_cb(uv_shutdown_t* req, int status)
uv_close((uv_handle_t *)&client_pipe, NULL);
return;
}
-
}
static void pipe_write_cb(uv_write_t* req, int status)
{
int ret;
- (void)req;
(void)status;
+ uv_pipe_t *clientp = req->data;
+ shutdown_req.data = clientp->data;
+
ret = uv_shutdown(&shutdown_req, (uv_stream_t *)&client_pipe, shutdown_cb);
if (ret) {
fprintf(stderr, "uv_shutdown(): %s\n", uv_strerror(ret));
@@ -144,10 +136,11 @@ static void connect_cb(uv_connect_t* req, int status)
exit(-1);
}
if (0 == command_string_size) {
- s = fgets(command_string, MAX_COMMAND_LENGTH, stdin);
+ s = fgets(command_string, MAX_COMMAND_LENGTH - 1, stdin);
}
(void)s; /* We don't need input to communicate with the server */
command_string_size = strlen(command_string);
+ client_pipe.data = req->data;
write_req.data = &client_pipe;
write_buf.base = command_string;
@@ -191,11 +184,13 @@ int main(int argc, char **argv)
}
}
+ req.data = buffer_create(128, NULL);
uv_pipe_connect(&req, &client_pipe, PIPENAME, connect_cb);
uv_run(loop, UV_RUN_DEFAULT);
uv_close((uv_handle_t *)&client_pipe, NULL);
+ buffer_free(client_pipe.data);
return exit_status;
}