Re: [PATCH 3/3] Do proper escaping of cgroup resource partitions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Apr 26, 2013 at 05:37:24AM -0600, Eric Blake wrote:
> On 04/26/2013 04:45 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
> > 
> > If a user cgroup name begins with "cgroup.", "_" or with any of
> > the controllers from /proc/cgroups followed by a dot, then they
> > need to be prefixed with a single underscore. eg if there is
> > an object "cpu.service", then this would end up as "_cpu.service"
> > in the cgroup filesystem tree, however, "waldo.service" would
> > stay "waldo.service", at least as long as nobody comes up with
> > a cgroup controller called "waldo".
> 
> Do we also need to consider cgroup names beginning with leading '.'?
> 
> > 
> > Since we require a '.XXXX' suffix on all partitions, there is
> > no scope for clashing with the kernel 'tasks' and 'release_agent'
> > files.
> > 
> > Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
> > ---
> >  src/util/vircgroup.c  | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++
> >  tests/vircgroupmock.c | 27 +++++++++++++---
> >  tests/vircgrouptest.c | 54 ++++++++++++++++++++++++++++++++
> >  3 files changed, 163 insertions(+), 4 deletions(-)
> 
> >  #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
> > +static int virCgroupNeedEscape(const char *path)
> 
> NeedsEscape sounds a bit better than NeedEscape, if you want to make the
> tweak.
> 
> > +static int virCgroupEscape(char **path)
> > +{
> > +    size_t len = strlen(*path);
> > +    int rc;
> > +
> > +    if ((rc = virCgroupNeedEscape(*path)) <= 0)
> > +        return rc;
> > +
> 
> From here...
> 
> > +    if (VIR_REALLOC_N(*path, len + 2) < 0)
> > +        return -ENOMEM;
> > +
> > +    memmove((*path) + 1,
> > +            *path,
> > +            len + 1);
> > +    (*path)[0] = '_';
> 
> ...to here could be simplified to:
> 
> char escape = '_';
> VIR_INSERT_ELEMENT(*path, 0, len, escape);

Hurrah for tests. Caught the fact that I needed

  size_t len = strlen(*path) + 1;

so that VIR_INSERT_ELEMENT keeps the null terminator :-)


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 :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]