21255d
From 1c8d1c3bbdf8bdfb2ee4f85b9f559f54c6e4cac4 Mon Sep 17 00:00:00 2001
21255d
From: Wen Yang <wenyang@linux.alibaba.com>
21255d
Date: Wed, 1 Jul 2020 04:45:33 +0800
21255d
Subject: [PATCH] mount-setup: fix segfault in mount_cgroup_controllers when
21255d
 using gcc9 compiler
21255d
21255d
According to the documentation:
21255d
https://gcc.gnu.org/gcc-9/porting_to.html#complit
21255d
21255d
The 'join_controllers' that relied on the extended lifetime needs
21255d
to be fixed, move the compound literals to the function scope it
21255d
need to accessible in.
21255d
21255d
Resolves: #1868877
21255d
---
21255d
 src/core/mount-setup.c | 24 +++++++++++++-----------
21255d
 1 file changed, 13 insertions(+), 11 deletions(-)
21255d
21255d
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
21255d
index 16880e6157..a6594580e5 100644
21255d
--- a/src/core/mount-setup.c
21255d
+++ b/src/core/mount-setup.c
21255d
@@ -237,20 +237,22 @@ int mount_cgroup_controllers(char ***join_controllers) {
21255d
         if (!cg_is_legacy_wanted())
21255d
                 return 0;
21255d
 
21255d
+        /* The defaults:
21255d
+         * mount "cpu" + "cpuacct" together, and "net_cls" + "net_prio".
21255d
+         *
21255d
+         * We'd like to add "cpuset" to the mix, but "cpuset" doesn't really
21255d
+         * work for groups with no initialized attributes.
21255d
+         */
21255d
+        char ***default_join_controllers = (char**[]) {
21255d
+                STRV_MAKE("cpu", "cpuacct"),
21255d
+                STRV_MAKE("net_cls", "net_prio"),
21255d
+                NULL,
21255d
+        };
21255d
+
21255d
         /* Mount all available cgroup controllers that are built into the kernel. */
21255d
 
21255d
         if (!has_argument)
21255d
-                /* The defaults:
21255d
-                 * mount "cpu" + "cpuacct" together, and "net_cls" + "net_prio".
21255d
-                 *
21255d
-                 * We'd like to add "cpuset" to the mix, but "cpuset" doesn't really
21255d
-                 * work for groups with no initialized attributes.
21255d
-                 */
21255d
-                join_controllers = (char**[]) {
21255d
-                        STRV_MAKE("cpu", "cpuacct"),
21255d
-                        STRV_MAKE("net_cls", "net_prio"),
21255d
-                        NULL,
21255d
-                };
21255d
+                join_controllers = default_join_controllers;
21255d
 
21255d
         r = cg_kernel_controllers(&controllers);
21255d
         if (r < 0)