mirror of
https://gitlab.nic.cz/knot/knot-dns.git
synced 2026-02-03 18:49:28 -05:00
ctl: remove running from status with arguments, fix snprintf err return
This commit is contained in:
parent
7d924855f2
commit
18f37a0802
3 changed files with 55 additions and 30 deletions
12
configure.ac
12
configure.ac
|
|
@ -536,8 +536,7 @@ AM_CONDITIONAL([HAVE_SPHINXBUILD], test "$SPHINXBUILD" != "false")
|
|||
AM_CONDITIONAL([HAVE_PDFLATEX], test "$PDFLATEX" != "false")
|
||||
AM_CONDITIONAL([HAVE_MAKEINFO], test "$MAKEINFO" != "false")
|
||||
|
||||
result_msg_base="
|
||||
$PACKAGE $VERSION
|
||||
result_msg_base=" $PACKAGE $VERSION
|
||||
|
||||
Target: $host_os $host_cpu
|
||||
Compiler: ${CC}
|
||||
|
|
@ -573,11 +572,12 @@ result_msg_base="
|
|||
Dnstap support: ${opt_dnstap}
|
||||
Code coverage: ${enable_code_coverage}
|
||||
Bash completions: ${bash_completions_output}
|
||||
PKCS #11 support: ${enable_pkcs11}
|
||||
"
|
||||
PKCS #11 support: ${enable_pkcs11}"
|
||||
|
||||
result_msg_esc=$(echo -n "$result_msg_base" | sed '$!s/$/\\n/' | tr -d '\n')
|
||||
result_msg_add="
|
||||
$result_msg_base
|
||||
|
||||
result_msg_esc=$(echo -n "$result_msg_base" | sed 's/$/\\n/' | tr -d '\n')
|
||||
result_msg_add="$result_msg_base
|
||||
Continue with 'make' command
|
||||
"
|
||||
|
||||
|
|
|
|||
|
|
@ -966,7 +966,7 @@ static int send_stats_ctr(mod_ctr_t *ctr, ctl_args_t *args, knot_ctl_data_t *dat
|
|||
if (ctr->count == 1) {
|
||||
int ret = snprintf(value, sizeof(value), "%"PRIu64, ctr->counter);
|
||||
if (ret <= 0 || ret >= sizeof(value)) {
|
||||
return ret;
|
||||
return KNOT_ESPACE;
|
||||
}
|
||||
|
||||
(*data)[KNOT_CTL_IDX_ID] = NULL;
|
||||
|
|
@ -998,13 +998,13 @@ static int send_stats_ctr(mod_ctr_t *ctr, ctl_args_t *args, knot_ctl_data_t *dat
|
|||
ret = snprintf(index, sizeof(index), "%u", i);
|
||||
}
|
||||
if (ret <= 0 || ret >= sizeof(index)) {
|
||||
return ret;
|
||||
return KNOT_ESPACE;
|
||||
}
|
||||
|
||||
ret = snprintf(value, sizeof(value), "%"PRIu64,
|
||||
ret = snprintf(value, sizeof(value), "%"PRIu64,
|
||||
ctr->counters[i]);
|
||||
if (ret <= 0 || ret >= sizeof(value)) {
|
||||
return ret;
|
||||
return KNOT_ESPACE;
|
||||
}
|
||||
|
||||
(*data)[KNOT_CTL_IDX_ID] = index;
|
||||
|
|
@ -1147,27 +1147,47 @@ static int ctl_zone(ctl_args_t *args, ctl_cmd_t cmd)
|
|||
}
|
||||
}
|
||||
|
||||
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[2048] = "";
|
||||
|
||||
int ret;
|
||||
if (strcasecmp(type, "version") == 0) {
|
||||
ret = snprintf(buff, sizeof(buff), "Version: %s", PACKAGE_VERSION);
|
||||
} else if (strcasecmp(type, "workers") == 0) {
|
||||
ret = snprintf(buff, sizeof(buff), "UDP workers: %zu, TCP workers %zu, "
|
||||
"background workers: %zu", conf_udp_threads(conf()),
|
||||
conf_tcp_threads(conf()), conf_bg_threads(conf()));
|
||||
} else if (strcasecmp(type, "configure") == 0) {
|
||||
ret = snprintf(buff, sizeof(buff), "%s", CONFIGURE_SUMMARY);
|
||||
} else {
|
||||
return KNOT_EINVAL;
|
||||
}
|
||||
if (ret <= 0 || ret >= sizeof(buff)) {
|
||||
return KNOT_ESPACE;
|
||||
}
|
||||
|
||||
args->data[KNOT_CTL_IDX_DATA] = buff;
|
||||
|
||||
return knot_ctl_send(args->ctl, KNOT_CTL_TYPE_DATA, &args->data);
|
||||
}
|
||||
|
||||
static int ctl_server(ctl_args_t *args, ctl_cmd_t cmd)
|
||||
{
|
||||
int ret = KNOT_EOK;
|
||||
char outbuf[2048] = { 0 };
|
||||
|
||||
switch (cmd) {
|
||||
case CTL_STATUS:
|
||||
ret = KNOT_EOK;
|
||||
if (strcasecmp(args->data[KNOT_CTL_IDX_DATA], "version") == 0) {
|
||||
snprintf(outbuf, sizeof(outbuf), "Version: %s", PACKAGE_VERSION);
|
||||
} else if (strcasecmp(args->data[KNOT_CTL_IDX_DATA], "workers") == 0) {
|
||||
snprintf(outbuf, sizeof(outbuf), "UDP workers: %zu, TCP workers %zu, "
|
||||
"background workers: %zu", conf_udp_threads(conf()),
|
||||
conf_tcp_threads(conf()), conf_bg_threads(conf()));
|
||||
} else if (strcasecmp(args->data[KNOT_CTL_IDX_DATA], "configure") == 0) {
|
||||
snprintf(outbuf, sizeof(outbuf), "%s", CONFIGURE_SUMMARY);
|
||||
} else if (args->data[KNOT_CTL_IDX_DATA][0] != '\0') {
|
||||
return KNOT_EINVAL;
|
||||
ret = server_status(args);
|
||||
if (ret != KNOT_EOK) {
|
||||
send_error(args, knot_strerror(ret));
|
||||
}
|
||||
args->data[KNOT_CTL_IDX_DATA] = outbuf;
|
||||
ret = knot_ctl_send(args->ctl, KNOT_CTL_TYPE_DATA, &args->data);
|
||||
break;
|
||||
case CTL_STOP:
|
||||
ret = KNOT_CTL_ESTOP;
|
||||
|
|
@ -1218,6 +1238,7 @@ static int ctl_stats(ctl_args_t *args, ctl_cmd_t cmd)
|
|||
int ret = snprintf(value, sizeof(value), "%"PRIu64,
|
||||
i->val(args->server));
|
||||
if (ret <= 0 || ret >= sizeof(value)) {
|
||||
ret = KNOT_ESPACE;
|
||||
send_error(args, knot_strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,11 +205,15 @@ static void format_data(ctl_cmd_t cmd, knot_ctl_type_t data_type,
|
|||
|
||||
switch (cmd) {
|
||||
case CTL_STATUS:
|
||||
if (data_type == KNOT_CTL_TYPE_DATA &&
|
||||
value != NULL && *value != '\0') {
|
||||
printf("%s\n", value);
|
||||
if (error != NULL) {
|
||||
printf("error: (%s)%s%s", error,
|
||||
(type != NULL) ? " " : "",
|
||||
(type != NULL) ? type : "");
|
||||
} else if (value != NULL) {
|
||||
printf("%s", value);
|
||||
*empty = false;
|
||||
}
|
||||
// FALLTHROUGH
|
||||
break;
|
||||
case CTL_STOP:
|
||||
case CTL_RELOAD:
|
||||
case CTL_CONF_BEGIN:
|
||||
|
|
@ -326,7 +330,7 @@ static void format_block(ctl_cmd_t cmd, bool failed, bool empty)
|
|||
{
|
||||
switch (cmd) {
|
||||
case CTL_STATUS:
|
||||
printf("%s\n", failed ? "" : "Running");
|
||||
printf("%s\n", (failed || !empty) ? "" : "Running");
|
||||
break;
|
||||
case CTL_STOP:
|
||||
printf("%s\n", failed ? "" : "Stopped");
|
||||
|
|
@ -420,7 +424,7 @@ static int cmd_ctl(cmd_args_t *args)
|
|||
knot_ctl_data_t data = {
|
||||
[KNOT_CTL_IDX_CMD] = ctl_cmd_to_str(args->desc->cmd),
|
||||
[KNOT_CTL_IDX_FLAGS] = args->force ? CTL_FLAG_FORCE : NULL,
|
||||
[KNOT_CTL_IDX_DATA] = (args->argc > 0 ? args->argv[0] : "")
|
||||
[KNOT_CTL_IDX_TYPE] = args->argc > 0 ? args->argv[0] : NULL
|
||||
};
|
||||
|
||||
// Send the command.
|
||||
|
|
|
|||
Loading…
Reference in a new issue