On Fri, May 22, 2009 at 12:04:24PM +0530, Bharata B Rao wrote:
> On Mon, May 18, 2009 at 02:17:46PM +0530, Dhaval Giani wrote:
> > This set of APIs will allow the caller to query the mount table
> > and find out what controller is mounted at what path.
> > 
> > Test program has been included in the patch. Running the test program
> > results in
> > 
> > [dha...@gondor tests]$ ../libtool --mode=execute ./get_controller
> > Controller cpu is mounted at /cgroup
> > Controller cpuacct is mounted at /cgroup
> > Controller memory is mounted at /cgroup1
> > [dha...@gondor tests]$
> > 
> > Which is the setup on this system.
> > 
> > Signed-off-by: Dhaval Giani <[email protected]>
> > Cc: Jan Safranek <[email protected]>
> > 
> > ---
> >  include/libcgroup.h    |   12 ++++++
> >  src/api.c              |   85 
> > +++++++++++++++++++++++++++++++++++++++++++++++++
> >  src/libcgroup.map      |    3 +
> >  tests/Makefile.am      |    3 +
> >  tests/get_controller.c |   35 ++++++++++++++++++++
> >  5 files changed, 137 insertions(+), 1 deletion(-)
> > 
> > Index: libcg/src/api.c
> > ===================================================================
> > --- libcg.orig/src/api.c
> > +++ libcg/src/api.c
> > @@ -2525,3 +2525,88 @@ int cgroup_get_task_begin(char *cgroup, 
> > 
> >     return ret;
> >  }
> > +
> > +
> > +int cgroup_get_controller_end(void **handle)
> > +{
> > +   int *key = (int *) *handle;
> 
> You call it key here and at other places you call it pos. Want to be
> consistent ?
> 

Sure, will make the change.

> > +
> > +   if (!cgroup_initialized)
> > +           return ECGROUPNOTINITIALIZED;
> > +
> > +   if (!key)
> > +           return ECGINVAL;
> > +
> > +   free(key);
> > +   *handle = NULL;
> > +
> > +   return 0;
> > +}
> > +/*
> > + * name and path will be allocated by the API. The caller *must* free
> > + * name and path before calling into the API again else there will be
> > + * leaks.
> 
> Hmm do you think we are better off taking allocated pointers (of size
> FILENAME_MAX) instead of this semantics where user provides pointers, library
> allocates them, but user frees them.
> 

I'm not sure. Buffer overflows? I've seen both types of
uses so I am not i any camp.

> > + */
> > +int cgroup_get_controller_next(void **handle, char **name, char **path)
> > +{
> > +   int error = 0;
> > +   int *pos = (int *) *handle;
> > +   int ret = 0;
> > +
> > +   if (!cgroup_initialized)
> > +           return ECGROUPNOTINITIALIZED;
> > +
> > +   if (!pos)
> > +           return ECGINVAL;
> > +
> > +   pthread_rwlock_rdlock(&cg_mount_table_lock);
> > +
> > +   if (cg_mount_table[*pos].name[0] == '\0') {
> > +           ret = ECGEOF;
> > +           goto out_unlock;
> > +   }
> > +
> > +   *name = strdup(cg_mount_table[*pos].name);
> > +
> > +   if (!*name) {
> > +           last_errno = errno;
> > +           ret = ECGOTHER;
> > +           goto out_unlock;
> > +   }
> > +
> > +   *path = strdup(cg_mount_table[*pos].path);
> > +
> > +   if (!*path) {
> > +           last_errno = errno;
> > +           ret = ECGOTHER;
> > +           goto out_unlock;
> > +   }
> > +
> > +   (*pos)++;
> > +   *handle = pos;
> > +
> > +out_unlock:
> > +   pthread_rwlock_unlock(&cg_mount_table_lock);
> > +   return ret;
> > +}
> > +
> > +int cgroup_get_controller_begin(void **handle, char **name, char **path)
> > +{
> > +   int *pos;
> > +
> > +   if (!cgroup_initialized)
> > +           return ECGROUPNOTINITIALIZED;
> > +
> > +   pos = malloc(sizeof(int));
> > +
> > +   if (!pos) {
> > +           last_errno = errno;
> > +           return ECGOTHER;
> > +   }
> 
> Do you want to validate name and path pointers with a !NULL check here and
> elsewhere ?
> 

No. Since we are going to allocate them.

-- 
regards,
Dhaval

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to