[PATCH 5/6] virt-admin: Introduce 'daemon-timeout'

Peter Krempa pkrempa at redhat.com
Mon Jun 13 13:56:32 UTC 2022


Add a simple command to drive the new 'virAdmConnectSetDaemonTimeout'
API.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 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:<msg_ident>"

+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 e010763e21..718df62854 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -1072,6 +1072,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,
@@ -1499,6 +1538,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}
 };

-- 
2.36.1



More information about the libvir-list mailing list