chiark / gitweb /
pid1: do not initialize join_controllers by default
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 16 Feb 2018 09:17:46 +0000 (10:17 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:58:59 +0000 (07:58 +0200)
We're moving towards unified cgroup hierarchy where this is not necessary.
This makes main.c a bit simpler.

src/core/mount-setup.c
src/shared/conf-parser.c
src/test/test-conf-parser.c

index b35b90c36a7110762d95bf529e83c89fa2c3f870..cad5934714c267285dbcf3f2a1c03767bfa37362 100644 (file)
@@ -268,6 +268,19 @@ int mount_cgroup_controllers(char ***join_controllers) {
 
         /* Mount all available cgroup controllers that are built into the kernel. */
 
+        if (!join_controllers)
+                /* The defaults:
+                 * mount "cpu" + "cpuacct" together, and "net_cls" + "net_prio".
+                 *
+                 * We'd like to add "cpuset" to the mix, but "cpuset" doesn't really
+                 * work for groups with no initialized attributes.
+                 */
+                join_controllers = (char**[]) {
+                        STRV_MAKE("cpu", "cpuacct"),
+                        STRV_MAKE("net_cls", "net_prio"),
+                        NULL,
+                };
+
         r = cg_kernel_controllers(&controllers);
         if (r < 0)
                 return log_error_errno(r, "Failed to enumerate cgroup controllers: %m");
@@ -286,10 +299,9 @@ int mount_cgroup_controllers(char ***join_controllers) {
                 if (!controller)
                         break;
 
-                if (join_controllers)
-                        for (k = join_controllers; *k; k++)
-                                if (strv_find(*k, controller))
-                                        break;
+                for (k = join_controllers; *k; k++)
+                        if (strv_find(*k, controller))
+                                break;
 
                 if (k && *k) {
                         char **i, **j;
index adb9ad4edd7fc311ded72e08322f87a37e23fbc3..3d12baf2d18cea1ba42306c092cb95a3f69c900a 100644 (file)
@@ -1138,6 +1138,17 @@ int config_parse_join_controllers(
         if (!isempty(rvalue))
                 log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring.");
 
+        /* As a special case, return a single empty strv, to override the default */
+        if (!controllers) {
+                controllers = new(char**, 2);
+                if (!controllers)
+                        return log_oom();
+                controllers[0] = strv_new(NULL, NULL);
+                if (!controllers[0])
+                        return log_oom();
+                controllers[1] = NULL;
+        }
+
         strv_free_free(*ret);
         *ret = controllers;
         controllers = NULL;
index fc68479540002d5f50442b1f696d503df6e66c04..30ca7a8e741fe6aba510f8a3babd5a68a44e23e0 100644 (file)
@@ -260,7 +260,9 @@ static void test_config_parse_join_controllers(void) {
         /* Test special case of no mounted controllers */
         r = config_parse_join_controllers(NULL, "example.conf", 12, "Section", 10, "JoinControllers", 0, "", &c, NULL);
         assert_se(r == 0);
-        assert_se(c == NULL);
+        assert_se(c);
+        assert_se(strv_equal(c[0], STRV_MAKE_EMPTY));
+        assert_se(c[1] == NULL);
 
         /* Test merging of overlapping lists */
         r = config_parse_join_controllers(NULL, "example.conf", 13, "Section", 10, "JoinControllers", 0, "a,b b,c", &c, NULL);