Commit 035b95f4 authored by Libor Peltan's avatar Libor Peltan

ctl: status: added options: version, workers, configure

...to display either real Knot running version, numbers of workers, or configure options
parent 59e5ab97
...@@ -9,6 +9,7 @@ m4_define([knot_VERSION_EXTRA],-dev)dnl ...@@ -9,6 +9,7 @@ m4_define([knot_VERSION_EXTRA],-dev)dnl
m4_define([knot_PKG_VERSION],[knot_VERSION_MAJOR.knot_VERSION_MINOR.knot_VERSION_PATCH]knot_VERSION_EXTRA)dnl m4_define([knot_PKG_VERSION],[knot_VERSION_MAJOR.knot_VERSION_MINOR.knot_VERSION_PATCH]knot_VERSION_EXTRA)dnl
AC_INIT([knot], knot_PKG_VERSION, [knot-dns@labs.nic.cz]) AC_INIT([knot], knot_PKG_VERSION, [knot-dns@labs.nic.cz])
configure_params="$*"
AM_INIT_AUTOMAKE([gnits subdir-objects no-dist-gzip dist-xz -Wall -Werror]) AM_INIT_AUTOMAKE([gnits subdir-objects no-dist-gzip dist-xz -Wall -Werror])
AM_SILENT_RULES([yes]) AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR([src/knot]) AC_CONFIG_SRCDIR([src/knot])
...@@ -26,6 +27,10 @@ AC_CONFIG_FILES([src/libknot/version.h ...@@ -26,6 +27,10 @@ AC_CONFIG_FILES([src/libknot/version.h
src/zscanner/version.h src/zscanner/version.h
src/dnssec/lib/dnssec/version.h]) src/dnssec/lib/dnssec/version.h])
# Store ./configure parameters into macro
AC_DEFINE_UNQUOTED([CONFIGURE_PARAMS],["$configure_params"],[Params passed to configure])
AC_DEFINE_UNQUOTED([CONFIGURE_CFLAGS],["$CFLAGS"],[Passed CFLAGS from environment])
# Updating version info # Updating version info
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
AC_SUBST([libknot_VERSION_INFO],["-version-info 5:0:0"]) AC_SUBST([libknot_VERSION_INFO],["-version-info 5:0:0"])
......
...@@ -1128,10 +1128,25 @@ static int ctl_zone(ctl_args_t *args, ctl_cmd_t cmd) ...@@ -1128,10 +1128,25 @@ static int ctl_zone(ctl_args_t *args, ctl_cmd_t cmd)
static int ctl_server(ctl_args_t *args, ctl_cmd_t cmd) static int ctl_server(ctl_args_t *args, ctl_cmd_t cmd)
{ {
int ret = KNOT_EOK; int ret = KNOT_EOK;
char outbuf[256] = { 0 };
switch (cmd) { switch (cmd) {
case CTL_STATUS: case CTL_STATUS:
ret = KNOT_EOK; 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), "Passed CFLAGS: %s; Configure parameters: %s",
CONFIGURE_CFLAGS, CONFIGURE_PARAMS);
} else if (args->data[KNOT_CTL_IDX_DATA][0] != '\0') {
return KNOT_EINVAL;
}
args->data[KNOT_CTL_IDX_DATA] = outbuf;
ret = knot_ctl_send(args->ctl, KNOT_CTL_TYPE_DATA, &args->data);
break; break;
case CTL_STOP: case CTL_STOP:
ret = KNOT_CTL_ESTOP; ret = KNOT_CTL_ESTOP;
......
...@@ -203,6 +203,11 @@ static void format_data(ctl_cmd_t cmd, knot_ctl_type_t data_type, ...@@ -203,6 +203,11 @@ static void format_data(ctl_cmd_t cmd, knot_ctl_type_t data_type,
switch (cmd) { switch (cmd) {
case CTL_STATUS: case CTL_STATUS:
if (data_type == KNOT_CTL_TYPE_DATA &&
value != NULL && *value != '\0') {
printf("%s\n", value);
}
// FALLTHROUGH
case CTL_STOP: case CTL_STOP:
case CTL_RELOAD: case CTL_RELOAD:
case CTL_CONF_BEGIN: case CTL_CONF_BEGIN:
...@@ -403,14 +408,15 @@ static int ctl_receive(cmd_args_t *args) ...@@ -403,14 +408,15 @@ static int ctl_receive(cmd_args_t *args)
static int cmd_ctl(cmd_args_t *args) static int cmd_ctl(cmd_args_t *args)
{ {
int ret = check_args(args, 0, 0); int ret = check_args(args, 0, (args->desc->cmd == CTL_STATUS ? 1 : 0));
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
return ret; return ret;
} }
knot_ctl_data_t data = { knot_ctl_data_t data = {
[KNOT_CTL_IDX_CMD] = ctl_cmd_to_str(args->desc->cmd), [KNOT_CTL_IDX_CMD] = ctl_cmd_to_str(args->desc->cmd),
[KNOT_CTL_IDX_FLAGS] = args->force ? CTL_FLAG_FORCE : NULL [KNOT_CTL_IDX_FLAGS] = args->force ? CTL_FLAG_FORCE : NULL,
[KNOT_CTL_IDX_DATA] = (args->argc > 0 ? args->argv[0] : "")
}; };
// Send the command. // Send the command.
...@@ -957,7 +963,7 @@ static int cmd_conf_ctl(cmd_args_t *args) ...@@ -957,7 +963,7 @@ static int cmd_conf_ctl(cmd_args_t *args)
const cmd_desc_t cmd_table[] = { const cmd_desc_t cmd_table[] = {
{ CMD_EXIT, NULL, CTL_NONE }, { CMD_EXIT, NULL, CTL_NONE },
{ CMD_STATUS, cmd_ctl, CTL_STATUS }, { CMD_STATUS, cmd_ctl, CTL_STATUS, CMD_FOPT_DATA},
{ CMD_STOP, cmd_ctl, CTL_STOP }, { CMD_STOP, cmd_ctl, CTL_STOP },
{ CMD_RELOAD, cmd_ctl, CTL_RELOAD }, { CMD_RELOAD, cmd_ctl, CTL_RELOAD },
{ CMD_STATS, cmd_stats_ctl, CTL_STATS }, { CMD_STATS, cmd_stats_ctl, CTL_STATS },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment