teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0278-pid1-when-reloading-configuration-forget-old-setting.patch

Brian Stinson 2593d8
From 0387294ba41ceaf80c79621409aab9508732bda0 Mon Sep 17 00:00:00 2001
Brian Stinson 2593d8
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Brian Stinson 2593d8
Date: Fri, 24 May 2019 09:41:44 +0200
Brian Stinson 2593d8
Subject: [PATCH] pid1: when reloading configuration, forget old settings
Brian Stinson 2593d8
Brian Stinson 2593d8
If we had a configuration setting from a configuration file, and it was
Brian Stinson 2593d8
removed, we'd still remember the old value, because there's was no mechanism to
Brian Stinson 2593d8
"reset" everything, just to assign new values.
Brian Stinson 2593d8
Brian Stinson 2593d8
Note that the effect of this is limited. For settings that have an "ongoing" effect,
Brian Stinson 2593d8
like systemd.confirm_spawn, the new value is simply used. But some settings can only
Brian Stinson 2593d8
be set at start.
Brian Stinson 2593d8
Brian Stinson 2593d8
In particular, CPUAffinity= will be updated if set to a new value, but if
Brian Stinson 2593d8
CPUAffinity= is fully removed, it will not be reset, simply because we don't
Brian Stinson 2593d8
know what to reset it to. We might have inherited a setting, or we might have
Brian Stinson 2593d8
set it ourselves. In principle we could remember the "original" value that was
Brian Stinson 2593d8
set when we were executed, but propagate this over reloads and reexecs, but
Brian Stinson 2593d8
that would be a lot of work for little gain. So this corner case of removal of
Brian Stinson 2593d8
CPUAffinity= is not handled fully, and a reboot is needed to execute the
Brian Stinson 2593d8
change. As a work-around, a full mask of CPUAffinity=0-8191 can be specified.
Brian Stinson 2593d8
Brian Stinson 2593d8
(cherry picked from commit fb39af4ce42d7ef9af63009f271f404038703704)
Brian Stinson 2593d8
Brian Stinson 2593d8
Related: #1734787
Brian Stinson 2593d8
---
Brian Stinson 2593d8
 src/core/main.c | 139 +++++++++++++++++++++++++++++++++---------------
Brian Stinson 2593d8
 1 file changed, 95 insertions(+), 44 deletions(-)
Brian Stinson 2593d8
Brian Stinson 2593d8
diff --git a/src/core/main.c b/src/core/main.c
Brian Stinson 2593d8
index 9a9f145080..c74dc641c1 100644
Brian Stinson 2593d8
--- a/src/core/main.c
Brian Stinson 2593d8
+++ b/src/core/main.c
Brian Stinson 2593d8
@@ -88,46 +88,52 @@ static enum {
Brian Stinson 2593d8
         ACTION_DUMP_CONFIGURATION_ITEMS,
Brian Stinson 2593d8
         ACTION_DUMP_BUS_PROPERTIES,
Brian Stinson 2593d8
 } arg_action = ACTION_RUN;
Brian Stinson 2593d8
-static char *arg_default_unit = NULL;
Brian Stinson 2593d8
-static bool arg_system = false;
Brian Stinson 2593d8
-static bool arg_dump_core = true;
Brian Stinson 2593d8
-static int arg_crash_chvt = -1;
Brian Stinson 2593d8
-static bool arg_crash_shell = false;
Brian Stinson 2593d8
-static bool arg_crash_reboot = false;
Brian Stinson 2593d8
-static char *arg_confirm_spawn = NULL;
Brian Stinson 2593d8
-static ShowStatus arg_show_status = _SHOW_STATUS_UNSET;
Brian Stinson 2593d8
-static bool arg_switched_root = false;
Brian Stinson 2593d8
-static bool arg_no_pager = false;
Brian Stinson 2593d8
-static bool arg_service_watchdogs = true;
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+/* Those variables are initalized to 0 automatically, so we avoid uninitialized memory access.
Brian Stinson 2593d8
+ * Real defaults are assigned in reset_arguments() below. */
Brian Stinson 2593d8
+static char *arg_default_unit;
Brian Stinson 2593d8
+static bool arg_system;
Brian Stinson 2593d8
+static bool arg_dump_core;
Brian Stinson 2593d8
+static int arg_crash_chvt;
Brian Stinson 2593d8
+static bool arg_crash_shell;
Brian Stinson 2593d8
+static bool arg_crash_reboot;
Brian Stinson 2593d8
+static char *arg_confirm_spawn;
Brian Stinson 2593d8
+static ShowStatus arg_show_status;
Brian Stinson 2593d8
+static bool arg_switched_root;
Brian Stinson 2593d8
+static bool arg_no_pager;
Brian Stinson 2593d8
+static bool arg_service_watchdogs;
Brian Stinson 2593d8
 static char ***arg_join_controllers = NULL;
