daandemeyer / rpms / systemd

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