Re: [PATCH 1/2] lib/procutils: general purpose procfs parsing functions

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

 



On Tue, May 03, 2011 at 09:50:41AM -0300, Davidlohr Bueso wrote:
> > > +	char path[18]; /* lenght of /proc/<5digits-pid>/task/ */
> 
> I guess we can use something based on BUFSIZ (like BUFSIZ/2?). No need
> to make it too big.

 PATH_MAX  (... although GNU/Hurd guys hate it, because they follow
 the universe and the universe is unlimited in space:-)

> > 
> > pid_t is __S32_TYPE, so it would be better to use something larger.
> > 
> > > +	sprintf(path, "/proc/%d/task/", pid);
> > > +
> > > +	dir = opendir(path);
> > > +	if (!dir)
> > > +		goto ret;
> > > +
> > > +	while ((d = readdir(dir))) {
> > > +		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
> > > +			continue;
> > > +		list = (i == 0) ? malloc(sizeof(pid_t)) : 
> > > +			realloc(list, (i + 1) * sizeof(pid_t));
> > 
> >  unnecessary, realloc(NULL, <size>) works like malloc(<size>);
> > 
> > > +		list[i++] = (pid_t) strtol(d->d_name, (char **) NULL, 10);
> > 
> >  this should be more paranoid ;-)
> 
> Something like strtol_or_err()?

 yes, but without err()/warn(), proc_get_next_tid() has to return -1
 on errors.

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux