On 08/21/2015 09:36 AM, Kővágó, Zoltán wrote: > This will let us print options in a format that the user would actually > write it on the command line (foo=bar,baz=asd,etc=def), without > prepending a spurious comma at the beginning of the list, or quoting > values unnecessarily. This patch provides the following changes: > * write id=, if the option has an id > * do not print separator before the first element > * do not quote string arguments > * properly escape commas (,) for QEMU > > Reviewed-by: Markus Armbruster <arm...@redhat.com> > Reviewed-by: Stefan Hajnoczi <stefa...@redhat.com> > Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com> > Signed-off-by: Kővágó, Zoltán <dirty.ice...@gmail.com> > ---
> +++ b/util/qemu-option.c > @@ -730,14 +730,35 @@ void qemu_opts_del(QemuOpts *opts) > g_free(opts); > } > > -void qemu_opts_print(QemuOpts *opts, const char *sep) > +/* print value, escaping any commas in value */ > +static void escaped_print(const char *value) > +{ > + const char *ptr; > + > + for (ptr = value; *ptr; ++ptr) { > + if (*ptr == ',') { > + putchar(','); > + } > + putchar(*ptr); > + } I guess this not in a hot path. (If it were, I might suggest using strchr() to skip to the next command, and fwrite() to output blocks of data between commas, rather than putchar() at a time; but unless it shows up in a benchmark that might be premature optimization) -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature