diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-05-08 16:27:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-05-08 16:27:04 +0000 |
commit | a836a244a3d2bdd4da1ee2641e3e957850668cea (patch) | |
tree | cb87c75b3677fab7144f868435243f864048a1e6 /daemon/commands.c | |
parent | Adding upstream version 1.38.1. (diff) | |
download | netdata-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 'daemon/commands.c')
-rw-r--r-- | daemon/commands.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/daemon/commands.c b/daemon/commands.c index 377a4002..fcb75b71 100644 --- a/daemon/commands.c +++ b/daemon/commands.c @@ -47,6 +47,7 @@ static cmd_status_t cmd_write_config_execute(char *args, char **message); static cmd_status_t cmd_ping_execute(char *args, char **message); static cmd_status_t cmd_aclk_state(char *args, char **message); static cmd_status_t cmd_version(char *args, char **message); +static cmd_status_t cmd_dumpconfig(char *args, char **message); static command_info_t command_info_array[] = { {"help", cmd_help_execute, CMD_TYPE_HIGH_PRIORITY}, // show help menu @@ -61,7 +62,8 @@ static command_info_t command_info_array[] = { {"write-config", cmd_write_config_execute, CMD_TYPE_ORTHOGONAL}, {"ping", cmd_ping_execute, CMD_TYPE_ORTHOGONAL}, {"aclk-state", cmd_aclk_state, CMD_TYPE_ORTHOGONAL}, - {"version", cmd_version, CMD_TYPE_ORTHOGONAL} + {"version", cmd_version, CMD_TYPE_ORTHOGONAL}, + {"dumpconfig", cmd_dumpconfig, CMD_TYPE_ORTHOGONAL} }; /* Mutexes for commands of type CMD_TYPE_ORTHOGONAL */ @@ -127,6 +129,8 @@ static cmd_status_t cmd_help_execute(char *args, char **message) " Return with 'pong' if agent is alive.\n" "aclk-state [json]\n" " Returns current state of ACLK and Cloud connection. (optionally in json).\n" + "dumpconfig\n" + " Returns the current netdata.conf on stdout.\n" "version\n" " Returns the netdata version.\n", MAX_COMMAND_LENGTH - 1); @@ -330,6 +334,17 @@ static cmd_status_t cmd_version(char *args, char **message) return CMD_STATUS_SUCCESS; } +static cmd_status_t cmd_dumpconfig(char *args, char **message) +{ + (void)args; + + BUFFER *wb = buffer_create(1024, NULL); + config_generate(wb, 0); + *message = strdupz(buffer_tostring(wb)); + buffer_free(wb); + return CMD_STATUS_SUCCESS; +} + static void cmd_lock_exclusive(unsigned index) { (void)index; @@ -393,32 +408,30 @@ static void pipe_write_cb(uv_write_t* req, int status) uv_close((uv_handle_t *)client, pipe_close_cb); --clients; - freez(client->data); + buffer_free(client->data); info("Command Clients = %u\n", clients); } -static inline void add_char_to_command_reply(char *reply_string, unsigned *reply_string_size, char character) +static inline void add_char_to_command_reply(BUFFER *reply_string, unsigned *reply_string_size, char character) { - reply_string[(*reply_string_size)++] = character; + buffer_fast_charcat(reply_string, character); + *reply_string_size +=1; } -static inline void add_string_to_command_reply(char *reply_string, unsigned *reply_string_size, char *str) +static inline void add_string_to_command_reply(BUFFER *reply_string, unsigned *reply_string_size, char *str) { unsigned len; len = strlen(str); - - if (MAX_COMMAND_LENGTH - 1 < len + *reply_string_size) - len = MAX_COMMAND_LENGTH - *reply_string_size - 1; - - strncpyz(reply_string + *reply_string_size, str, len); + buffer_fast_strcat(reply_string, str, len); *reply_string_size += len; } static void send_command_reply(struct command_context *cmd_ctx, cmd_status_t status, char *message) { int ret; - char *reply_string = mallocz(MAX_COMMAND_LENGTH); + BUFFER *reply_string = buffer_create(128, NULL); + char exit_status_string[MAX_EXIT_STATUS_LENGTH + 1] = {'\0', }; unsigned reply_string_size = 0; uv_buf_t write_buf; @@ -436,13 +449,12 @@ static void send_command_reply(struct command_context *cmd_ctx, cmd_status_t sta cmd_ctx->write_req.data = client; client->data = reply_string; - write_buf.base = reply_string; + write_buf.base = reply_string->buffer; write_buf.len = reply_string_size; ret = uv_write(&cmd_ctx->write_req, (uv_stream_t *)client, &write_buf, 1, pipe_write_cb); if (ret) { error("uv_write(): %s", uv_strerror(ret)); } - info("COMMAND: Sending reply: \"%s\"", reply_string); } cmd_status_t execute_command(cmd_t idx, char *args, char **message) |