From fe69f5074a6ad6af49ad87242317542dc45e4406 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 13 Jun 2022 15:27:27 +0200 Subject: [PATCH] virt-admin: Introduce 'daemon-timeout' Add a simple command to drive the new 'virAdmConnectSetDaemonTimeout' API. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- docs/manpages/virt-admin.rst | 12 ++++++++++ tools/virt-admin.c | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/docs/manpages/virt-admin.rst b/docs/manpages/virt-admin.rst index 30cfd24e73..479e27b2c2 100644 --- a/docs/manpages/virt-admin.rst +++ b/docs/manpages/virt-admin.rst @@ -313,6 +313,18 @@ To define multiple outputs at once they need to be delimited by spaces: $ virt-admin daemon-log-outputs "4:stderr 2:syslog:" +daemon-timeout +-------------- + +**Syntax:** + +:: + + daemon-timeout --timeout NUM + +Sets the daemon timeout to the value of '--timeout' argument. Use ``--timeout 0`` +to disable auto-shutdown of the daemon. + SERVER COMMANDS =============== diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 952999ca3c..11ba242742 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1071,6 +1071,45 @@ static const vshCmdInfo info_daemon_log_outputs[] = { {.name = NULL} }; +static const vshCmdOptDef opts_daemon_timeout[] = { + {.name = "timeout", + .type = VSH_OT_INT, + .help = N_("number of seconds the daemon will run without any active connection"), + .flags = VSH_OFLAG_REQ | VSH_OFLAG_REQ_OPT + }, + {.name = NULL} +}; + +static bool +cmdDaemonTimeout(vshControl *ctl, const vshCmd *cmd) +{ + vshAdmControl *priv = ctl->privData; + unsigned int timeout = 0; + + if (vshCommandOptUInt(ctl, cmd, "timeout", &timeout) < 0) + return false; + + if (virAdmConnectSetDaemonTimeout(priv->conn, timeout, 0) < 0) + return false; + + return true; +} + + +/* -------------------------- + * Command daemon-timeout + * -------------------------- + */ +static const vshCmdInfo info_daemon_timeout[] = { + {.name = "help", + .data = N_("set the auto shutdown timeout of the daemon") + }, + {.name = "desc", + .data = N_("set the auto shutdown timeout of the daemon") + }, + {.name = NULL} +}; + static const vshCmdOptDef opts_daemon_log_outputs[] = { {.name = "outputs", .type = VSH_OT_STRING, @@ -1498,6 +1537,12 @@ static const vshCmdDef managementCmds[] = { .info = info_daemon_log_outputs, .flags = 0 }, + {.name = "daemon-timeout", + .handler = cmdDaemonTimeout, + .opts = opts_daemon_timeout, + .info = info_daemon_timeout, + .flags = 0 + }, {.name = NULL} };