[CRIU] [PATCH] proc: read all data from /proc/pid/task/tid/children

Andrew Vagin avagin at odin.com
Mon Oct 26 08:51:19 PDT 2015


On Mon, Oct 26, 2015 at 06:41:13PM +0300, Pavel Emelyanov wrote:
> On 10/26/2015 04:49 PM, Andrey Vagin wrote:
> > From: Andrew Vagin <avagin at openvz.org>
> > 
> > Currently we read only 4096 bytes (the size of buf).
> > 
> > Signed-off-by: Andrew Vagin <avagin at openvz.org>
> > ---
> >  proc_parse.c | 31 ++++++++++++++-----------------
> >  1 file changed, 14 insertions(+), 17 deletions(-)
> > 
> > diff --git a/proc_parse.c b/proc_parse.c
> > index 75ca682..bd6f023 100644
> > --- a/proc_parse.c
> > +++ b/proc_parse.c
> > @@ -2145,40 +2145,37 @@ int parse_children(pid_t pid, pid_t **_c, int *_n)
> >  		return -1;
> >  
> >  	while ((de = readdir(dir))) {
> > -		int fd, len;
> > -		char *pos;
> > +		FILE *f;
> >  
> >  		if (dir_dots(de))
> >  			continue;
> >  
> > -		fd = open_proc(pid, "task/%s/children", de->d_name);
> > -		if (fd < 0)
> > +		f = fopen_proc(pid, "task/%s/children", de->d_name);
> 
> Please, use bfd engine for this.

I use fscanf(), can I use it with bfd?

> 
> > +		if (f == NULL)
> >  			goto err;
> >  
> > -		len = read(fd, buf, BUF_SIZE);
> > -		close(fd);
> > -		if (len < 0)
> > -			goto err;
> > -
> > -		buf[len] = '\0';
> > -		pos = buf;
> >  		while (1) {
> >  			pid_t val, *tmp;
> >  
> > -			val = strtol(pos, &pos, 0);
> > -			if (!val) {
> > -				BUG_ON(*pos != '\0');
> > -				break;
> > +			if (fscanf(f, "%u", &val) < 1) {
> > +				if (feof(f)) {
> > +					fclose(f);
> > +					break;
> > +				}
> > +				pr_perror("Unable to parse task/%s/children", de->d_name);
> > +				fclose(f);
> > +				goto err;
> >  			}
> >  
> >  			tmp = xrealloc(ch, (nr + 1) * sizeof(pid_t));
> > -			if (!tmp)
> > +			if (!tmp) {
> > +				fclose(f);
> >  				goto err;
> > +			}
> >  
> >  			ch = tmp;
> >  			ch[nr] = val;
> >  			nr++;
> > -			pos++; /* space goes after each pid */
> >  		}
> >  	}
> >  
> > 
> 


More information about the CRIU mailing list