[CRIU] [PATCH 1/2] Re-create cgroups if necessary
Andrew Vagin
avagin at parallels.com
Mon Jun 23 11:29:53 PDT 2014
On Mon, Jun 23, 2014 at 03:54:22PM +0000, Tycho Andersen wrote:
> If a task had cgroups, these should be restored. (Also any properties of
> cgroups, but this commit doesn't do that yet.)
>
> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
> ---
> cgroup.c | 6 +++++-
> include/util.h | 5 +++++
> util.c | 26 ++++++++++++++++++++++++++
> 3 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/cgroup.c b/cgroup.c
> index 2d9ebad..8b2deb2 100644
> --- a/cgroup.c
> +++ b/cgroup.c
> @@ -258,9 +258,13 @@ static int move_in_cgroup(CgSetEntry *se)
> int fd, err;
> ControllerEntry *ce = se->ctls[i];
>
> + sprintf(aux, "%s/%s", ce->name, ce->path);
> + if (mkdirpat(cg, aux) < 0)
> + return -1;
> +
> sprintf(aux, "%s/%s/tasks", ce->name, ce->path);
> pr_debug(" `-> %s\n", aux);
> - err = fd = openat(cg, aux, O_WRONLY);
> + err = fd = openat(cg, aux, O_WRONLY | O_CREAT, 0700);
> if (fd >= 0) {
> /*
> * Writing zero into this file moves current
> diff --git a/include/util.h b/include/util.h
> index 22a0f3d..e2ec22e 100644
> --- a/include/util.h
> +++ b/include/util.h
> @@ -303,4 +303,9 @@ static inline bool strstartswith(char *str, char *sub)
> }
> }
>
> +/*
> + * mkdir -p for a file descriptor
> + */
> +int mkdirpat(int fd, const char* path);
> +
> #endif /* __CR_UTIL_H__ */
> diff --git a/util.c b/util.c
> index 975af30..7d235c6 100644
> --- a/util.c
> +++ b/util.c
> @@ -677,3 +677,29 @@ struct vma_area *alloc_vma_area(void)
>
> return p;
> }
> +
> +int mkdirpat(int fd, const char* path)
> +{
> + char* tok;
> + char made_path[PATH_MAX] = "", tok_path[PATH_MAX];
> +
> + if (strlen(path) < PATH_MAX)
> + {
> + pr_err("path %s is longer than PATH_MAX", path);
> + return -1;
> + }
> +
> + strncpy(tok_path, path, PATH_MAX);
> +
> + for(tok = strtok(tok_path, "/"); tok; tok = strtok(NULL, "/")) {
tok = strtok(NULL, "/") always returns NULL
> + strcat(made_path, tok);
> + strcat(made_path, "/");
> + if (mkdirat(fd, made_path, 0755) < 0 && errno != EEXIST) {
> + pr_perror("couldn't mkdirpat directory\n");
> + return -1;
> + }
> + }
> +
> + return 0;
> +
> +}
> --
> 1.9.1
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list