- cgroup_free(&cg);
- return r;
-}
-
-int manager_setup_cgroup(Manager *m) {
- char *mp, *cp;
- int r;
- pid_t pid;
- char suffix[32];
-
- assert(m);
-
- if ((r = cgroup_init()) != 0) {
- log_error("Failed to initialize libcg: %s", cgroup_strerror(r));
- return translate_error(r, errno);
- }
-
- free(m->cgroup_controller);
- if (!(m->cgroup_controller = strdup("name=systemd")))
- return -ENOMEM;
-
- if ((r = cgroup_get_subsys_mount_point(m->cgroup_controller, &mp)))
- return translate_error(r, errno);
-
- pid = getpid();
-
- if ((r = cgroup_get_current_controller_path(pid, m->cgroup_controller, &cp))) {
- free(mp);
- return translate_error(r, errno);
- }
-
- snprintf(suffix, sizeof(suffix), "/systemd-%u", (unsigned) pid);
- char_array_0(suffix);
-
- free(m->cgroup_hierarchy);
-
- if (endswith(cp, suffix))
- /* We probably got reexecuted and can continue to use our root cgroup */
- m->cgroup_hierarchy = cp;
- else {
- /* We need a new root cgroup */
-
- m->cgroup_hierarchy = NULL;
- r = asprintf(&m->cgroup_hierarchy, "%s%s", streq(cp, "/") ? "" : cp, suffix);
- free(cp);
-
- if (r < 0) {
- free(mp);
- return -ENOMEM;
- }
- }
-
- log_debug("Using cgroup controller <%s>, hierarchy mounted at <%s>, using root group <%s>.",
- m->cgroup_controller,
- mp,
- m->cgroup_hierarchy);
-
- if ((r = install_release_agent(m, mp)) < 0)
- log_warning("Failed to install release agent, ignoring: %s", strerror(-r));
- else
- log_debug("Installed release agent, or already installed.");
-
- free(mp);
-
- if ((r = create_hierarchy_cgroup(m)) < 0)
- log_error("Failed to create root cgroup hierarchy: %s", strerror(-r));
- else
- log_debug("Created root group.");