]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
load-fragment: config_parse_emergency_action() doesn't ever get a Manager pointer... 25936/head
authorLennart Poettering <lennart@poettering.net>
Thu, 5 Jan 2023 09:34:23 +0000 (10:34 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 6 Jan 2023 15:15:46 +0000 (16:15 +0100)
In 'data' we get the location passed in we write stuff, and that's not
the Manager object.

And we neither get the Manager passed in via 'userdata', because at the
time we parse the emergency action for the manager the Manager is not
actually allocated yet.

hence, let's fix this differently, and pass in the user/system mode
descriptor via the 'ltype' argument.

Fixes: #25933
src/core/load-fragment.c
src/core/main.c

index 7b58e4ff7b48d87e0739494d2213a1f0515549d9..e115aa62706b94bbc4b4fd2f7724d988965f528d 100644 (file)
@@ -5581,25 +5581,26 @@ int config_parse_emergency_action(
                 void *data,
                 void *userdata) {
 
-        Manager *m = NULL;
         EmergencyAction *x = ASSERT_PTR(data);
+        bool is_system;
         int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
 
+        /* If we have a unit determine the scope based on it */
         if (unit)
-                m = ((Unit*) userdata)->manager;
+                is_system = MANAGER_IS_SYSTEM(((Unit*) ASSERT_PTR(userdata))->manager);
         else
-                m = data;
+                is_system = ltype; /* otherwise, assume the scope is passed in via ltype */
 
-        r = parse_emergency_action(rvalue, MANAGER_IS_SYSTEM(m), x);
+        r = parse_emergency_action(rvalue, is_system, x);
         if (r < 0) {
                 if (r == -EOPNOTSUPP)
                         log_syntax(unit, LOG_WARNING, filename, line, r,
                                    "%s= specified as %s mode action, ignoring: %s",
-                                   lvalue, MANAGER_IS_SYSTEM(m) ? "user" : "system", rvalue);
+                                   lvalue, is_system ? "user" : "system", rvalue);
                 else
                         log_syntax(unit, LOG_WARNING, filename, line, r,
                                    "Failed to parse %s=, ignoring: %s", lvalue, rvalue);
index 899d211d1af7a49cc50457daf953f7367a381773..c833050db0af9ac647282bfe08563d842dd7071e 100644 (file)
@@ -683,7 +683,7 @@ static int parse_config_file(void) {
                 { "Manager", "DefaultMemoryAccounting",      config_parse_bool,                  0,                        &arg_default_memory_accounting    },
                 { "Manager", "DefaultTasksAccounting",       config_parse_bool,                  0,                        &arg_default_tasks_accounting     },
                 { "Manager", "DefaultTasksMax",              config_parse_tasks_max,             0,                        &arg_default_tasks_max            },
-                { "Manager", "CtrlAltDelBurstAction",        config_parse_emergency_action,      0,                        &arg_cad_burst_action             },
+                { "Manager", "CtrlAltDelBurstAction",        config_parse_emergency_action,      arg_system,               &arg_cad_burst_action             },
                 { "Manager", "DefaultOOMPolicy",             config_parse_oom_policy,            0,                        &arg_default_oom_policy           },
                 { "Manager", "DefaultOOMScoreAdjust",        config_parse_oom_score_adjust,      0,                        NULL                              },
                 { "Manager", "ReloadLimitIntervalSec",       config_parse_sec,                   0,                        &arg_reload_limit_interval_sec    },