]> err.no Git - systemd/commitdiff
cgroup: make cgroup controller name a constant
authorLennart Poettering <lennart@poettering.net>
Sat, 10 Jul 2010 15:38:50 +0000 (17:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 10 Jul 2010 15:38:50 +0000 (17:38 +0200)
src/cgroup.c
src/cgroup.h
src/manager.c
src/manager.h
src/unit.c

index 244a602024d4b804a298e8e8824c3b3c3132c24b..83fe2ef207e1ddb72b0111a844d407722c3f4abb 100644 (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);
index 05c858c425c4e10d28c8dee6e6f6e5c1ca50ecd8..a7ca8abb063bcb6e35fd7081369babf48aa90f08 100644 (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;
index 524d125bdc8560bfeae9604ad8c05eeb7ae08c2f..8d016b9f5de405bb83e53b97a7f8a54da4d7054b 100644 (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);
 
index b44ffe27ce08215897d2c8ff70e152edd5f5b2fa..e5915d37e4c044a7f58574f595a58e36dce5c7c7 100644 (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;
 
index 18faae22e47c48b98bcbb9918e26014f354c1400..5d51f99966e8deb660cbe28cc3d2324bace7add5 100644 (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) {