From 586eb55f35af9d3cb7b1b526fac2cb7c9a4d33e5 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 16 Jul 2014 19:48:44 +0400 Subject: [PATCH] cg: Trim proper prefix from ftw's path After the commit that walks /proc/self/fd/N path instead of the temporary one, the add_cgroup() started trimming first several bytes from the cgroup path. Test passed, since all cgroups were left as is after dump, so criu restore didn't recreate them but got EEXIST on all mkdir-s. Signed-off-by: Pavel Emelyanov Acked-by: Tycho Andersen --- cgroup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cgroup.c b/cgroup.c index 71ac271ee..fcd57fc3d 100644 --- a/cgroup.c +++ b/cgroup.c @@ -195,6 +195,7 @@ static bool cgroup_contains(char **controllers, unsigned int n_controllers, char /* This is for use in add_cgroup() as additional arguments for the ftw() * callback */ static struct cg_controller *current_controller; +static unsigned int path_pref_len; #define EXACT_MATCH 0 #define PARENT_MATCH 1 @@ -242,8 +243,8 @@ static int add_cgroup(const char *fpath, const struct stat *sb, int typeflag) goto out; } - /* chop off the first strlen(".criu.cgmounts.XXXXXX") */ - ncd->path = xstrdup(fpath + 21); + /* chop off the first "/proc/self/fd/N" str */ + ncd->path = xstrdup(fpath + path_pref_len); if (!ncd->path) { ret = -1; goto out; @@ -316,7 +317,8 @@ static int collect_cgroups(struct list_head *ctls) if (fd < 0) return -1; - snprintf(path, PATH_MAX, "/proc/self/fd/%d/%s", fd, cc->path); + path_pref_len = snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd); + snprintf(path + path_pref_len, PATH_MAX - path_pref_len, "%s", cc->path); current_controller = NULL;