Brian Stinson 2593d8
-static ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL;
Brian Stinson 2593d8
-static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
Brian Stinson 2593d8
-static usec_t arg_default_restart_usec = DEFAULT_RESTART_USEC;
Brian Stinson 2593d8
-static usec_t arg_default_timeout_start_usec = DEFAULT_TIMEOUT_USEC;
Brian Stinson 2593d8
-static usec_t arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
Brian Stinson 2593d8
-static usec_t arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL;
Brian Stinson 2593d8
-static unsigned arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST;
Brian Stinson 2593d8
-static usec_t arg_runtime_watchdog = 0;
Brian Stinson 2593d8
-static usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
Brian Stinson 2593d8
-static char *arg_watchdog_device = NULL;
Brian Stinson 2593d8
-static char **arg_default_environment = NULL;
Brian Stinson 2593d8
-static struct rlimit *arg_default_rlimit[_RLIMIT_MAX] = {};
Brian Stinson 2593d8
-static uint64_t arg_capability_bounding_set = CAP_ALL;
Brian Stinson 2593d8
-static bool arg_no_new_privs = false;
Brian Stinson 2593d8
-static nsec_t arg_timer_slack_nsec = NSEC_INFINITY;
Brian Stinson 2593d8
-static usec_t arg_default_timer_accuracy_usec = 1 * USEC_PER_MINUTE;
Brian Stinson 2593d8
-static Set* arg_syscall_archs = NULL;
Brian Stinson 2593d8
-static FILE* arg_serialization = NULL;
Brian Stinson 2593d8
-static bool arg_default_cpu_accounting = false;
Brian Stinson 2593d8
-static bool arg_default_io_accounting = false;
Brian Stinson 2593d8
-static bool arg_default_ip_accounting = false;
Brian Stinson 2593d8
-static bool arg_default_blockio_accounting = false;
Brian Stinson 2593d8
-static bool arg_default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT;
Brian Stinson 2593d8
-static bool arg_default_tasks_accounting = true;
Brian Stinson 2593d8
-static uint64_t arg_default_tasks_max = UINT64_MAX;
Brian Stinson 2593d8
-static sd_id128_t arg_machine_id = {};
Brian Stinson 2593d8
-static EmergencyAction arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE;
Brian Stinson 2593d8
-static CPUSet arg_cpu_affinity = {};
Brian Stinson 2593d8
+static ExecOutput arg_default_std_output;
Brian Stinson 2593d8
+static ExecOutput arg_default_std_error;
Brian Stinson 2593d8
+static usec_t arg_default_restart_usec;
Brian Stinson 2593d8
+static usec_t arg_default_timeout_start_usec;
Brian Stinson 2593d8
+static usec_t arg_default_timeout_stop_usec;
Brian Stinson 2593d8
+static usec_t arg_default_timeout_abort_usec;
Brian Stinson 2593d8
+static bool arg_default_timeout_abort_set;
Brian Stinson 2593d8
+static usec_t arg_default_start_limit_interval;
Brian Stinson 2593d8
+static unsigned arg_default_start_limit_burst;
Brian Stinson 2593d8
+static usec_t arg_runtime_watchdog;
Brian Stinson 2593d8
+static usec_t arg_shutdown_watchdog;
Brian Stinson 2593d8
+static char *arg_early_core_pattern;
Brian Stinson 2593d8
+static char *arg_watchdog_device;
Brian Stinson 2593d8
+static char **arg_default_environment;
Brian Stinson 2593d8
+static struct rlimit *arg_default_rlimit[_RLIMIT_MAX];
Brian Stinson 2593d8
+static uint64_t arg_capability_bounding_set;
Brian Stinson 2593d8
+static bool arg_no_new_privs;
Brian Stinson 2593d8
+static nsec_t arg_timer_slack_nsec;
Brian Stinson 2593d8
+static usec_t arg_default_timer_accuracy_usec;
Brian Stinson 2593d8
+static Set* arg_syscall_archs;
Brian Stinson 2593d8
+static FILE* arg_serialization;
Brian Stinson 2593d8
+static int arg_default_cpu_accounting;
Brian Stinson 2593d8
+static bool arg_default_io_accounting;
Brian Stinson 2593d8
+static bool arg_default_ip_accounting;
Brian Stinson 2593d8
+static bool arg_default_blockio_accounting;
Brian Stinson 2593d8
+static bool arg_default_memory_accounting;
Brian Stinson 2593d8
+static bool arg_default_tasks_accounting;
Brian Stinson 2593d8
+static uint64_t arg_default_tasks_max;
Brian Stinson 2593d8
+static sd_id128_t arg_machine_id;
Brian Stinson 2593d8
+static EmergencyAction arg_cad_burst_action;
Brian Stinson 2593d8
+static CPUSet arg_cpu_affinity;
Brian Stinson 2593d8
 
Brian Stinson 2593d8
 static int parse_configuration(void);
Brian Stinson 2593d8
 
Brian Stinson 2593d8
@@ -1951,17 +1957,59 @@ static int do_queue_default_job(
Brian Stinson 2593d8
         return 0;
Brian Stinson 2593d8
 }
Brian Stinson 2593d8
 
