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.");
+ 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\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.");
+ 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\nSetting C<path> to C<NULL> restores the default path.\n\nYou can use 'path' as an alias for this command.");
else
if (strcasecmp (cmd, "get_path") == 0 || strcasecmp (cmd, "get-path") == 0)
pod2text ("get-path - get the search path", " get-path\n\nReturn the current search path.\n\nThis is always non-NULL. If it wasn't set already, then this will\nreturn the default path.");
else
if (strcasecmp (cmd, "set_append") == 0 || strcasecmp (cmd, "set-append") == 0 || strcasecmp (cmd, "append") == 0)
- pod2text ("set-append - add options to kernel command line", " set-append <append>\n\nThis function is used to add additional options to the\nguest kernel command line.\n\nThe default is C<NULL> unless overridden by setting\nC<LIBGUESTFS_APPEND> environment variable.\n\nThe string C<append> is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C<append> to C<NULL> means I<no> additional options\nare passed (libguestfs always adds a few of its own).\n\nYou can use 'append' as an alias for this command.");
+ pod2text ("set-append - add options to kernel command line", " set-append <append>\n\nThis function is used to add additional options to the\nguest kernel command line.\n\nThe default is C<NULL> unless overridden by setting\nC<LIBGUESTFS_APPEND> environment variable.\n\nSetting C<append> to C<NULL> means I<no> additional options\nare passed (libguestfs always adds a few of its own).\n\nYou can use 'append' as an alias for this command.");
else
if (strcasecmp (cmd, "get_append") == 0 || strcasecmp (cmd, "get-append") == 0)
pod2text ("get-append - get the additional kernel options", " get-append\n\nReturn the additional kernel options which are added to the\nguest kernel command line.\n\nIf C<NULL> then no options are added.");
The default is C<NULL> unless overridden by setting
C<LIBGUESTFS_APPEND> environment variable.
-The string C<append> is stashed in the libguestfs handle, so the caller
-must make sure it remains valid for the lifetime of the handle.
-
Setting C<append> to C<NULL> means I<no> additional options
are passed (libguestfs always adds a few of its own).
The default is C<$libdir/guestfs> unless overridden by setting
C<LIBGUESTFS_PATH> environment variable.
-The string C<path> is stashed in the libguestfs handle, so the caller
-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
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
The default is C<NULL> unless overridden by setting
C<LIBGUESTFS_APPEND> environment variable.
-The string C<append> is stashed in the libguestfs handle, so the caller
-must make sure it remains valid for the lifetime of the handle.
-
Setting C<append> to C<NULL> means I<no> additional options
are passed (libguestfs always adds a few of its own).
The default is C<$libdir/guestfs> unless overridden by setting
C<LIBGUESTFS_PATH> environment variable.
-The string C<path> is stashed in the libguestfs handle, so the caller
-must make sure it remains valid for the lifetime of the handle.
-
Setting C<path> to C<NULL> restores the default path.
This function returns 0 on success or -1 on error.
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.
* 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.
*
* The default is "$libdir/guestfs" unless overridden by
* setting "LIBGUESTFS_PATH" environment variable.
*
- * The string "path" is stashed in the libguestfs handle,
- * so the caller must make sure it remains valid for the
- * lifetime of the handle.
- *
* Setting "path" to "NULL" restores the default path.
*
* @throws LibGuestFSException
* The default is "NULL" unless overridden by setting
* "LIBGUESTFS_APPEND" environment variable.
*
- * The string "append" is stashed in the libguestfs handle,
- * so the caller must make sure it remains valid for the
- * lifetime of the handle.
- *
* Setting "append" to "NULL" means *no* additional options
* are passed (libguestfs always adds a few of its own).
*
The default is C<NULL> unless overridden by setting
C<LIBGUESTFS_APPEND> environment variable.
-The string C<append> is stashed in the libguestfs handle, so the caller
-must make sure it remains valid for the lifetime of the handle.
-
Setting C<append> to C<NULL> means I<no> additional options
are passed (libguestfs always adds a few of its own).
The default is C<$libdir/guestfs> unless overridden by setting
C<LIBGUESTFS_PATH> environment variable.
-The string C<path> is stashed in the libguestfs handle, so the caller
-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);
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 ();
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.
"""
The default is "$libdir/guestfs" unless overridden by
setting "LIBGUESTFS_PATH" environment variable.
- The string "path" is stashed in the libguestfs handle,
- so the caller must make sure it remains valid for the
- lifetime of the handle.
-
Setting "path" to "NULL" restores the default path.
"""
return libguestfsmod.set_path (self._o, path)
The default is "NULL" unless overridden by setting
"LIBGUESTFS_APPEND" environment variable.
- The string "append" is stashed in the libguestfs handle,
- so the caller must make sure it remains valid for the
- lifetime of the handle.
-
Setting "append" to "NULL" means *no* additional options
are passed (libguestfs always adds a few of its own).
"""
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, [],
The default is C<$libdir/guestfs> unless overridden by setting
C<LIBGUESTFS_PATH> environment variable.
-The string C<path> is stashed in the libguestfs handle, so the caller
-must make sure it remains valid for the lifetime of the handle.
-
Setting C<path> to C<NULL> restores the default path.");
("get_path", (RConstString "path", []), -1, [],
The default is C<NULL> unless overridden by setting
C<LIBGUESTFS_APPEND> environment variable.
-The string C<append> is stashed in the libguestfs handle, so the caller
-must make sure it remains valid for the lifetime of the handle.
-
Setting C<append> to C<NULL> means I<no> additional options
are passed (libguestfs always adds a few of its own).");
int verbose;
int autosync;
- const char *path;
- const char *qemu;
-
- const char *append; /* Append to kernel command line. */
+ char *path; /* Path to kernel, initrd. */
+ char *qemu; /* Qemu binary. */
+ char *append; /* Append to kernel command line. */
char *last_error;
g->verbose = str != NULL && strcmp (str, "1") == 0;
str = getenv ("LIBGUESTFS_PATH");
- g->path = str != NULL ? str : GUESTFS_DEFAULT_PATH;
+ g->path = str != NULL ? strdup (str) : strdup (GUESTFS_DEFAULT_PATH);
+ if (!g->path) goto error;
str = getenv ("LIBGUESTFS_QEMU");
- g->qemu = str != NULL ? str : QEMU;
+ g->qemu = str != NULL ? strdup (str) : strdup (QEMU);
+ if (!g->qemu) goto error;
str = getenv ("LIBGUESTFS_APPEND");
- g->append = str;
+ if (str) {
+ g->append = strdup (str);
+ if (!g->append) goto error;
+ }
g->main_loop = guestfs_get_default_main_loop ();
fprintf (stderr, "new guestfs handle %p\n", g);
return g;
+
+ error:
+ free (g->path);
+ free (g->qemu);
+ free (g->append);
+ free (g);
+ return NULL;
}
void
free (g->msg_in);
free (g->msg_out);
free (g->last_error);
+ free (g->path);
+ free (g->qemu);
+ free (g->append);
free (g);
}
int
guestfs_set_path (guestfs_h *g, const char *path)
{
- if (path == NULL)
- g->path = GUESTFS_DEFAULT_PATH;
- else
- g->path = path;
+ free (g->path);
+ g->path = NULL;
+
+ g->path =
+ path == NULL ?
+ safe_strdup (g, GUESTFS_DEFAULT_PATH) : safe_strdup (g, path);
return 0;
}
int
guestfs_set_qemu (guestfs_h *g, const char *qemu)
{
- if (qemu == NULL)
- g->qemu = QEMU;
- else
- g->qemu = qemu;
+ free (g->qemu);
+ g->qemu = NULL;
+
+ g->qemu = qemu == NULL ? safe_strdup (g, QEMU) : safe_strdup (g, qemu);
return 0;
}
int
guestfs_set_append (guestfs_h *g, const char *append)
{
- g->append = append;
+ free (g->append);
+ g->append = NULL;
+
+ g->append = append ? safe_strdup (g, append) : NULL;
return 0;
}
/* 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 *) g->qemu;
+ g->cmdline[0] = g->qemu;
/* Construct the -net channel parameter for qemu. */
snprintf (vmchannel, sizeof vmchannel,