diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2023-04-21 16:50:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-21 16:50:48 +0300 |
commit | 1fa60373300bbcd796201ee576ea11d3711f69e7 (patch) | |
tree | a68e9387ef942de38f493299a1deec2dedc006de /daemon | |
parent | 0d2c327ae58af5de35c9cb35a20cce9f59e92b9c (diff) |
Remove netdatacli response size limitation (#14906)
* Dump config
* Add charcat and rawcat
* Build incoming response in an buffer
* Allocate a buffer to hold the command response so that we dont have a 4K char limit
* Add a dumpconfig command to output the current netdata.conf
* Remove -W dumpconfig for now
* Fix typo
* Improve help message
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/commands.c | 38 | ||||
-rw-r--r-- | daemon/commands.h | 1 |
2 files changed, 26 insertions, 13 deletions
diff --git a/daemon/commands.c b/daemon/commands.c index 377a4002f3..fcb75b71c9 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) diff --git a/daemon/commands.h b/daemon/commands.h index 78bdcc779a..43a0ef96b6 100644 --- a/daemon/commands.h +++ b/daemon/commands.h @@ -26,6 +26,7 @@ typedef enum cmd { CMD_PING, CMD_ACLK_STATE, CMD_VERSION, + CMD_DUMPCONFIG, CMD_TOTAL_COMMANDS } cmd_t; |