From 724f061db6efdc40a0e4994130862325d4f4c8c7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 5 Jan 2023 10:34:23 +0100 Subject: [PATCH] load-fragment: config_parse_emergency_action() doesn't ever get a Manager pointer passed in 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 | 11 ++++++----- src/core/main.c | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 7b58e4ff7b4..e115aa62706 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -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); diff --git a/src/core/main.c b/src/core/main.c index 899d211d1af..c833050db0a 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -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 }, -- 2.47.3