From: Richard W.M. Jones Date: Wed, 13 May 2009 17:03:41 +0000 (+0100) Subject: Don't stash strings in the handle. X-Git-Tag: 1.0.26~12 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=5d628a4a9cc11eb9a61a1dc683aadca9ac378736;p=libguestfs.git Don't stash strings in the handle. - makes it impossible to write bindings for set_{path,qemu,append} functions --- diff --git a/fish/cmds.c b/fish/cmds.c index 47c66da..1e442d8 100644 --- a/fish/cmds.c +++ b/fish/cmds.c @@ -168,19 +168,19 @@ void display_command (const char *cmd) pod2text ("config - add qemu parameters", " config \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 string must be a C<-> (dash).\n\nC 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 \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\nenvironment variable.\n\nThe string C is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C to C 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 \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\nenvironment variable.\n\nSetting C to C 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 \n\nSet the path that libguestfs searches for kernel and initrd.img.\n\nThe default is C<$libdir/guestfs> unless overridden by setting\nC environment variable.\n\nThe string C is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C to C restores the default path.\n\nYou can use 'path' as an alias for this command."); + pod2text ("set-path - set the search path", " set-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 environment variable.\n\nSetting C to C 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 \n\nThis function is used to add additional options to the\nguest kernel command line.\n\nThe default is C unless overridden by setting\nC environment variable.\n\nThe string C is stashed in the libguestfs handle, so the caller\nmust make sure it remains valid for the lifetime of the handle.\n\nSetting C to C means I 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 \n\nThis function is used to add additional options to the\nguest kernel command line.\n\nThe default is C unless overridden by setting\nC environment variable.\n\nSetting C to C means I 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 then no options are added."); diff --git a/guestfish-actions.pod b/guestfish-actions.pod index 20c34a5..9146c41 100644 --- a/guestfish-actions.pod +++ b/guestfish-actions.pod @@ -968,9 +968,6 @@ guest kernel command line. The default is C unless overridden by setting C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C means I additional options are passed (libguestfs always adds a few of its own). @@ -1018,9 +1015,6 @@ Set the path that libguestfs searches for kernel and initrd.img. The default is C<$libdir/guestfs> unless overridden by setting C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C restores the default path. =head2 set-qemu | qemu @@ -1035,9 +1029,6 @@ configure script. You can also override this by setting the C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C restores the default qemu binary. =head2 set-verbose | verbose diff --git a/guestfs-actions.pod b/guestfs-actions.pod index 7de041c..53bfa54 100644 --- a/guestfs-actions.pod +++ b/guestfs-actions.pod @@ -1295,9 +1295,6 @@ guest kernel command line. The default is C unless overridden by setting C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C means I additional options are passed (libguestfs always adds a few of its own). @@ -1370,9 +1367,6 @@ Set the path that libguestfs searches for kernel and initrd.img. The default is C<$libdir/guestfs> unless overridden by setting C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C restores the default path. This function returns 0 on success or -1 on error. @@ -1390,9 +1384,6 @@ configure script. You can also override this by setting the C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C restores the default qemu binary. This function returns 0 on success or -1 on error. diff --git a/java/com/redhat/et/libguestfs/GuestFS.java b/java/com/redhat/et/libguestfs/GuestFS.java index d0b3446..c816baa 100644 --- a/java/com/redhat/et/libguestfs/GuestFS.java +++ b/java/com/redhat/et/libguestfs/GuestFS.java @@ -229,10 +229,6 @@ public class GuestFS { * 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. * @@ -277,10 +273,6 @@ public class GuestFS { * 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 @@ -324,10 +316,6 @@ public class GuestFS { * 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). * diff --git a/perl/lib/Sys/Guestfs.pm b/perl/lib/Sys/Guestfs.pm index d803ce1..13c084f 100644 --- a/perl/lib/Sys/Guestfs.pm +++ b/perl/lib/Sys/Guestfs.pm @@ -889,9 +889,6 @@ guest kernel command line. The default is C unless overridden by setting C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C means I additional options are passed (libguestfs always adds a few of its own). @@ -938,9 +935,6 @@ Set the path that libguestfs searches for kernel and initrd.img. The default is C<$libdir/guestfs> unless overridden by setting C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C restores the default path. =item $h->set_qemu ($qemu); @@ -953,9 +947,6 @@ configure script. You can also override this by setting the C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C restores the default qemu binary. =item $h->set_ready (); diff --git a/python/guestfs.py b/python/guestfs.py index 324dea5..e61ba65 100644 --- a/python/guestfs.py +++ b/python/guestfs.py @@ -152,10 +152,6 @@ class GuestFS: 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. """ @@ -176,10 +172,6 @@ class GuestFS: 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) @@ -199,10 +191,6 @@ class GuestFS: 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). """ diff --git a/src/generator.ml b/src/generator.ml index fdd4ae6..7edfe67 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -305,9 +305,6 @@ configure script. You can also override this by setting the C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C restores the default qemu binary."); ("get_qemu", (RConstString "qemu", []), -1, [], @@ -328,9 +325,6 @@ Set the path that libguestfs searches for kernel and initrd.img. The default is C<$libdir/guestfs> unless overridden by setting C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C restores the default path."); ("get_path", (RConstString "path", []), -1, [], @@ -352,9 +346,6 @@ guest kernel command line. The default is C unless overridden by setting C environment variable. -The string C is stashed in the libguestfs handle, so the caller -must make sure it remains valid for the lifetime of the handle. - Setting C to C means I additional options are passed (libguestfs always adds a few of its own)."); diff --git a/src/guestfs.c b/src/guestfs.c index 646be77..b30ade0 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -158,10 +158,9 @@ struct guestfs_h 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; @@ -222,13 +221,18 @@ guestfs_create (void) 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 (); @@ -253,6 +257,13 @@ guestfs_create (void) 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 @@ -316,6 +327,9 @@ guestfs_close (guestfs_h *g) free (g->msg_in); free (g->msg_out); free (g->last_error); + free (g->path); + free (g->qemu); + free (g->append); free (g); } @@ -516,10 +530,12 @@ guestfs_get_autosync (guestfs_h *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; } @@ -532,10 +548,10 @@ guestfs_get_path (guestfs_h *g) 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; } @@ -548,7 +564,10 @@ guestfs_get_qemu (guestfs_h *g) 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; } @@ -773,7 +792,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 *) g->qemu; + g->cmdline[0] = g->qemu; /* Construct the -net channel parameter for qemu. */ snprintf (vmchannel, sizeof vmchannel,