summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-22 09:00:39 +0100
committerRichard Jones <rjones@redhat.com>2009-04-22 09:00:39 +0100
commit43db06ea892cc157324a6b837ca430607441c509 (patch)
treefc377195fcfda3b163d8f184a6965bb64b1bb018 /src
parent54dd7be5855055a698291084c0074a1abac7b921 (diff)
downloadlibguestfs-43db06ea892cc157324a6b837ca430607441c509.tar.gz
libguestfs-43db06ea892cc157324a6b837ca430607441c509.tar.xz
libguestfs-43db06ea892cc157324a6b837ca430607441c509.zip
Allow qemu binary to be overridden at runtime.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/generator.ml26
-rw-r--r--src/guestfs-actions.h2
-rw-r--r--src/guestfs.c29
3 files changed, 52 insertions, 5 deletions
diff --git a/src/generator.ml b/src/generator.ml
index 3b08993f..beb36708 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -284,6 +284,32 @@ The first character of C<param> string must be a C<-> (dash).
C<value> can be NULL.");
+ ("set_qemu", (RErr, [String "qemu"]), -1, [FishAlias "qemu"],
+ [],
+ "set the qemu binary",
+ "\
+Set the qemu binary that we will use.
+
+The default is chosen when the library was compiled by the
+configure script.
+
+You can also override this by setting the C<LIBGUESTFS_QEMU>
+environment variable.
+
+The string C<qemu> is stashed in the libguestfs handle, so the caller
+must make sure it remains valid for the lifetime of the handle.
+
+Setting C<qemu> to C<NULL> restores the default qemu binary.");
+
+ ("get_qemu", (RConstString "qemu", []), -1, [],
+ [],
+ "get the qemu binary",
+ "\
+Return the current qemu binary.
+
+This is always non-NULL. If it wasn't set already, then this will
+return the default qemu binary name.");
+
("set_path", (RErr, [String "path"]), -1, [FishAlias "path"],
[],
"set the search path",
diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h
index ae54d3a3..68184bad 100644
--- a/src/guestfs-actions.h
+++ b/src/guestfs-actions.h
@@ -25,6 +25,8 @@ extern int guestfs_kill_subprocess (guestfs_h *handle);
extern int guestfs_add_drive (guestfs_h *handle, const char *filename);
extern int guestfs_add_cdrom (guestfs_h *handle, const char *filename);
extern int guestfs_config (guestfs_h *handle, const char *qemuparam, const char *qemuvalue);
+extern int guestfs_set_qemu (guestfs_h *handle, const char *qemu);
+extern const char *guestfs_get_qemu (guestfs_h *handle);
extern int guestfs_set_path (guestfs_h *handle, const char *path);
extern const char *guestfs_get_path (guestfs_h *handle);
extern int guestfs_set_autosync (guestfs_h *handle, int autosync);
diff --git a/src/guestfs.c b/src/guestfs.c
index 0bec3b74..1642019a 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -156,6 +156,7 @@ struct guestfs_h
int autosync;
const char *path;
+ const char *qemu;
char *last_error;
@@ -217,7 +218,9 @@ guestfs_create (void)
str = getenv ("LIBGUESTFS_PATH");
g->path = str != NULL ? str : GUESTFS_DEFAULT_PATH;
- /* XXX We should probably make QEMU configurable as well. */
+
+ str = getenv ("LIBGUESTFS_QEMU");
+ g->qemu = str != NULL ? str : QEMU;
g->main_loop = guestfs_get_default_main_loop ();
@@ -511,6 +514,22 @@ guestfs_get_path (guestfs_h *g)
return g->path;
}
+int
+guestfs_set_qemu (guestfs_h *g, const char *qemu)
+{
+ if (qemu == NULL)
+ g->qemu = QEMU;
+ else
+ g->qemu = qemu;
+ return 0;
+}
+
+const char *
+guestfs_get_qemu (guestfs_h *g)
+{
+ return g->qemu;
+}
+
/* Add a string to the current command line. */
static void
incr_cmdline_size (guestfs_h *g)
@@ -715,7 +734,7 @@ guestfs_launch (guestfs_h *g)
/* Set up the full command line. Do this in the subprocess so we
* don't need to worry about cleaning up.
*/
- g->cmdline[0] = (char *) QEMU;
+ g->cmdline[0] = (char *) g->qemu;
/* Construct the -net channel parameter for qemu. */
snprintf (vmchannel, sizeof vmchannel,
@@ -752,7 +771,7 @@ guestfs_launch (guestfs_h *g)
g->cmdline[g->cmdline_size-1] = NULL;
if (g->verbose) {
- fprintf (stderr, "%s", QEMU);
+ fprintf (stderr, "%s", g->qemu);
for (i = 0; g->cmdline[i]; ++i)
fprintf (stderr, " %s", g->cmdline[i]);
fprintf (stderr, "\n");
@@ -775,8 +794,8 @@ guestfs_launch (guestfs_h *g)
setpgid (0, 0);
#endif
- execv (QEMU, g->cmdline); /* Run qemu. */
- perror (QEMU);
+ execv (g->qemu, g->cmdline); /* Run qemu. */
+ perror (g->qemu);
_exit (1);
}