On Tue, Apr 21, 2009 at 12:05:55PM +0530, Dhaval Giani wrote:
> On Tue, Apr 21, 2009 at 11:57:34AM +0530, Balbir Singh wrote:
> > * Dhaval Giani <[email protected]> [2009-04-20 19:27:36]:
> > 
> > > +
> > > +int cgroup_get_task_end(void **handle)
> > > +{
> > > + FILE *tasks;
> > > +
> > > + if (!cgroup_initialized)
> > > +         return ECGROUPNOTINITIALIZED;
> > > +
> > 
> > I think we should encapsulate this in an inline function in the future
> > 
> > > + if (!handle)
> > > +         return ECGINVAL;
> > > +
> > > + tasks = (FILE *) *handle;
> >                         ^
> > Extra space here
> 
> hmm. checkpatch did not crib about it. Isn't this more readable?
> 
> > 
> > > +
> > > + if (!tasks)
> > > +         return ECGINVAL;
> > > +
> > > + fclose(tasks);
> > > + tasks = NULL;
> > > + *handle = tasks;

Can't you just have *handle = NULL. What's the point in making tasks NULL ?
Why do you even want to make handle NULL. Won't the same handle used next
time fail during file read ?

> > > +
> > > + return 0;
> > > +}
> > > +
> > > +int cgroup_get_task_next(void **handle, pid_t *pid)
> > > +{
> > > + FILE *tasks;
> > > + int ret;
> > > +
> > > + if (!cgroup_initialized)
> > > +         return ECGROUPNOTINITIALIZED;
> > > +
> > > + if (!handle)
> > > +         return ECGINVAL;
> > > +
> > > + tasks = (FILE *) *handle;
> > > +
> > See above
> > 
> > > + if (feof(tasks))
> > > +         return ECGEOF;
> > > +
> > > + ret = fscanf(tasks, "%u", pid);
> > > +
> > > + if (ret != 1) {
> > > +         *handle = tasks;
> > > +         if (feof(tasks))
> > > +                 return ECGEOF;
> > > +         last_errno = errno;
> > > +         return ECGOTHER;
> > > + }
> > > +
> > > + *handle = tasks;
> > 
> > Do we need to do this all the time? Shouldn't doing this at begin be
> > enough?
> > 
> 
> apparently not. my testing was failing at this very point. So I added
> it.

Looks like a goto (with *handle = tasks at the end) will help.

Regards,
Bharata.

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to