return;
}
-
-#define INIT_SCOPE "/init.scope"
-char *prune_init_scope(char *cg)
-{
- if (is_empty_string(cg))
- return NULL;
-
- if (strnequal(cg, INIT_SCOPE, STRLITERALLEN(INIT_SCOPE)))
- return cg + STRLITERALLEN(INIT_SCOPE);
-
- return cg;
-}
__hidden extern void cgroup_exit(struct cgroup_ops *ops);
define_cleanup_function(struct cgroup_ops *, cgroup_exit);
-__hidden extern char *prune_init_scope(char *cg);
-
__hidden extern int cgroup_attach(const struct lxc_conf *conf, const char *name,
const char *lxcpath, pid_t pid);
__hidden extern int cgroup_get(const char *name, const char *lxcpath,
return 0;
}
+
+#define INIT_SCOPE "/init.scope"
+char *prune_init_scope(char *path)
+{
+ char *slash = path;
+ size_t len;
+
+ /*
+ * This function can only be called on information parsed from
+ * /proc/<pid>/cgroup. The file displays the current cgroup of the
+ * process as absolute paths. So if we are passed a non-absolute path
+ * things are way wrong.
+ */
+ if (!abspath(path))
+ return ret_set_errno(NULL, EINVAL);
+
+ len = strlen(path);
+ if (len < STRLITERALLEN(INIT_SCOPE))
+ return path;
+
+ slash += (len - STRLITERALLEN(INIT_SCOPE));
+ if (strequal(slash, INIT_SCOPE)) {
+ if (slash == path)
+ slash++;
+ *slash = '\0';
+ }
+
+ return path;
+}
__hidden extern int cgroup_tree_prune(int dfd, const char *path);
+/*
+ * This function can only be called on information parsed from
+ * /proc/<pid>/cgroup or on absolute paths and it will verify the latter and
+ * return NULL if a relative path is passed.
+ */
+__hidden extern char *prune_init_scope(char *path);
+
#endif /* __LXC_CGROUP_UTILS_H */