]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add check for binary existing in machine type probe
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 2 Feb 2011 12:35:31 +0000 (12:35 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 9 Feb 2011 16:45:31 +0000 (16:45 +0000)
When probing machine types if the QEMU binary does not exist
we get a hard to diagnose error, due to the execve() in the
child failing

error: internal error Child process exited with status 1.

Add an explicit check so that we get

error: Cannot find QEMU binary /usr/libexec/qem3u-kvm: No such file or directory

* src/qemu/qemu_capabilities.c: Check for QEMU binary

src/qemu/qemu_capabilities.c

index 0e1f79cd2002808ce86fd873a88126622dd0662e..4504b7e9f1959bbaf5d44ccf25f26c91a20da3fc 100644 (file)
@@ -172,6 +172,15 @@ qemuCapsProbeMachineTypes(const char *binary,
     int ret = -1;
     virCommandPtr cmd;
 
+    /* Make sure the binary we are about to try exec'ing exists.
+     * Technically we could catch the exec() failure, but that's
+     * in a sub-process so it's hard to feed back a useful error.
+     */
+    if (access(binary, X_OK) < 0) {
+        virReportSystemError(errno, _("Cannot find QEMU binary %s"), binary);
+        return -1;
+    }
+
     cmd = virCommandNewArgList(binary, "-M", "?", NULL);
     virCommandAddEnvPassCommon(cmd);
     virCommandSetOutputBuffer(cmd, &output);