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");
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");
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
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;
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
"file",
"get-autosync",
"get-path",
+ "get-qemu",
"get-state",
"get-verbose",
"is-busy",
"pvcreate",
"pvs",
"pvs-full",
+ "qemu",
"read-lines",
"rm",
"rm-rf",
"run",
"set-autosync",
"set-path",
+ "set-qemu",
"set-verbose",
"sfdisk",
"stat",
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
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
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
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);
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);
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
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
}
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)
{
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"
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 *)
}
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);
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;
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
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
}
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;
{ (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 },
"""
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.
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;
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",
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",
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);
int autosync;
const char *path;
+ const char *qemu;
char *last_error;
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 ();
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)
/* 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,
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");
setpgid (0, 0);
#endif
- execv (QEMU, g->cmdline); /* Run qemu. */
- perror (QEMU);
+ execv (g->qemu, g->cmdline); /* Run qemu. */
+ perror (g->qemu);
_exit (1);
}
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");