summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fish/cmds.c42
-rw-r--r--fish/completion.c3
-rw-r--r--guestfish-actions.pod26
-rw-r--r--guestfish.pod6
-rw-r--r--guestfs-actions.pod32
-rw-r--r--guestfs.pod6
-rw-r--r--java/com/redhat/et/libguestfs/GuestFS.java50
-rw-r--r--java/com_redhat_et_libguestfs_GuestFS.c32
-rw-r--r--ocaml/guestfs.ml2
-rw-r--r--ocaml/guestfs.mli6
-rw-r--r--ocaml/guestfs_c_actions.c45
-rw-r--r--perl/Guestfs.xs24
-rw-r--r--perl/lib/Sys/Guestfs.pm22
-rw-r--r--python/guestfs-py.c50
-rw-r--r--python/guestfs.py26
-rw-r--r--ruby/ext/guestfs/_guestfs.c42
-rwxr-xr-xsrc/generator.ml26
-rw-r--r--src/guestfs-actions.h2
-rw-r--r--src/guestfs.c29
-rw-r--r--tests.c2
20 files changed, 468 insertions, 5 deletions
diff --git a/fish/cmds.c b/fish/cmds.c
index 82be2614..6c66f0ac 100644
--- a/fish/cmds.c
+++ b/fish/cmds.c
@@ -68,6 +68,7 @@ void list_commands (void)
printf ("%-20s %s\n", "file", "determine file type");
printf ("%-20s %s\n", "get-autosync", "get autosync mode");
printf ("%-20s %s\n", "get-path", "get the search path");
+ printf ("%-20s %s\n", "get-qemu", "get the qemu binary");
printf ("%-20s %s\n", "get-state", "get the current state");
printf ("%-20s %s\n", "get-verbose", "get verbose mode");
printf ("%-20s %s\n", "is-busy", "is busy processing a command");
@@ -101,6 +102,7 @@ void list_commands (void)
printf ("%-20s %s\n", "rmdir", "remove a directory");
printf ("%-20s %s\n", "set-autosync", "set autosync mode");
printf ("%-20s %s\n", "set-path", "set the search path");
+ printf ("%-20s %s\n", "set-qemu", "set the qemu binary");
printf ("%-20s %s\n", "set-verbose", "set verbose mode");
printf ("%-20s %s\n", "sfdisk", "create partitions on a block device");
printf ("%-20s %s\n", "stat", "get file information");
@@ -139,6 +141,12 @@ void display_command (const char *cmd)
if (strcasecmp (cmd, "config") == 0)
pod2text ("config - add qemu parameters", " config <qemuparam> <qemuvalue>\n\nThis can be used to add arbitrary qemu command line parameters\nof the form C<-param value>. Actually it's not quite arbitrary - we\nprevent you from setting some parameters which would interfere with\nparameters that we use.\n\nThe first character of C<param> string must be a C<-> (dash).\n\nC<value> can be NULL.");
else
+ if (strcasecmp (cmd, "set_qemu") == 0 || strcasecmp (cmd, "set-qemu") == 0 || strcasecmp (cmd, "qemu") == 0)
+ pod2text ("set-qemu - set the qemu binary", " set-qemu <qemu>\n\nSet the qemu binary that we will use.\n\nThe default is chosen when the library was compiled by the\nconfigure script.\n\nYou can also override this by setting the C<LIBGUESTFS_QEMU>\nenvironment variable.\n\nThe string C<qemu> is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C<qemu> to C<NULL> restores the default qemu binary.\n\nYou can use 'qemu' as an alias for this command.");
+ else
+ if (strcasecmp (cmd, "get_qemu") == 0 || strcasecmp (cmd, "get-qemu") == 0)
+ pod2text ("get-qemu - get the qemu binary", " get-qemu\n\nReturn the current qemu binary.\n\nThis is always non-NULL. If it wasn't set already, then this will\nreturn the default qemu binary name.");
+ else
if (strcasecmp (cmd, "set_path") == 0 || strcasecmp (cmd, "set-path") == 0 || strcasecmp (cmd, "path") == 0)
pod2text ("set-path - set the search path", " set-path <path>\n\nSet the path that libguestfs searches for kernel and initrd.img.\n\nThe default is C<$libdir/guestfs> unless overridden by setting\nC<LIBGUESTFS_PATH> environment variable.\n\nThe string C<path> is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C<path> to C<NULL> restores the default path.\n\nYou can use 'path' as an alias for this command.");
else
@@ -593,6 +601,34 @@ static int run_config (const char *cmd, int argc, char *argv[])
return r;
}
+static int run_set_qemu (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ const char *qemu;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ qemu = argv[0];
+ r = guestfs_set_qemu (g, qemu);
+ return r;
+}
+
+static int run_get_qemu (const char *cmd, int argc, char *argv[])
+{
+ const char *r;
+ if (argc != 0) {
+ fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ r = guestfs_get_qemu (g);
+ if (r == NULL) return -1;
+ printf ("%s\n", r);
+ return 0;
+}
+
static int run_set_path (const char *cmd, int argc, char *argv[])
{
int r;
@@ -1898,6 +1934,12 @@ int run_action (const char *cmd, int argc, char *argv[])
if (strcasecmp (cmd, "config") == 0)
return run_config (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "set_qemu") == 0 || strcasecmp (cmd, "set-qemu") == 0 || strcasecmp (cmd, "qemu") == 0)
+ return run_set_qemu (cmd, argc, argv);
+ else
+ if (strcasecmp (cmd, "get_qemu") == 0 || strcasecmp (cmd, "get-qemu") == 0)
+ return run_get_qemu (cmd, argc, argv);
+ else
if (strcasecmp (cmd, "set_path") == 0 || strcasecmp (cmd, "set-path") == 0 || strcasecmp (cmd, "path") == 0)
return run_set_path (cmd, argc, argv);
else
diff --git a/fish/completion.c b/fish/completion.c
index 44cfb9e5..e1603f1b 100644
--- a/fish/completion.c
+++ b/fish/completion.c
@@ -74,6 +74,7 @@ static const char *commands[] = {
"file",
"get-autosync",
"get-path",
+ "get-qemu",
"get-state",
"get-verbose",
"is-busy",
@@ -102,6 +103,7 @@ static const char *commands[] = {
"pvcreate",
"pvs",
"pvs-full",
+ "qemu",
"read-lines",
"rm",
"rm-rf",
@@ -109,6 +111,7 @@ static const char *commands[] = {
"run",
"set-autosync",
"set-path",
+ "set-qemu",
"set-verbose",
"sfdisk",
"stat",
diff --git a/guestfish-actions.pod b/guestfish-actions.pod
index da4bbaeb..4403cb0b 100644
--- a/guestfish-actions.pod
+++ b/guestfish-actions.pod
@@ -452,6 +452,15 @@ Return the current search path.
This is always non-NULL. If it wasn't set already, then this will
return the default path.
+=head2 get-qemu
+
+ get-qemu
+
+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.
+
=head2 get-state
get-state
@@ -761,6 +770,23 @@ must make sure it remains valid for the lifetime of the handle.
Setting C<path> to C<NULL> restores the default path.
+=head2 set-qemu | qemu
+
+ set-qemu qemu
+
+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.
+
=head2 set-verbose | verbose
set-verbose true|false
diff --git a/guestfish.pod b/guestfish.pod
index f2e45913..9dadc941 100644
--- a/guestfish.pod
+++ b/guestfish.pod
@@ -233,6 +233,12 @@ same effect as using the B<-v> option.
Set the path that guestfish uses to search for kernel and initrd.img.
See the discussion of paths in L<guestfs(3)>.
+=item LIBGUESTFS_QEMU
+
+Set the default qemu binary that libguestfs uses. If not set, then
+the qemu which was found at compile time by the configure script is
+used.
+
=item HOME
If compiled with GNU readline support, then the command history
diff --git a/guestfs-actions.pod b/guestfs-actions.pod
index dcffc831..b9648762 100644
--- a/guestfs-actions.pod
+++ b/guestfs-actions.pod
@@ -585,6 +585,18 @@ return the default path.
This function returns a string, or NULL on error.
The string is owned by the guest handle and must I<not> be freed.
+=head2 guestfs_get_qemu
+
+ const char *guestfs_get_qemu (guestfs_h *handle);
+
+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.
+
+This function returns a string, or NULL on error.
+The string is owned by the guest handle and must I<not> be freed.
+
=head2 guestfs_get_state
int guestfs_get_state (guestfs_h *handle);
@@ -1016,6 +1028,26 @@ Setting C<path> to C<NULL> restores the default path.
This function returns 0 on success or -1 on error.
+=head2 guestfs_set_qemu
+
+ int guestfs_set_qemu (guestfs_h *handle,
+ const char *qemu);
+
+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.
+
+This function returns 0 on success or -1 on error.
+
=head2 guestfs_set_ready
int guestfs_set_ready (guestfs_h *handle);
diff --git a/guestfs.pod b/guestfs.pod
index db157fa5..f133a1c4 100644
--- a/guestfs.pod
+++ b/guestfs.pod
@@ -646,6 +646,12 @@ has the same effect as calling C<guestfs_set_verbose (handle, 1)>.
Set the path that libguestfs uses to search for kernel and initrd.img.
See the discussion of paths in section PATH above.
+=item LIBGUESTFS_QEMU
+
+Set the default qemu binary that libguestfs uses. If not set, then
+the qemu which was found at compile time by the configure script is
+used.
+
=back
=head1 SEE ALSO
diff --git a/java/com/redhat/et/libguestfs/GuestFS.java b/java/com/redhat/et/libguestfs/GuestFS.java
index 8c2265e7..119a2df1 100644
--- a/java/com/redhat/et/libguestfs/GuestFS.java
+++ b/java/com/redhat/et/libguestfs/GuestFS.java
@@ -219,6 +219,56 @@ public class GuestFS {
throws LibGuestFSException;
/**
+ * 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
+ * "LIBGUESTFS_QEMU" environment variable.
+ *
+ * The string "qemu" is stashed in the libguestfs handle,
+ * so the caller must make sure it remains valid for the
+ * lifetime of the handle.
+ *
+ * Setting "qemu" to "NULL" restores the default qemu
+ * binary.
+ *
+ * @throws LibGuestFSException
+ */
+ public void set_qemu (String qemu)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("set_qemu: handle is closed");
+ _set_qemu (g, qemu);
+ }
+ private native void _set_qemu (long g, String qemu)
+ throws LibGuestFSException;
+
+ /**
+ * 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.
+ *
+ * @throws LibGuestFSException
+ */
+ public String get_qemu ()
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("get_qemu: handle is closed");
+ return _get_qemu (g);
+ }
+ private native String _get_qemu (long g)
+ throws LibGuestFSException;
+
+ /**
* set the search path
*
* Set the path that libguestfs searches for kernel and
diff --git a/java/com_redhat_et_libguestfs_GuestFS.c b/java/com_redhat_et_libguestfs_GuestFS.c
index 51412780..550568b8 100644
--- a/java/com_redhat_et_libguestfs_GuestFS.c
+++ b/java/com_redhat_et_libguestfs_GuestFS.c
@@ -158,6 +158,38 @@ Java_com_redhat_et_libguestfs_GuestFS__1config
}
JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1set_1qemu
+ (JNIEnv *env, jobject obj, jlong jg, jstring jqemu)
+{
+ guestfs_h *g = (guestfs_h *) jg;
+ int r;
+ const char *qemu;
+
+ qemu = (*env)->GetStringUTFChars (env, jqemu, NULL);
+ r = guestfs_set_qemu (g, qemu);
+ (*env)->ReleaseStringUTFChars (env, jqemu, qemu);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
+JNIEXPORT jstring JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1get_1qemu
+ (JNIEnv *env, jobject obj, jlong jg)
+{
+ guestfs_h *g = (guestfs_h *) jg;
+ const char *r;
+
+ r = guestfs_get_qemu (g);
+ if (r == NULL) {
+ throw_exception (env, guestfs_last_error (g));
+ return NULL;
+ }
+ return (*env)->NewStringUTF (env, r);
+}
+
+JNIEXPORT void JNICALL
Java_com_redhat_et_libguestfs_GuestFS__1set_1path
(JNIEnv *env, jobject obj, jlong jg, jstring jpath)
{
diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml
index 3ca33f7b..1cfe9210 100644
--- a/ocaml/guestfs.ml
+++ b/ocaml/guestfs.ml
@@ -121,6 +121,8 @@ external kill_subprocess : t -> unit = "ocaml_guestfs_kill_subprocess"
external add_drive : t -> string -> unit = "ocaml_guestfs_add_drive"
external add_cdrom : t -> string -> unit = "ocaml_guestfs_add_cdrom"
external config : t -> string -> string option -> unit = "ocaml_guestfs_config"
+external set_qemu : t -> string -> unit = "ocaml_guestfs_set_qemu"
+external get_qemu : t -> string = "ocaml_guestfs_get_qemu"
external set_path : t -> string -> unit = "ocaml_guestfs_set_path"
external get_path : t -> string = "ocaml_guestfs_get_path"
external set_autosync : t -> bool -> unit = "ocaml_guestfs_set_autosync"
diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli
index 629e443e..766c3e0e 100644
--- a/ocaml/guestfs.mli
+++ b/ocaml/guestfs.mli
@@ -142,6 +142,12 @@ val add_cdrom : t -> string -> unit
val config : t -> string -> string option -> unit
(** add qemu parameters *)
+val set_qemu : t -> string -> unit
+(** set the qemu binary *)
+
+val get_qemu : t -> string
+(** get the qemu binary *)
+
val set_path : t -> string -> unit
(** set the search path *)
diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c
index cfcf4e4c..b0f9cdc5 100644
--- a/ocaml/guestfs_c_actions.c
+++ b/ocaml/guestfs_c_actions.c
@@ -466,6 +466,51 @@ ocaml_guestfs_config (value gv, value qemuparamv, value qemuvaluev)
}
CAMLprim value
+ocaml_guestfs_set_qemu (value gv, value qemuv)
+{
+ CAMLparam2 (gv, qemuv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("set_qemu: used handle after closing it");
+
+ const char *qemu = String_val (qemuv);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_set_qemu (g, qemu);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "set_qemu");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_get_qemu (value gv)
+{
+ CAMLparam1 (gv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("get_qemu: used handle after closing it");
+
+ const char *r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_get_qemu (g);
+ caml_leave_blocking_section ();
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "get_qemu");
+
+ rv = caml_copy_string (r);
+ CAMLreturn (rv);
+}
+
+CAMLprim value
ocaml_guestfs_set_path (value gv, value pathv)
{
CAMLparam2 (gv, pathv);
diff --git a/perl/Guestfs.xs b/perl/Guestfs.xs
index 63dce749..657a0ba1 100644
--- a/perl/Guestfs.xs
+++ b/perl/Guestfs.xs
@@ -168,6 +168,30 @@ PREINIT:
croak ("config: %s", guestfs_last_error (g));
void
+set_qemu (g, qemu)
+ guestfs_h *g;
+ char *qemu;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_set_qemu (g, qemu);
+ if (r == -1)
+ croak ("set_qemu: %s", guestfs_last_error (g));
+
+SV *
+get_qemu (g)
+ guestfs_h *g;
+PREINIT:
+ const char *qemu;
+ CODE:
+ qemu = guestfs_get_qemu (g);
+ if (qemu == NULL)
+ croak ("get_qemu: %s", guestfs_last_error (g));
+ RETVAL = newSVpv (qemu, 0);
+ OUTPUT:
+ RETVAL
+
+void
set_path (g, path)
guestfs_h *g;
char *path;
diff --git a/perl/lib/Sys/Guestfs.pm b/perl/lib/Sys/Guestfs.pm
index d16077e5..273e4fe1 100644
--- a/perl/lib/Sys/Guestfs.pm
+++ b/perl/lib/Sys/Guestfs.pm
@@ -469,6 +469,13 @@ Return the current search path.
This is always non-NULL. If it wasn't set already, then this will
return the default path.
+=item $qemu = $h->get_qemu ();
+
+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.
+
=item $state = $h->get_state ();
This returns the current state as an opaque integer. This is
@@ -719,6 +726,21 @@ must make sure it remains valid for the lifetime of the handle.
Setting C<path> to C<NULL> restores the default path.
+=item $h->set_qemu ($qemu);
+
+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.
+
=item $h->set_ready ();
This sets the state to C<READY>. This is only used when implementing
diff --git a/python/guestfs-py.c b/python/guestfs-py.c
index 800d21b9..d6470140 100644
--- a/python/guestfs-py.c
+++ b/python/guestfs-py.c
@@ -537,6 +537,54 @@ py_guestfs_config (PyObject *self, PyObject *args)
}
static PyObject *
+py_guestfs_set_qemu (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ const char *qemu;
+
+ if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_set_qemu",
+ &py_g, &qemu))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_set_qemu (g, qemu);
+ if (r == -1) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ Py_INCREF (Py_None);
+ py_r = Py_None;
+ return py_r;
+}
+
+static PyObject *
+py_guestfs_get_qemu (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ const char *r;
+
+ if (!PyArg_ParseTuple (args, (char *) "O:guestfs_get_qemu",
+ &py_g))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_get_qemu (g);
+ if (r == NULL) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ py_r = PyString_FromString (r);
+ return py_r;
+}
+
+static PyObject *
py_guestfs_set_path (PyObject *self, PyObject *args)
{
PyObject *py_g;
@@ -2675,6 +2723,8 @@ static PyMethodDef methods[] = {
{ (char *) "add_drive", py_guestfs_add_drive, METH_VARARGS, NULL },
{ (char *) "add_cdrom", py_guestfs_add_cdrom, METH_VARARGS, NULL },
{ (char *) "config", py_guestfs_config, METH_VARARGS, NULL },
+ { (char *) "set_qemu", py_guestfs_set_qemu, METH_VARARGS, NULL },
+ { (char *) "get_qemu", py_guestfs_get_qemu, METH_VARARGS, NULL },
{ (char *) "set_path", py_guestfs_set_path, METH_VARARGS, NULL },
{ (char *) "get_path", py_guestfs_get_path, METH_VARARGS, NULL },
{ (char *) "set_autosync", py_guestfs_set_autosync, METH_VARARGS, NULL },
diff --git a/python/guestfs.py b/python/guestfs.py
index 6417caf4..e5f43d1f 100644
--- a/python/guestfs.py
+++ b/python/guestfs.py
@@ -143,6 +143,32 @@ class GuestFS:
"""
return libguestfsmod.config (self._o, qemuparam, qemuvalue)
+ def set_qemu (self, qemu):
+ u"""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
+ "LIBGUESTFS_QEMU" environment variable.
+
+ The string "qemu" is stashed in the libguestfs handle,
+ so the caller must make sure it remains valid for the
+ lifetime of the handle.
+
+ Setting "qemu" to "NULL" restores the default qemu
+ binary.
+ """
+ return libguestfsmod.set_qemu (self._o, qemu)
+
+ def get_qemu (self):
+ u"""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.
+ """
+ return libguestfsmod.get_qemu (self._o)
+
def set_path (self, path):
u"""Set the path that libguestfs searches for kernel and
initrd.img.
diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c
index 9971228f..4e1a2d40 100644
--- a/ruby/ext/guestfs/_guestfs.c
+++ b/ruby/ext/guestfs/_guestfs.c
@@ -181,6 +181,44 @@ static VALUE ruby_guestfs_config (VALUE gv, VALUE qemuparamv, VALUE qemuvaluev)
return Qnil;
}
+static VALUE ruby_guestfs_set_qemu (VALUE gv, VALUE qemuv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "set_qemu");
+
+ const char *qemu = StringValueCStr (qemuv);
+ if (!qemu)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "qemu", "set_qemu");
+
+ int r;
+
+ r = guestfs_set_qemu (g, qemu);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
+static VALUE ruby_guestfs_get_qemu (VALUE gv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "get_qemu");
+
+
+ const char *r;
+
+ r = guestfs_get_qemu (g);
+ if (r == NULL)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return rb_str_new2 (r);
+}
+
static VALUE ruby_guestfs_set_path (VALUE gv, VALUE pathv)
{
guestfs_h *g;
@@ -2215,6 +2253,10 @@ void Init__guestfs ()
ruby_guestfs_add_cdrom, 1);
rb_define_method (c_guestfs, "config",
ruby_guestfs_config, 2);
+ rb_define_method (c_guestfs, "set_qemu",
+ ruby_guestfs_set_qemu, 1);
+ rb_define_method (c_guestfs, "get_qemu",
+ ruby_guestfs_get_qemu, 0);
rb_define_method (c_guestfs, "set_path",
ruby_guestfs_set_path, 1);
rb_define_method (c_guestfs, "get_path",
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);
}
diff --git a/tests.c b/tests.c
index 1c862691..da8b4095 100644
--- a/tests.c
+++ b/tests.c
@@ -63,6 +63,8 @@ static void no_test_warnings (void)
fprintf (stderr, "warning: \"guestfs_add_drive\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_add_cdrom\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_config\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_set_qemu\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_qemu\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_set_path\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_get_path\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_set_autosync\" has no tests\n");