]> xenbits.xensource.com Git - people/aperard/libvirt.git/commitdiff
rpc: don't try to spawn non-existant daemon
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 25 Jan 2023 14:23:48 +0000 (14:23 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 6 Dec 2023 16:45:46 +0000 (16:45 +0000)
If libvirt is built in client only mode, the libvirtd/virtqemud/etc
daemons won't exist. If the client is told to connect to a local
hypervisor, it'll see the socket doesn't exist, try to spawn the
daemon and then re-try connecting to the socket for a few seconds.
Ultimately this will fail because the daemon doesn't exist and the
user gets an error message

  error: Failed to connect socket to '/run/user/1000/libvirt/virtqemud-sock': No such file or directory

technically this is accurate, but it doesn't help identify the root
cause. With this change it will now report

  error: binary 'virtqemud' does not exist in $PATH: No such file or directory

and will skip all the socket connect retries

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/rpc/virnetsocket.c

index 151077c2ddcbc564821ede7b71c7c114277e265c..79bf8e511ae6f81d2c8ef83cfe2c46f7216e29a7 100644 (file)
@@ -123,9 +123,19 @@ VIR_ONCE_GLOBAL_INIT(virNetSocket);
 #ifndef WIN32
 static int virNetSocketForkDaemon(const char *binary)
 {
-    g_autoptr(virCommand) cmd = virCommandNewArgList(binary,
-                                                     "--timeout=120",
-                                                     NULL);
+    g_autofree char *binarypath = virFindFileInPath(binary);
+    g_autoptr(virCommand) cmd = NULL;
+
+    if (!binarypath) {
+        virReportSystemError(ENOENT,
+                             _("binary '%1$s' does not exist in $PATH"),
+                             binary);
+        return -1;
+    }
+
+    cmd = virCommandNewArgList(binarypath,
+                               "--timeout=120",
+                               NULL);
 
     virCommandAddEnvPassCommon(cmd);
     virCommandAddEnvPass(cmd, "XDG_CACHE_HOME");