diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-07-20 11:57:10 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-07-20 13:49:10 +0100 |
commit | 08cad543492c9624be0659dfb18b7a8b21de8fba (patch) | |
tree | e7a12e893f9e4e540b7282d62ddafd0990ed7246 | |
parent | 52fa23d74f6308daf804c2330b0b27e0b4412594 (diff) | |
download | libguestfs-08cad543492c9624be0659dfb18b7a8b21de8fba.tar.gz libguestfs-08cad543492c9624be0659dfb18b7a8b21de8fba.tar.xz libguestfs-08cad543492c9624be0659dfb18b7a8b21de8fba.zip |
launch: Move the command line building code entirely into launch-appliance.c.
Although we still use the handle as convenient temporary
storage.
-rw-r--r-- | src/guestfs-internal.h | 2 | ||||
-rw-r--r-- | src/guestfs.c | 8 | ||||
-rw-r--r-- | src/launch-appliance.c | 56 |
3 files changed, 19 insertions, 47 deletions
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index b33605c3..180e599e 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -246,7 +246,7 @@ struct guestfs_h char *qemu_version; /* Output of qemu -version. */ char *qemu_devices; /* Output of qemu -device ? */ - char **cmdline; /* Qemu command line. */ + char **cmdline; /* Only used in child, does not need freeing. */ size_t cmdline_size; bool virtio_scsi; /* See function qemu_supports_virtio_scsi */ diff --git a/src/guestfs.c b/src/guestfs.c index 19f75f01..00a32db5 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -233,14 +233,6 @@ guestfs_close (guestfs_h *g) guestfs___free_inspect_info (g); guestfs___free_drives (&g->drives); - if (g->cmdline) { - size_t i; - - for (i = 0; i < g->cmdline_size; ++i) - free (g->cmdline[i]); - free (g->cmdline); - } - for (qp = g->qemu_params; qp; qp = qp_next) { free (qp->qemu_param); free (qp->qemu_value); diff --git a/src/launch-appliance.c b/src/launch-appliance.c index d6ee3045..3be7fe20 100644 --- a/src/launch-appliance.c +++ b/src/launch-appliance.c @@ -43,55 +43,41 @@ static int qemu_supports_virtio_scsi (guestfs_h *g); static char *qemu_drive_param (guestfs_h *g, const struct drive *drv, size_t index); static char *drive_name (size_t index, char *ret); -/* Functions to add a string to the current command line. */ +/* Functions to build up the qemu command line. These are only run + * in the child process so no clean-up is required. + */ static void alloc_cmdline (guestfs_h *g) { - if (g->cmdline == NULL) { - /* g->cmdline[0] is reserved for argv[0], set in guestfs_launch. */ - g->cmdline_size = 1; - g->cmdline = safe_malloc (g, sizeof (char *)); - g->cmdline[0] = NULL; - } + g->cmdline_size = 1; + g->cmdline = safe_malloc (g, sizeof (char *)); + g->cmdline[0] = g->qemu; } static void incr_cmdline_size (guestfs_h *g) { - alloc_cmdline (g); g->cmdline_size++; - g->cmdline = safe_realloc (g, g->cmdline, sizeof (char *) * g->cmdline_size); + g->cmdline = + safe_realloc (g, g->cmdline, sizeof (char *) * g->cmdline_size); } -static int +static void add_cmdline (guestfs_h *g, const char *str) { - if (g->state != CONFIG) { - error (g, - _("command line cannot be altered after qemu subprocess launched")); - return -1; - } - incr_cmdline_size (g); g->cmdline[g->cmdline_size-1] = safe_strdup (g, str); - return 0; } /* Like 'add_cmdline' but allowing a shell-quoted string of zero or * more options. XXX The unquoting is not very clever. */ -static int +static void add_cmdline_shell_unquoted (guestfs_h *g, const char *options) { char quote; const char *startp, *endp, *nextp; - if (g->state != CONFIG) { - error (g, - _("command line cannot be altered after qemu subprocess launched")); - return -1; - } - while (*options) { quote = *options; if (quote == '\'' || quote == '"') @@ -104,9 +90,10 @@ add_cmdline_shell_unquoted (guestfs_h *g, const char *options) endp = strchr (options, quote); if (endp == NULL) { if (quote != ' ') { - error (g, _("unclosed quote character (%c) in command line near: %s"), - quote, options); - return -1; + fprintf (stderr, + _("unclosed quote character (%c) in command line near: %s"), + quote, options); + _exit (EXIT_FAILURE); } endp = options + strlen (options); } @@ -119,20 +106,19 @@ add_cmdline_shell_unquoted (guestfs_h *g, const char *options) else if (endp[1] == ' ') nextp = endp+2; else { - error (g, _("cannot parse quoted string near: %s"), options); - return -1; + fprintf (stderr, _("cannot parse quoted string near: %s"), options); + _exit (EXIT_FAILURE); } } while (*nextp && *nextp == ' ') nextp++; incr_cmdline_size (g); - g->cmdline[g->cmdline_size-1] = safe_strndup (g, startp, endp-startp); + g->cmdline[g->cmdline_size-1] = + safe_strndup (g, startp, endp-startp); options = nextp; } - - return 0; } /* RHBZ#790721: It makes no sense to have multiple threads racing to @@ -243,13 +229,7 @@ guestfs___launch_appliance (guestfs_h *g) /* Set up the full command line. Do this in the subprocess so we * don't need to worry about cleaning up. */ - - /* Set g->cmdline[0] to the name of the qemu process. However - * it is possible that no g->cmdline has been allocated yet so - * we must do that first. - */ alloc_cmdline (g); - g->cmdline[0] = g->qemu; /* Add any qemu parameters. */ for (qp = g->qemu_params; qp; qp = qp->next) { |