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

Tycho Andersen tycho.andersen at canonical.com
Mon Jun 23 21:28:27 PDT 2014


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
read-only memory to mkdirpat, which might also be a little surprising.
Maybe this version with a copy?

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