Brian Stinson 2593d8
-static void free_arguments(void) {
Brian Stinson 2593d8
-
Brian Stinson 2593d8
-        /* Frees all arg_* variables, with the exception of arg_serialization */
Brian Stinson 2593d8
-        rlimit_free_all(arg_default_rlimit);
Brian Stinson 2593d8
+static void reset_arguments(void) {
Brian Stinson 2593d8
+        /* Frees/resets arg_* variables, with a few exceptions commented below. */
Brian Stinson 2593d8
 
Brian Stinson 2593d8
         arg_default_unit = mfree(arg_default_unit);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        /* arg_system — ignore */
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        arg_dump_core = true;
Brian Stinson 2593d8
+        arg_crash_chvt = -1;
Brian Stinson 2593d8
+        arg_crash_shell = false;
Brian Stinson 2593d8
+        arg_crash_reboot = false;
Brian Stinson 2593d8
         arg_confirm_spawn = mfree(arg_confirm_spawn);
Brian Stinson 2593d8
         arg_join_controllers = strv_free_free(arg_join_controllers);
Brian Stinson 2593d8
+        arg_show_status = _SHOW_STATUS_UNSET;
Brian Stinson 2593d8
+        arg_switched_root = false;
Brian Stinson 2593d8
+        arg_no_pager = false;
Brian Stinson 2593d8
+        arg_service_watchdogs = true;
Brian Stinson 2593d8
+        arg_default_std_output = EXEC_OUTPUT_JOURNAL;
Brian Stinson 2593d8
+        arg_default_std_error = EXEC_OUTPUT_INHERIT;
Brian Stinson 2593d8
+        arg_default_restart_usec = DEFAULT_RESTART_USEC;
Brian Stinson 2593d8
+        arg_default_timeout_start_usec = DEFAULT_TIMEOUT_USEC;
Brian Stinson 2593d8
+        arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
Brian Stinson 2593d8
+        arg_default_timeout_abort_usec = DEFAULT_TIMEOUT_USEC;
Brian Stinson 2593d8
+        arg_default_timeout_abort_set = false;
Brian Stinson 2593d8
+        arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL;
Brian Stinson 2593d8
+        arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST;
Brian Stinson 2593d8
+        arg_runtime_watchdog = 0;
Brian Stinson 2593d8
+        arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
Brian Stinson 2593d8
+        arg_early_core_pattern = NULL;
Brian Stinson 2593d8
+        arg_watchdog_device = NULL;
Brian Stinson 2593d8
+
Brian Stinson 2593d8
         arg_default_environment = strv_free(arg_default_environment);
Brian Stinson 2593d8
+        rlimit_free_all(arg_default_rlimit);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        arg_capability_bounding_set = CAP_ALL;
Brian Stinson 2593d8
+        arg_no_new_privs = false;
Brian Stinson 2593d8
+        arg_timer_slack_nsec = NSEC_INFINITY;
Brian Stinson 2593d8
+        arg_default_timer_accuracy_usec = 1 * USEC_PER_MINUTE;
Brian Stinson 2593d8
+
Brian Stinson 2593d8
         arg_syscall_archs = set_free(arg_syscall_archs);
Brian Stinson 2593d8
 
Brian Stinson 2593d8
+        /* arg_serialization — ignore */
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        arg_default_cpu_accounting = -1;
Brian Stinson 2593d8
+        arg_default_io_accounting = false;
Brian Stinson 2593d8
+        arg_default_ip_accounting = false;
Brian Stinson 2593d8
+        arg_default_blockio_accounting = false;
Brian Stinson 2593d8
+        arg_default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT;
Brian Stinson 2593d8
+        arg_default_tasks_accounting = true;
Brian Stinson 2593d8
+        arg_default_tasks_max = UINT64_MAX;
Brian Stinson 2593d8
+        arg_machine_id = (sd_id128_t) {};
Brian Stinson 2593d8
+        arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE;
Brian Stinson 2593d8
+
Brian Stinson 2593d8
         cpu_set_reset(&arg_cpu_affinity);
Brian Stinson 2593d8
 }
Brian Stinson 2593d8
 
Brian Stinson 2593d8
@@ -1970,6 +2018,9 @@ static int parse_configuration(void) {
Brian Stinson 2593d8
 
Brian Stinson 2593d8
         arg_default_tasks_max = system_tasks_max_scale(DEFAULT_TASKS_MAX_PERCENTAGE, 100U);
Brian Stinson 2593d8
 
Brian Stinson 2593d8
+        /* Assign configuration defaults */
Brian Stinson 2593d8
+        reset_arguments();
Brian Stinson 2593d8
+
Brian Stinson 2593d8
         r = parse_config_file();
Brian Stinson 2593d8
         if (r < 0)
Brian Stinson 2593d8
                 log_warning_errno(r, "Failed to parse config file, ignoring: %m");
Brian Stinson 2593d8
@@ -2460,7 +2511,7 @@ finish:
Brian Stinson 2593d8
                 m = manager_free(m);
Brian Stinson 2593d8
         }
Brian Stinson 2593d8
 
Brian Stinson 2593d8
-        free_arguments();
Brian Stinson 2593d8
+        reset_arguments();
Brian Stinson 2593d8
         mac_selinux_finish();
Brian Stinson 2593d8
 
Brian Stinson 2593d8
         if (reexecute)