summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-08-07 09:51:04 +0100
committerRichard Jones <rjones@trick.home.annexia.org>2009-08-07 09:51:04 +0100
commitf0d6be10c2d7bbf49bfa1cdbcb99e356458aa60f (patch)
tree3c8f41002488e4b059f7f85243e6ddde16cf55ef
parentb5b87cdb764dc757295316878a7fd6e2ff01bec4 (diff)
downloadlibguestfs-f0d6be10c2d7bbf49bfa1cdbcb99e356458aa60f.tar.gz
libguestfs-f0d6be10c2d7bbf49bfa1cdbcb99e356458aa60f.tar.xz
libguestfs-f0d6be10c2d7bbf49bfa1cdbcb99e356458aa60f.zip
Debug: Improve the way the qemu command line is printed.
Change the way the qemu command is displayed to look like this: /usr/bin/qemu-kvm \ -drive file=/tmp/test.img,cache=off,if=virtio \ -m 500 \ -no-reboot \ -kernel /tmp/libguestfsHBJHRh/kernel \ -initrd /tmp/libguestfsHBJHRh/initrd \ [...] This allows the command line to be copied and pasted directly into the shell, and also makes it simpler to read.
-rw-r--r--src/guestfs.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index 186c5708..9560aec0 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -866,6 +866,7 @@ dir_contains_files (const char *dir, ...)
static int build_supermin_appliance (guestfs_h *g, const char *path, char **kernel, char **initrd);
static int test_qemu (guestfs_h *g);
static int qemu_supports (guestfs_h *g, const char *option);
+static void print_cmdline (guestfs_h *g);
static const char *kernel_name = "vmlinuz." REPO "." host_cpu;
static const char *initrd_name = "initramfs." REPO "." host_cpu ".img";
@@ -879,7 +880,7 @@ guestfs_launch (guestfs_h *g)
{
const char *tmpdir;
char dir_template[PATH_MAX];
- int r, i, pmore;
+ int r, pmore;
size_t len;
int wfd[2], rfd[2];
int tries;
@@ -1116,12 +1117,8 @@ guestfs_launch (guestfs_h *g)
incr_cmdline_size (g);
g->cmdline[g->cmdline_size-1] = NULL;
- if (g->verbose) {
- fprintf (stderr, "%s", g->qemu);
- for (i = 0; g->cmdline[i]; ++i)
- fprintf (stderr, " %s", g->cmdline[i]);
- fprintf (stderr, "\n");
- }
+ if (g->verbose)
+ print_cmdline (g);
/* Set up stdin, stdout. */
close (0);
@@ -1301,6 +1298,33 @@ guestfs_launch (guestfs_h *g)
return -1;
}
+/* This function is used to print the qemu command line before it gets
+ * executed, when in verbose mode.
+ */
+static void
+print_cmdline (guestfs_h *g)
+{
+ int i = 0;
+ int needs_quote;
+
+ while (g->cmdline[i]) {
+ if (g->cmdline[i][0] == '-') /* -option starts a new line */
+ fprintf (stderr, " \\\n ");
+
+ if (i > 0) fputc (' ', stderr);
+
+ /* Does it need shell quoting? This only deals with simple cases. */
+ needs_quote = strcspn (g->cmdline[i], " ") != strlen (g->cmdline[i]);
+
+ if (needs_quote) fputc ('\'', stderr);
+ fprintf (stderr, "%s", g->cmdline[i]);
+ if (needs_quote) fputc ('\'', stderr);
+ i++;
+ }
+
+ fputc ('\n', stderr);
+}
+
/* This function does the hard work of building the supermin appliance
* on the fly. 'path' is the directory containing the control files.
* 'kernel' and 'initrd' are where we will return the names of the