1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 19:21:53 +03:00

cgroup: make cgroup controller name a constant

This commit is contained in:
Lennart Poettering 2010-07-10 17:38:50 +02:00
parent fb38518151
commit 5509654721
5 changed files with 13 additions and 18 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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) {