-static int install_release_agent(Manager *m, const char *mount_point) {
- char *p, *c, *sc;
- int r;
-
- assert(m);
- assert(mount_point);
-
- if (asprintf(&p, "%s/release_agent", mount_point) < 0)
- return -ENOMEM;
-
- if ((r = read_one_line_file(p, &c)) < 0) {
- free(p);
- return r;
- }
-
- sc = strstrip(c);
-
- if (sc[0] == 0) {
- if ((r = write_one_line_file(p, CGROUP_AGENT_PATH "\n" )) < 0) {
- free(p);
- free(c);
- return r;
- }
- } else if (!streq(sc, CGROUP_AGENT_PATH)) {
- free(p);
- free(c);
- return -EEXIST;
- }
-
- free(c);
- free(p);
-
- if (asprintf(&p, "%s/notify_on_release", mount_point) < 0)
- return -ENOMEM;
-
- if ((r = read_one_line_file(p, &c)) < 0) {
- free(p);
- return r;
- }
-
- sc = strstrip(c);
-
- if (streq(sc, "0")) {
- if ((r = write_one_line_file(p, "1\n")) < 0) {
- free(p);
- free(c);
- return r;
- }
- } else if (!streq(sc, "1")) {
- free(p);
- free(c);
- return -EIO;
- }
-
- free(p);
- free(c);
-
- return 0;
-}
-
-static int create_hierarchy_cgroup(Manager *m) {
- struct cgroup *cg;
- int r;
-
- assert(m);
-
- if (!(cg = cgroup_new_cgroup(m->cgroup_hierarchy)))
- return -ENOMEM;
-
- if (!(cgroup_add_controller(cg, m->cgroup_controller))) {
- r = -ENOMEM;
- goto finish;
- }
-
- if ((r = cgroup_create_cgroup(cg, true)) != 0) {
- log_error("Failed to create cgroup hierarchy group: %s", cgroup_strerror(r));
- r = translate_error(r, errno);
- goto finish;
- }
-
- if ((r = cgroup_attach_task(cg)) != 0) {
- log_error("Failed to add ourselves to hierarchy group: %s", cgroup_strerror(r));
- r = translate_error(r, errno);
- goto finish;
- }
-
- r = 0;
-
-finish:
- cgroup_free(&cg);
- return r;
-}
-