From: Lennart Poettering Date: Sat, 10 Jul 2010 15:38:50 +0000 (+0200) Subject: cgroup: make cgroup controller name a constant X-Git-Tag: v3~55 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55096547212928b0ba83fca2595cae0d66d3c0b0;p=systemd cgroup: make cgroup controller name a constant --- diff --git a/src/cgroup.c b/src/cgroup.c index 244a6020..83fe2ef2 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -222,18 +222,14 @@ int manager_setup_cgroup(Manager *m) { return cg_translate_error(r, errno); } - free(m->cgroup_controller); - if (!(m->cgroup_controller = strdup("name=systemd"))) - return -ENOMEM; - free(m->cgroup_mount_point); m->cgroup_mount_point = NULL; - if ((r = cgroup_get_subsys_mount_point(m->cgroup_controller, &m->cgroup_mount_point))) + if ((r = cgroup_get_subsys_mount_point(SYSTEMD_CGROUP_CONTROLLER, &m->cgroup_mount_point))) return cg_translate_error(r, errno); pid = getpid(); - if ((r = cgroup_get_current_controller_path(pid, m->cgroup_controller, &cp))) + if ((r = cgroup_get_current_controller_path(pid, SYSTEMD_CGROUP_CONTROLLER, &cp))) return cg_translate_error(r, errno); snprintf(suffix, sizeof(suffix), "/systemd-%u", (unsigned) pid); @@ -255,17 +251,16 @@ int manager_setup_cgroup(Manager *m) { return -ENOMEM; } - log_debug("Using cgroup controller <%s>, hierarchy mounted at <%s>, using root group <%s>.", - m->cgroup_controller, + log_debug("Using cgroup controller <" SYSTEMD_CGROUP_CONTROLLER ">, hierarchy mounted at <%s>, using root group <%s>.", m->cgroup_mount_point, m->cgroup_hierarchy); - if ((r = cg_install_release_agent(m->cgroup_controller, CGROUP_AGENT_PATH)) < 0) + if ((r = cg_install_release_agent(SYSTEMD_CGROUP_CONTROLLER, CGROUP_AGENT_PATH)) < 0) log_warning("Failed to install release agent, ignoring: %s", strerror(-r)); else log_debug("Installed release agent, or already installed."); - if ((r = cg_create_and_attach(m->cgroup_controller, m->cgroup_hierarchy, 0)) < 0) + if ((r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_hierarchy, 0)) < 0) log_error("Failed to create root cgroup hierarchy: %s", strerror(-r)); else log_debug("Created root group."); @@ -276,10 +271,10 @@ int manager_setup_cgroup(Manager *m) { int manager_shutdown_cgroup(Manager *m) { assert(m); - if (!m->cgroup_controller || !m->cgroup_hierarchy) + if (!m->cgroup_hierarchy) return 0; - return cg_delete(m->cgroup_controller, m->cgroup_hierarchy); + return cg_delete(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_hierarchy); } int cgroup_notify_empty(Manager *m, const char *group) { @@ -324,7 +319,7 @@ Unit* cgroup_unit_by_pid(Manager *m, pid_t pid) { if (pid <= 1) return NULL; - if ((r = cg_get_by_pid(m->cgroup_controller, pid, &group))) + if ((r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, pid, &group))) return NULL; l = hashmap_get(m->cgroup_bondings, group); diff --git a/src/cgroup.h b/src/cgroup.h index 05c858c4..a7ca8abb 100644 --- a/src/cgroup.h +++ b/src/cgroup.h @@ -26,6 +26,8 @@ typedef struct CGroupBonding CGroupBonding; #include "unit.h" +#define SYSTEMD_CGROUP_CONTROLLER "name=systemd" + /* Binds a cgroup to a name */ struct CGroupBonding { char *controller; diff --git a/src/manager.c b/src/manager.c index 524d125b..8d016b9f 100644 --- a/src/manager.c +++ b/src/manager.c @@ -443,7 +443,6 @@ void manager_free(Manager *m) { lookup_paths_free(&m->lookup_paths); strv_free(m->environment); - free(m->cgroup_controller); free(m->cgroup_hierarchy); free(m->cgroup_mount_point); diff --git a/src/manager.h b/src/manager.h index b44ffe27..e5915d37 100644 --- a/src/manager.h +++ b/src/manager.h @@ -171,7 +171,6 @@ struct Manager { /* Data specific to the cgroup subsystem */ Hashmap *cgroup_bondings; /* path string => CGroupBonding object 1:n */ - char *cgroup_controller; char *cgroup_mount_point; char *cgroup_hierarchy; diff --git a/src/unit.c b/src/unit.c index 18faae22..5d51f999 100644 --- a/src/unit.c +++ b/src/unit.c @@ -1598,7 +1598,7 @@ int unit_add_cgroup_from_text(Unit *u, const char *name) { if (n > 0) controller = strndup(name, n); else - controller = strdup(u->meta.manager->cgroup_controller); + controller = strdup(SYSTEMD_CGROUP_CONTROLLER); if (!controller) { r = -ENOMEM; @@ -1647,7 +1647,7 @@ int unit_add_default_cgroup(Unit *u) { if (!(b = new0(CGroupBonding, 1))) return -ENOMEM; - if (!(b->controller = strdup(u->meta.manager->cgroup_controller))) + if (!(b->controller = strdup(SYSTEMD_CGROUP_CONTROLLER))) goto fail; if (!(b->path = default_cgroup_path(u))) @@ -1672,7 +1672,7 @@ fail: CGroupBonding* unit_get_default_cgroup(Unit *u) { assert(u); - return cgroup_bonding_find_list(u->meta.cgroup_bondings, u->meta.manager->cgroup_controller); + return cgroup_bonding_find_list(u->meta.cgroup_bondings, SYSTEMD_CGROUP_CONTROLLER); } int unit_load_related_unit(Unit *u, const char *type, Unit **_found) {