[libvirt] [PATCH] Add a virStrSplitQuoted for splitting quoted strings
Daniel P. Berrange
berrange at redhat.com
Wed Mar 14 17:28:01 UTC 2012
On Wed, Mar 14, 2012 at 11:10:24AM -0600, Eric Blake wrote:
> On 03/14/2012 10:50 AM, Daniel P. Berrange wrote:
> >> This looks like it is repeating some of the code in
> >> virsh.c:vshCommandStringGetArg; any chance we can combine them? In
> >> particular, the ability to mimic shell handling of \ escapes, as well as
> >> the difference in behavior of \ inside "" vs. '', seems like it will
> >> come in handy.
> >
> > Ah I had forgotten about that code. Can you clarify the difference
> > in \ handling. I guess you mean that inside '', \ can only be used
> > for \\ and \', while inside "", it can do all the standard shell
> > escapes like \t, \n, etc ?
>
> Inside '', \ has no special meaning. (There's no way to escape ' inside
> of ').
>
> Inside "", \ escapes the next byte (important for " and \, but works on
> any byte.
>
> Outside quotes, \ escapes the next byte.
>
> And most importantly: concatenating two forms of quoted materials is
> permitted. Thus:
>
> foo"b'ar\" "\'' blah\'
>
> on input becomes this on output:
>
> foob'ar" ' blah\
>
> >>
> >> What you have here does neither; although I didn't spot any flaw in the
> >> code, I don't know if it's the algorithm we want to be using.
> >
> > I should have sent this paired with my other patch for <cmdline>
> > handling in LXC. That is the intended use case for this function.
> >
> > I'm not sure that anyone has ever clearly defined what escaping
> > syntax is used for /proc/cmdline (which is what <cmdline> is
> > representing.
>
> Hmm, good point. If it is /bin/sh doing the parsing, then we know the
> rules (and virsh matches them); but it if is a custom parser in the
> kernel, the we have to match that custom parser.
Hmm, well actually there are multiple consumers of /proc/cmdline
data.
- kernel
- init
- userspace (eg anaconda)
What is the betting that everyone has their own rules :-)
For LXC's purposes though, we don't care about the kernel, only
init. So I guess I should look at what upstart/sysvinit/systemd
do for parsing rules
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list