X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Flaunch.c;h=1f68346a41847e8a8208528cf2fd1a7cd973025f;hb=ed87e28af0e4099afd11b9543ab29d7b95b0b9e8;hp=0d7a3f344db2fd3302a80f0b9073002ff8e4c16c;hpb=d7dad641943ef718302be47cc89ff55d9032b018;p=libguestfs.git diff --git a/src/launch.c b/src/launch.c index 0d7a3f3..1f68346 100644 --- a/src/launch.c +++ b/src/launch.c @@ -255,7 +255,6 @@ dir_contains_files (const char *dir, ...) return 1; } -static void print_timestamped_message (guestfs_h *g, const char *fs, ...); static int build_supermin_appliance (guestfs_h *g, const char *path, char **kernel, char **initrd); static int is_openable (guestfs_h *g, const char *path, int flags); static void print_cmdline (guestfs_h *g); @@ -266,8 +265,6 @@ static const char *initrd_name = "initramfs." REPO "." host_cpu ".img"; int guestfs__launch (guestfs_h *g) { - const char *tmpdir; - char dir_template[PATH_MAX]; int r, pmore; size_t len; int wfd[2], rfd[2]; @@ -293,16 +290,11 @@ guestfs__launch (guestfs_h *g) gettimeofday (&g->launch_t, NULL); /* Make the temporary directory. */ -#ifdef P_tmpdir - tmpdir = P_tmpdir; -#else - tmpdir = "/tmp"; -#endif - - tmpdir = getenv ("TMPDIR") ? : tmpdir; - snprintf (dir_template, sizeof dir_template, "%s/libguestfsXXXXXX", tmpdir); - if (!g->tmpdir) { + const char *tmpdir = guestfs___tmpdir (); + char dir_template[strlen (tmpdir) + 32]; + sprintf (dir_template, "%s/libguestfsXXXXXX", tmpdir); + g->tmpdir = safe_strdup (g, dir_template); if (mkdtemp (g->tmpdir) == NULL) { perrorf (g, _("%s: cannot create temporary directory"), dir_template); @@ -407,7 +399,7 @@ guestfs__launch (guestfs_h *g) } if (g->verbose) - print_timestamped_message (g, "begin testing qemu features"); + guestfs___print_timestamped_message (g, "begin testing qemu features"); /* Get qemu help text and version. */ if (qemu_supports (g, NULL) == -1) @@ -470,7 +462,7 @@ guestfs__launch (guestfs_h *g) } if (g->verbose) - print_timestamped_message (g, "finished testing qemu features"); + guestfs___print_timestamped_message (g, "finished testing qemu features"); r = fork (); if (r == -1) { @@ -493,6 +485,9 @@ guestfs__launch (guestfs_h *g) */ g->cmdline[0] = g->qemu; + if (qemu_supports (g, "-nodefconfig")) + add_cmdline (g, "-nodefconfig"); + /* qemu sometimes needs this option to enable hardware * virtualization, but some versions of 'qemu-kvm' will use KVM * regardless (even where this option appears in the help text). @@ -837,7 +832,7 @@ guestfs__launch (guestfs_h *g) } if (g->verbose) - print_timestamped_message (g, "appliance is up"); + guestfs___print_timestamped_message (g, "appliance is up"); /* This is possible in some really strange situations, such as * guestfsd starts up OK but then qemu immediately exits. Check for @@ -877,6 +872,23 @@ guestfs__launch (guestfs_h *g) return -1; } +const char * +guestfs___tmpdir (void) +{ + const char *tmpdir; + +#ifdef P_tmpdir + tmpdir = P_tmpdir; +#else + tmpdir = "/tmp"; +#endif + + const char *t = getenv ("TMPDIR"); + if (t) tmpdir = t; + + return tmpdir; +} + /* This function is used to print the qemu command line before it gets * executed, when in verbose mode. */ @@ -918,7 +930,7 @@ build_supermin_appliance (guestfs_h *g, const char *path, int r, len; if (g->verbose) - print_timestamped_message (g, "begin building supermin appliance"); + guestfs___print_timestamped_message (g, "begin building supermin appliance"); len = strlen (g->tmpdir); *kernel = safe_malloc (g, len + 8); @@ -941,7 +953,7 @@ build_supermin_appliance (guestfs_h *g, const char *path, path, *kernel, *initrd); if (g->verbose) - print_timestamped_message (g, "%s", cmd); + guestfs___print_timestamped_message (g, "%s", cmd); r = system (cmd); if (r == -1 || WEXITSTATUS(r) != 0) { @@ -953,7 +965,7 @@ build_supermin_appliance (guestfs_h *g, const char *path, } if (g->verbose) - print_timestamped_message (g, "finished building supermin appliance"); + guestfs___print_timestamped_message (g, "finished building supermin appliance"); return 0; } @@ -972,8 +984,8 @@ timeval_diff (const struct timeval *x, const struct timeval *y) return msec; } -static void -print_timestamped_message (guestfs_h *g, const char *fs, ...) +void +guestfs___print_timestamped_message (guestfs_h *g, const char *fs, ...) { va_list args; char *msg;