From: Daniel Salzman Date: Tue, 29 Jul 2025 12:39:19 +0000 (+0200) Subject: ctl: return Loading from status when not in the ServerAnswering state X-Git-Tag: v3.5.0~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5319e0a024c0061eae490dd67c74473a67bd94ec;p=thirdparty%2Fknot-dns.git ctl: return Loading from status when not in the ServerAnswering state --- diff --git a/src/knot/ctl/commands.c b/src/knot/ctl/commands.c index f389659ff1..b133cb706c 100644 --- a/src/knot/ctl/commands.c +++ b/src/knot/ctl/commands.c @@ -1943,43 +1943,44 @@ static int check_no_zone_txn(server_t *server, const char *action) static int server_status(ctl_args_t *args) { - const char *type = args->data[KNOT_CTL_IDX_TYPE]; - - if (type == NULL || strlen(type) == 0) { - return KNOT_EOK; - } - char buff[4096] = ""; - int ret; - if (strcasecmp(type, CMD_STATUS_VERSION) == 0) { - ret = snprintf(buff, sizeof(buff), "%s", PACKAGE_VERSION); - } else if (strcasecmp(type, CMD_STATUS_WORKERS) == 0) { - int running_bkg_wrk, wrk_queue; - worker_pool_status(args->server->workers, false, &running_bkg_wrk, &wrk_queue); - ret = snprintf(buff, sizeof(buff), "UDP workers: %zu, TCP workers: %zu, " - "XDP workers: %zu, background workers: %zu (running: %d, pending: %d)", - conf()->cache.srv_udp_threads, conf()->cache.srv_tcp_threads, - conf()->cache.srv_xdp_threads, conf()->cache.srv_bg_threads, - running_bkg_wrk, wrk_queue); - } else if (strcasecmp(type, CMD_STATUS_CONFIG) == 0) { - ret = snprintf(buff, sizeof(buff), "%s", configure_summary); - } else if (strcasecmp(type, CMD_STATUS_CERT) == 0) { - uint8_t pin[128]; - size_t pin_len = server_cert_pin(args->server, pin, sizeof(pin)); - if (pin_len > 0) { - ret = snprintf(buff, sizeof(buff), "%.*s", (int)pin_len, pin); - } else { - ret = snprintf(buff, sizeof(buff), STATUS_EMPTY); + const char *type = args->data[KNOT_CTL_IDX_TYPE]; + if (type == NULL || strlen(type) == 0) { + if (!(args->server->state & ServerAnswering)) { + args->data[KNOT_CTL_IDX_FILTERS] = CTL_FILTER_STATUS_LOADING; } } else { - return KNOT_EINVAL; - } - if (ret <= 0 || ret >= sizeof(buff)) { - return KNOT_ESPACE; - } + int ret; + if (strcasecmp(type, CMD_STATUS_VERSION) == 0) { + ret = snprintf(buff, sizeof(buff), "%s", PACKAGE_VERSION); + } else if (strcasecmp(type, CMD_STATUS_WORKERS) == 0) { + int running_bkg_wrk, wrk_queue; + worker_pool_status(args->server->workers, false, &running_bkg_wrk, &wrk_queue); + ret = snprintf(buff, sizeof(buff), "UDP workers: %zu, TCP workers: %zu, " + "XDP workers: %zu, background workers: %zu (running: %d, pending: %d)", + conf()->cache.srv_udp_threads, conf()->cache.srv_tcp_threads, + conf()->cache.srv_xdp_threads, conf()->cache.srv_bg_threads, + running_bkg_wrk, wrk_queue); + } else if (strcasecmp(type, CMD_STATUS_CONFIG) == 0) { + ret = snprintf(buff, sizeof(buff), "%s", configure_summary); + } else if (strcasecmp(type, CMD_STATUS_CERT) == 0) { + uint8_t pin[128]; + size_t pin_len = server_cert_pin(args->server, pin, sizeof(pin)); + if (pin_len > 0) { + ret = snprintf(buff, sizeof(buff), "%.*s", (int)pin_len, pin); + } else { + ret = snprintf(buff, sizeof(buff), STATUS_EMPTY); + } + } else { + return KNOT_EINVAL; + } + if (ret <= 0 || ret >= sizeof(buff)) { + return KNOT_ESPACE; + } - args->data[KNOT_CTL_IDX_DATA] = buff; + args->data[KNOT_CTL_IDX_DATA] = buff; + } return knot_ctl_send(args->ctl, KNOT_CTL_TYPE_DATA, &args->data); } diff --git a/src/knot/ctl/commands.h b/src/knot/ctl/commands.h index a787d15db3..ea2b32dff7 100644 --- a/src/knot/ctl/commands.h +++ b/src/knot/ctl/commands.h @@ -20,6 +20,8 @@ #define CTL_FILTER_FLUSH_OUTDIR "d" +#define CTL_FILTER_STATUS_LOADING "l" + #define CTL_FILTER_STATUS_ROLE "r" #define CTL_FILTER_STATUS_SERIAL "s" #define CTL_FILTER_STATUS_TRANSACTION "t" diff --git a/src/utils/knotc/commands.c b/src/utils/knotc/commands.c index ae922f4df7..1797536a10 100644 --- a/src/utils/knotc/commands.c +++ b/src/utils/knotc/commands.c @@ -175,8 +175,12 @@ static void format_data(cmd_args_t *args, knot_ctl_type_t data_type, (type != NULL) ? type : ""); } else if (value != NULL) { printf("%s", value); - *empty = false; + } else if (ctl_has_flag(filters, CTL_FILTER_STATUS_LOADING)) { + printf("Loading"); + } else { + printf("Running"); } + *empty = false; break; case CTL_STOP: case CTL_RELOAD: @@ -329,9 +333,6 @@ static void format_data(cmd_args_t *args, knot_ctl_type_t data_type, static void format_block(ctl_cmd_t cmd, bool failed, bool empty) { switch (cmd) { - case CTL_STATUS: - printf("%s\n", (failed || !empty) ? "" : "Running"); - break; case CTL_STOP: printf("%s\n", failed ? "" : "Stopped"); break; @@ -367,6 +368,7 @@ static void format_block(ctl_cmd_t cmd, bool failed, bool empty) case CTL_ZONE_PURGE: printf("%s\n", failed ? "" : "OK"); break; + case CTL_STATUS: case CTL_ZONE_STATUS: case CTL_ZONE_READ: case CTL_ZONE_DIFF: