[libvirt] [PATCH 1/4] Add APIs for formatting systemd slice/scope names
Daniel P. Berrange
berrange at redhat.com
Tue Jul 30 18:47:54 UTC 2013
On Tue, Jul 30, 2013 at 12:05:51PM -0600, Eric Blake wrote:
> On 07/26/2013 09:48 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" <berrange at redhat.com>
> >
> > There are some interesting escaping rules to consider when dealing
> > with systemd slice/scope names. Thus it is helpful to have APIs
> > for formatting names
> >
> > Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> > ---
> > src/libvirt_private.syms | 2 ++
> > src/util/virsystemd.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++--
> > src/util/virsystemd.h | 5 +++
> > tests/virsystemdtest.c | 48 +++++++++++++++++++++++++
> > 4 files changed, 144 insertions(+), 2 deletions(-)
> >
>
> > +
> > +#define VALID_CHARS \
> > + "0123456789" \
> > + "abcdefghijklmnopqrstuvwxyz" \
> > + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
> > + ":-_.\\"
>
> If you would remove - and \\ from this list...
This is the set that systemd uses, and we need to match it
exactly, otherwise we won't detect the cgroups correctly.
>
> > +
> > + if (*name == '.') {
> > + ESCAPE(*name);
> > + name++;
> > + }
> > +
> > + while (*name) {
> > + if (*name == '/')
> > + virBufferAddChar(buf, '-');
> > + else if (*name == '-' ||
> > + *name == '\\' ||
> > + !strchr(VALID_CHARS, *name))
>
> ...then this could be simplified to just !strchr().
>
> > +
> > +
> > +char *virSystemdMakeScopeName(const char *name,
>
> Is it worth using the style:
>
> char *
> virSystemdMakeScopeName(...
>
> > + TEST_SCOPE("demo", "/machine/eng-dept/testing!stuff", "machine-eng\\x2ddept-testing\\x21stuff-lxc\\x2ddemo.scope");
>
> Worth wrapping the long line.
>
> ACK.
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