[CRIU] [PATCH 1/2] Re-create cgroups if necessary

Andrew Vagin avagin at parallels.com
Mon Jun 23 23:07:58 PDT 2014


On Mon, Jun 23, 2014 at 11:28:27PM -0500, Tycho Andersen wrote:
> On Tue, Jun 24, 2014 at 08:03:25AM +0400, Andrew Vagin wrote:
> > On Tue, Jun 24, 2014 at 02:29:27AM +0000, Tycho Andersen wrote:
> > > On Mon, Jun 23, 2014 at 10:53:48PM +0400, Andrew Vagin wrote:
> > > >
> > > > Look at my version. It doesn't copy a path in another place.
> > > 
> > > The copy is sort of unfortunate, strtok writes a null byte to the
> > > string it is tokenizing, which seems impolite to do as callers won't
> > > expect it, even though it might not break anything. I used it because
> > > I prefer using library functions to rolling my own, but I'm happy to
> > > switch it if the copy is a big issue.
> > > 
> > > Tycho
> > > 
> > 
> > The copy isn't a big issue. I don't like strtok:).
> 
> That's fair :-)
> 
> > Below you can find a version, which don't modify path in place.
> 
> It still does modify the string, though, which means you can't pass

No, it doesn't. It creates a copy in made_path and does that for one
call and then it modifies this copy.

> read-only memory to mkdirpat, which might also be a little surprising.
> Maybe this version with a copy?

It's up to Pavel.

> 
> Thanks,
> 
> Tycho
> 
> > 
> > 	strcpy(made_path, path)
> > > > 	tok = made_path;
> > > > 	while (tok = strchr(tok + 1, "/")) {
> > > > 		char c;
> > > > 		if (tok != NULL) {
> > > > 			c = *tok;
> > > > 			*tok = 0;
> > > > 		}
> > > > 
> > > > 		if (mkdirat(fd, made_path, 0755) < 0 && errno != EEXIST) {
> > > > 			pr_perror("couldn't mkdirpat directory\n");
> > 			if (tok != NULL)
> > 				*tok = c;
> > > > 			return -1;
> > > > 		}
> > > > 
> > > > 		if (tok == NULL)
> > > > 			break;
> > > > 		else
> > > > 			*tok = c;
> > > > 	}
> > > > 
> > > > Thanks.


More information about the CRIU mailing list