summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-07-23 15:24:57 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-07-23 15:24:57 +0100
commit20a5b4de7ddc4221544784df65eb472481698dcb (patch)
treeaf26740bd12c512b5a82471028aac1759223a854 /src
parent7a691e6665ed5079e6baa000c9c475f32ca78475 (diff)
downloadlibguestfs-20a5b4de7ddc4221544784df65eb472481698dcb.tar.gz
libguestfs-20a5b4de7ddc4221544784df65eb472481698dcb.tar.xz
libguestfs-20a5b4de7ddc4221544784df65eb472481698dcb.zip
launch: Allow default attach-method to be set in environment or configure.
You can now choose the default attach method in two ways: (1) Set the LIBGUESTFS_ATTACH_METHOD environment variable. (2) ./configure --with-default-attach-method=appliance|libvirt|... Note that (1) overrides (2).
Diffstat (limited to 'src')
-rw-r--r--src/guestfs.c41
-rw-r--r--src/guestfs.pod5
2 files changed, 40 insertions, 6 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index e13dd9fa..efdf254a 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -72,6 +72,7 @@
#include "guestfs-internal-actions.h"
#include "guestfs_protocol.h"
+static int parse_attach_method (guestfs_h *g, const char *method);
static void default_error_cb (guestfs_h *g, void *data, const char *msg);
static void close_handles (void);
@@ -139,6 +140,19 @@ guestfs_create (void)
} else
g->memsize = 500;
+ str = getenv ("LIBGUESTFS_ATTACH_METHOD");
+ if (str) {
+ if (parse_attach_method (g, str) == -1) {
+ warning (g, _("invalid or unknown value for LIBGUESTFS_ATTACH_METHOD environment variable"));
+ goto error;
+ }
+ } else {
+ if (parse_attach_method (g, DEFAULT_ATTACH_METHOD) == -1) {
+ warning (g, _("libguestfs was built with an invalid default attach-method, using 'appliance' instead"));
+ g->attach_method = ATTACH_METHOD_APPLIANCE;
+ }
+ }
+
/* Start with large serial numbers so they are easy to spot
* inside the protocol.
*/
@@ -162,6 +176,7 @@ guestfs_create (void)
return g;
error:
+ free (g->attach_method_arg);
free (g->path);
free (g->qemu);
free (g->append);
@@ -738,31 +753,45 @@ guestfs__get_network (guestfs_h *g)
return g->enable_network;
}
-int
-guestfs__set_attach_method (guestfs_h *g, const char *method)
+static int
+parse_attach_method (guestfs_h *g, const char *method)
{
if (STREQ (method, "appliance")) {
g->attach_method = ATTACH_METHOD_APPLIANCE;
free (g->attach_method_arg);
g->attach_method_arg = NULL;
+ return 0;
}
- else if (STREQ (method, "libvirt")) {
+
+ if (STREQ (method, "libvirt")) {
g->attach_method = ATTACH_METHOD_LIBVIRT;
free (g->attach_method_arg);
g->attach_method_arg = NULL;
+ return 0;
}
- else if (STRPREFIX (method, "libvirt:") && strlen (method) > 8) {
+
+ if (STRPREFIX (method, "libvirt:") && strlen (method) > 8) {
g->attach_method = ATTACH_METHOD_LIBVIRT;
free (g->attach_method_arg);
g->attach_method_arg = safe_strdup (g, method + 8);
+ return 0;
}
- else if (STRPREFIX (method, "unix:") && strlen (method) > 5) {
+
+ if (STRPREFIX (method, "unix:") && strlen (method) > 5) {
g->attach_method = ATTACH_METHOD_UNIX;
free (g->attach_method_arg);
g->attach_method_arg = safe_strdup (g, method + 5);
/* Note that we don't check the path exists until launch is called. */
+ return 0;
}
- else {
+
+ return -1;
+}
+
+int
+guestfs__set_attach_method (guestfs_h *g, const char *method)
+{
+ if (parse_attach_method (g, method) == -1) {
error (g, "invalid attach method: %s", method);
return -1;
}
diff --git a/src/guestfs.pod b/src/guestfs.pod
index 92bdca04..0e258ab9 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -3332,6 +3332,11 @@ feature is only available in febootstrap E<ge> 3.8.
Pass additional options to the guest kernel.
+=item LIBGUESTFS_ATTACH_METHOD
+
+Choose the default way to create the appliance. See
+L</guestfs_set_attach_method>.
+
=item LIBGUESTFS_DEBUG
Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages. This