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