+static const char *normalize_controller(const char *controller) {
+
+ if (streq(controller, SYSTEMD_CGROUP_CONTROLLER))
+ return "systemd";
+ else if (startswith(controller, "name="))
+ return controller + 5;
+ else
+ return controller;
+}
+
+static int join_path(const char *controller, const char *path, const char *suffix, char **fs) {
+ char *t = NULL;
+
+ if (!(controller || path))
+ return -EINVAL;
+
+ if (controller) {
+ if (path && suffix)
+ t = join("/sys/fs/cgroup/", controller, "/", path, "/", suffix, NULL);
+ else if (path)
+ t = join("/sys/fs/cgroup/", controller, "/", path, NULL);
+ else if (suffix)
+ t = join("/sys/fs/cgroup/", controller, "/", suffix, NULL);
+ else
+ t = join("/sys/fs/cgroup/", controller, NULL);
+ } else {
+ if (path && suffix)
+ t = join(path, "/", suffix, NULL);
+ else if (path)
+ t = strdup(path);
+ }
+
+ if (!t)
+ return -ENOMEM;
+
+ path_kill_slashes(t);
+
+ *fs = t;
+ return 0;
+}
+