2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 14:25:49 +00:00

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 <xemul@parallels.com>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
This commit is contained in:
Pavel Emelyanov
2014-07-16 19:48:44 +04:00
parent dda742ec57
commit 586eb55f35

View File

@@ -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;