HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/core/main.c

180,411 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: 7887e0f02d9696e736ccfb06986d5d50dcb1cfc6

Lines 1–1000 of 4,044

/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
#include <fcntl.h>
#include <linux/oom.h>
#include <linux/vt.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/prctl.h> /* IWYU pragma: keep */
#include <sys/utsname.h>
#include <unistd.h>
 
#if HAVE_VALGRIND_VALGRIND_H
#  include <valgrind/valgrind.h>
#endif
 
#include "sd-bus.h"
#include "sd-daemon.h"
#include "sd-json.h"
#include "sd-messages.h"
 
#include "alloc-util.h"
#include "ansi-color.h"
#include "apparmor-setup.h"
#include "architecture.h"
#include "argv-util.h"
#include "bpf-restrict-fsaccess.h"
#include "build.h"
#include "bus-error.h"
#include "capability-util.h"
#include "cgroup-setup.h"
#include "chase.h"
#include "clock-util.h"
#include "clock-warp.h"
#include "conf-parser.h"
#include "confidential-virt.h"
#include "constants.h"
#include "copy.h"
#include "coredump-util.h"
#include "cpu-set-util.h"
#include "crash-handler.h"
#include "dbus.h"
#include "dbus-manager.h"
#include "dev-setup.h"
#include "dlopen-note.h"
#include "efi-random.h"
#include "emergency-action.h"
#include "env-util.h"
#include "escape.h"
#include "executor.h"
#include "extract-word.h"
#include "fd-util.h"
#include "fdset.h"
#include "fileio.h"
#include "format-util.h"
#include "fs-util.h"
#include "glyph-util.h"
#include "hash-funcs.h"
#include "hashmap.h"
#include "hexdecoct.h"
#include "hostname-setup.h"
#include "id128-util.h"
#include "ima-setup.h"
#include "import-creds.h"
#include "initrd-util.h"
#include "io-util.h"
#include "ipe-setup.h"
#include "json-util.h"
#include "killall.h"
#include "kmod-setup.h"
#include "label-util.h"
#include "libmount-util.h"
#include "limits-util.h"
#include "load-fragment.h"
#include "log.h"
#include "loopback-setup.h"
#include "luo.h"
#include "machine-id-setup.h"
#include "main.h"
#include "manager.h"
#include "manager-dump.h"
#include "manager-serialize.h"
#include "mkdir.h"
#include "mount-setup.h"
#include "mount-util.h"
#include "options.h"
#include "os-util.h"
#include "osc-context.h"
#include "pager.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pidfd-util.h"
#include "pretty-print.h"
#include "proc-cmdline.h"
#include "process-util.h"
#include "random-util.h"
#include "reboot-util.h"
#include "rlimit-util.h"
#include "rm-rf.h"
#include "seccomp-util.h"
#include "selinux-setup.h"
#include "selinux-util.h"
#include "serialize.h"
#include "service.h"
#include "set.h"
#include "signal-util.h"
#include "smack-setup.h"
#include "special.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "strv.h"
#include "switch-root.h"
#include "sysctl-util.h"
#include "terminal-util.h"
#include "time-util.h"
#include "umask-util.h"
#include "unit-name.h"
#include "user-util.h"
#include "utf8.h"
#include "verbs.h"
#include "version.h"
#include "virt.h"
#include "watchdog.h"
 
#if HAS_FEATURE_ADDRESS_SANITIZER
#include <sanitizer/lsan_interface.h>
#endif
 
static enum {
        ACTION_RUN,
        ACTION_HELP,
        ACTION_VERSION,
        ACTION_INTROSPECT_CLI,
        ACTION_TEST,
        ACTION_DUMP_CONFIGURATION_ITEMS,
        ACTION_DUMP_BUS_PROPERTIES,
        ACTION_BUS_INTROSPECT,
} arg_action = ACTION_RUN;
 
static const char *arg_bus_introspect = NULL;
 
/* Those variables are initialized to 0 automatically, so we avoid uninitialized memory access.  Real
 * defaults are assigned in reset_arguments() below. */
static char *arg_default_unit;
static RuntimeScope arg_runtime_scope;
bool arg_dump_core;
int arg_crash_chvt;
bool arg_crash_shell;
CrashAction arg_crash_action;
static char *arg_confirm_spawn;
static ShowStatus arg_show_status;
static StatusUnitFormat arg_status_unit_format;
static bool arg_switched_root;
static PagerFlags arg_pager_flags;
static bool arg_service_watchdogs;
static UnitDefaults arg_defaults;
static usec_t arg_runtime_watchdog;
static usec_t arg_reboot_watchdog;
static usec_t arg_kexec_watchdog;
static usec_t arg_pretimeout_watchdog;
static char *arg_early_core_pattern;
static char *arg_watchdog_pretimeout_governor;
static char *arg_watchdog_device;
static char **arg_default_environment;
static char **arg_manager_environment;
static uint64_t arg_capability_bounding_set;
static bool arg_no_new_privs;
static int arg_protect_system;
static RestrictFileSystemAccess arg_restrict_filesystem_access;
static nsec_t arg_timer_slack_nsec;
static Set* arg_syscall_archs;
static FILE* arg_serialization;
static FILE* arg_luo_serialization;
static sd_id128_t arg_machine_id;
static bool arg_machine_id_from_firmware = false;
static EmergencyAction arg_cad_burst_action;
static CPUSet arg_cpu_affinity;
static NUMAPolicy arg_numa_policy;
static usec_t arg_clock_usec;
static void *arg_random_seed;
static size_t arg_random_seed_size;
static usec_t arg_reload_limit_interval_sec;
static unsigned arg_reload_limit_burst;
static usec_t arg_event_loop_ratelimit_interval_sec;
static unsigned arg_event_loop_ratelimit_burst;
static usec_t arg_minimum_uptime_usec;
 
/* A copy of the original environment block */
static char **saved_env = NULL;
 
static int parse_configuration(const struct rlimit *saved_rlimit_nofile,
                               const struct rlimit *saved_rlimit_memlock);
 
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_crash_action, crash_action, CrashAction, CRASH_FREEZE);
 
static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) {
        _cleanup_free_ char *base = NULL;
        _cleanup_strv_free_ char **files = NULL, **dirs = NULL;
        int r;
 
        assert(ret_files);
        assert(ret_dirs);
 
        r = xdg_user_config_dir("/systemd", &base);
        if (r < 0)
                return r;
 
        r = strv_extendf(&files, "%s/user.conf", base);
        if (r < 0)
                return r;
 
        r = strv_extend(&files, PKGSYSCONFDIR "/user.conf");
        if (r < 0)
                return r;
 
        r = strv_consume(&dirs, TAKE_PTR(base));
        if (r < 0)
                return r;
 
        r = strv_extend_strv(&dirs, CONF_PATHS_STRV("systemd"), false);
        if (r < 0)
                return r;
 
        *ret_files = TAKE_PTR(files);
        *ret_dirs = TAKE_PTR(dirs);
        return 0;
}
 
static int save_console_winsize_in_environment(int tty_fd) {
        int r;
 
        assert(tty_fd >= 0);
 
        struct winsize ws = {};
        if (ioctl(tty_fd, TIOCGWINSZ, &ws) < 0) {
                log_debug_errno(errno, "Failed to acquire console window size, ignoring.");
                goto unset;
        }
 
        if (ws.ws_col <= 0 && ws.ws_row <= 0) {
                log_debug("No console window size set, ignoring.");
                goto unset;
        }
 
        r = setenvf("COLUMNS", /* overwrite= */ true, "%u", ws.ws_col);
        if (r < 0) {
                log_debug_errno(r, "Failed to set $COLUMNS, ignoring: %m");
                goto unset;
        }
 
        r = setenvf("LINES", /* overwrite= */ true, "%u", ws.ws_row);
        if (r < 0) {
                log_debug_errno(r, "Failed to set $LINES, ignoring: %m");
                goto unset;
        }
 
        log_debug("Recorded console dimensions in environment: $COLUMNS=%u $LINES=%u.", ws.ws_col, ws.ws_row);
        return 1;
 
unset:
        (void) unsetenv("COLUMNS");
        (void) unsetenv("LINES");
        return 0;
}
 
static int console_setup(void) {
 
        if (getpid_cached() != 1)
                return 0;
 
        _cleanup_close_ int tty_fd = -EBADF;
 
        tty_fd = open_terminal("/dev/console", O_RDWR|O_NOCTTY|O_CLOEXEC);
        if (tty_fd < 0)
                return log_error_errno(tty_fd, "Failed to open %s: %m", "/dev/console");
 
        /* We don't want to force text mode. Plymouth may be showing pictures already from initrd. */
        reset_dev_console_fd(tty_fd, /* switch_to_text= */ false);
 
        save_console_winsize_in_environment(tty_fd);
 
        return 0;
}
 
static int parse_timeout(const char *value, usec_t *ret) {
        int r = 0;
 
        assert(value);
        assert(ret);
 
        if (streq(value, "default"))
                *ret = USEC_INFINITY;
        else if (streq(value, "off"))
                *ret = 0;
        else
                r = parse_sec(value, ret);
 
        return r;
}
 
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
        int r;
 
        assert(key);
 
        if (STR_IN_SET(key, "systemd.unit", "rd.systemd.unit")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                if (!unit_name_is_valid(value, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
                        log_warning("Unit name specified on %s= is not valid, ignoring: %s", key, value);
                else if (in_initrd() == !!startswith(key, "rd."))
                        return free_and_strdup_warn(&arg_default_unit, value);
 
        } else if (proc_cmdline_key_streq(key, "systemd.dump_core")) {
 
                r = value ? parse_boolean(value) : true;
                if (r < 0)
                        log_warning_errno(r, "Failed to parse dump core switch %s, ignoring: %m", value);
                else
                        arg_dump_core = r;
 
        } else if (proc_cmdline_key_streq(key, "systemd.early_core_pattern")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                if (path_is_absolute(value))
                        (void) parse_path_argument(value, false, &arg_early_core_pattern);
                else
                        log_warning("Specified core pattern '%s' is not an absolute path, ignoring.", value);
 
        } else if (proc_cmdline_key_streq(key, "systemd.crash_chvt")) {
 
                if (!value)
                        arg_crash_chvt = 0; /* turn on */
                else {
                        r = parse_crash_chvt(value, &arg_crash_chvt);
                        if (r < 0)
                                log_warning_errno(r, "Failed to parse crash chvt switch %s, ignoring: %m", value);
                }
 
        } else if (proc_cmdline_key_streq(key, "systemd.crash_shell")) {
 
                r = value ? parse_boolean(value) : true;
                if (r < 0)
                        log_warning_errno(r, "Failed to parse crash shell switch %s, ignoring: %m", value);
                else
                        arg_crash_shell = r;
 
        } else if (proc_cmdline_key_streq(key, "systemd.crash_reboot")) {
 
                r = value ? parse_boolean(value) : true;
                if (r < 0)
                        log_warning_errno(r, "Failed to parse crash reboot switch %s, ignoring: %m", value);
                else
                        arg_crash_action = r ? CRASH_REBOOT : CRASH_FREEZE;
 
        } else if (proc_cmdline_key_streq(key, "systemd.crash_action")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = crash_action_from_string(value);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse crash action switch %s, ignoring: %m", value);
                else
                        arg_crash_action = r;
 
        } else if (proc_cmdline_key_streq(key, "systemd.confirm_spawn")) {
                char *s;
 
                r = parse_confirm_spawn(value, &s);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse confirm_spawn switch %s, ignoring: %m", value);
                else
                        free_and_replace(arg_confirm_spawn, s);
 
        } else if (proc_cmdline_key_streq(key, "systemd.service_watchdogs")) {
 
                r = value ? parse_boolean(value) : true;
                if (r < 0)
                        log_warning_errno(r, "Failed to parse service watchdog switch %s, ignoring: %m", value);
                else
                        arg_service_watchdogs = r;
 
        } else if (proc_cmdline_key_streq(key, "systemd.show_status")) {
 
                if (value) {
                        r = parse_show_status(value, &arg_show_status);
                        if (r < 0)
                                log_warning_errno(r, "Failed to parse show status switch %s, ignoring: %m", value);
                } else
                        arg_show_status = SHOW_STATUS_YES;
 
        } else if (proc_cmdline_key_streq(key, "systemd.status_unit_format")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = status_unit_format_from_string(value);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse %s=%s, ignoring: %m", key, value);
                else
                        arg_status_unit_format = r;
 
        } else if (proc_cmdline_key_streq(key, "systemd.default_standard_output")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = exec_output_from_string(value);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse default standard output switch %s, ignoring: %m", value);
                else
                        arg_defaults.std_output = r;
 
        } else if (proc_cmdline_key_streq(key, "systemd.default_standard_error")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = exec_output_from_string(value);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse default standard error switch %s, ignoring: %m", value);
                else
                        arg_defaults.std_error = r;
 
        } else if (streq(key, "systemd.setenv")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                if (!env_assignment_is_valid(value))
                        log_warning("Environment variable assignment '%s' is not valid. Ignoring.", value);
                else {
                        r = strv_env_replace_strdup(&arg_default_environment, value);
                        if (r < 0)
                                return log_oom();
                }
 
        } else if (proc_cmdline_key_streq(key, "systemd.machine_id")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                if (streq(value, "firmware"))
                        arg_machine_id_from_firmware = true;
                else {
                        r = id128_from_string_nonzero(value, &arg_machine_id);
                        if (r < 0)
                                log_warning_errno(r, "MachineID '%s' is not valid, ignoring: %m", value);
                        else
                                arg_machine_id_from_firmware = false;
                }
        } else if (proc_cmdline_key_streq(key, "systemd.default_timeout_start_sec")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = parse_sec(value, &arg_defaults.timeout_start_usec);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse default start timeout '%s', ignoring: %m", value);
 
                if (arg_defaults.timeout_start_usec <= 0)
                        arg_defaults.timeout_start_usec = USEC_INFINITY;
 
        } else if (proc_cmdline_key_streq(key, "systemd.default_device_timeout_sec")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = parse_sec(value, &arg_defaults.device_timeout_usec);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse default device timeout '%s', ignoring: %m", value);
 
                if (arg_defaults.device_timeout_usec <= 0)
                        arg_defaults.device_timeout_usec = USEC_INFINITY;
 
        } else if (proc_cmdline_key_streq(key, "systemd.cpu_affinity")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = parse_cpu_set(value, &arg_cpu_affinity);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse CPU affinity mask '%s', ignoring: %m", value);
 
        } else if (proc_cmdline_key_streq(key, "systemd.watchdog_device")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                (void) parse_path_argument(value, false, &arg_watchdog_device);
 
        } else if (proc_cmdline_key_streq(key, "systemd.watchdog_sec")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = parse_timeout(value, &arg_runtime_watchdog);
                if (r < 0) {
                        log_warning_errno(r, "Failed to parse systemd.watchdog_sec= argument '%s', ignoring: %m", value);
                        return 0;
                }
 
                arg_kexec_watchdog = arg_reboot_watchdog = arg_runtime_watchdog;
 
        } else if (proc_cmdline_key_streq(key, "systemd.watchdog_pre_sec")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = parse_timeout(value, &arg_pretimeout_watchdog);
                if (r < 0) {
                        log_warning_errno(r, "Failed to parse systemd.watchdog_pre_sec= argument '%s', ignoring: %m", value);
                        return 0;
                }
 
        } else if (proc_cmdline_key_streq(key, "systemd.watchdog_pretimeout_governor")) {
 
                if (proc_cmdline_value_missing(key, value) || isempty(value)) {
                        arg_watchdog_pretimeout_governor = mfree(arg_watchdog_pretimeout_governor);
                        return 0;
                }
 
                if (!string_is_safe(value, /* flags= */ 0)) {
                        log_warning("Watchdog pretimeout governor '%s' is not valid, ignoring.", value);
                        return 0;
                }
 
                return free_and_strdup_warn(&arg_watchdog_pretimeout_governor, value);
 
        } else if (proc_cmdline_key_streq(key, "systemd.clock_usec")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = safe_atou64(value, &arg_clock_usec);
                if (r < 0)
                        log_warning_errno(r, "Failed to parse systemd.clock_usec= argument, ignoring: %s", value);
 
        } else if (proc_cmdline_key_streq(key, "systemd.random_seed")) {
                void *p;
                size_t sz;
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = unbase64mem(value, &p, &sz);
                if (r < 0) {
                        log_warning_errno(r, "Failed to parse systemd.random_seed= argument, ignoring: %s", value);
                        return 0;
                }
 
                free(arg_random_seed);
                arg_random_seed = sz > 0 ? p : mfree(p);
                arg_random_seed_size = sz;
 
        } else if (proc_cmdline_key_streq(key, "systemd.reload_limit_interval_sec")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = parse_sec(value, &arg_reload_limit_interval_sec);
                if (r < 0) {
                        log_warning_errno(r, "Failed to parse systemd.reload_limit_interval_sec= argument '%s', ignoring: %m", value);
                        return 0;
                }
 
        } else if (proc_cmdline_key_streq(key, "systemd.reload_limit_burst")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = safe_atou(value, &arg_reload_limit_burst);
                if (r < 0) {
                        log_warning_errno(r, "Failed to parse systemd.reload_limit_burst= argument '%s', ignoring: %m", value);
                        return 0;
                }
 
        } else if (proc_cmdline_key_streq(key, "systemd.event_loop_ratelimit_interval_sec")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = parse_sec(value, &arg_event_loop_ratelimit_interval_sec);
                if (r < 0) {
                        log_warning_errno(r, "Failed to parse systemd.event_loop_ratelimit_interval_sec= argument '%s', ignoring: %m", value);
                        return 0;
                }
 
        } else if (proc_cmdline_key_streq(key, "systemd.event_loop_ratelimit_burst")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = safe_atou(value, &arg_event_loop_ratelimit_burst);
                if (r < 0) {
                        log_warning_errno(r, "Failed to parse systemd.event_loop_ratelimit_burst= argument '%s', ignoring: %m", value);
                        return 0;
                }
 
        } else if (proc_cmdline_key_streq(key, "systemd.minimum_uptime_sec")) {
 
                if (proc_cmdline_value_missing(key, value))
                        return 0;
 
                r = parse_sec(value, &arg_minimum_uptime_usec);
                if (r < 0) {
                        log_warning_errno(r, "Failed to parse systemd.minimum_uptime_sec= argument '%s', ignoring: %m", value);
                        return 0;
                }
 
        } else if (proc_cmdline_key_streq(key, "systemd.restrict_filesystem_access")) {
 
                if (value) {
                        r = restrict_filesystem_access_from_string(value);
                        if (r < 0)
                                log_warning_errno(r, "Failed to parse systemd.restrict_filesystem_access= argument '%s', ignoring: %m", value);
                        else
                                arg_restrict_filesystem_access = r;
                } else
                        arg_restrict_filesystem_access = RESTRICT_FILESYSTEM_ACCESS_EXEC;
 
        } else if (streq(key, "quiet") && !value) {
 
                if (arg_show_status == _SHOW_STATUS_INVALID)
                        arg_show_status = SHOW_STATUS_ERROR;
 
        } else if (streq(key, "debug") && !value) {
 
                /* Note that log_parse_environment() handles 'debug'
                 * too, and sets the log level to LOG_DEBUG. */
 
                if (detect_container() > 0)
                        log_set_target(LOG_TARGET_CONSOLE);
 
        } else if (!value) {
                const char *target;
 
                /* Compatible with SysV, but supported independently even if SysV compatibility is disabled. */
                target = runlevel_to_target(key);
                if (target)
                        return free_and_strdup_warn(&arg_default_unit, target);
        }
 
        return 0;
}
 
#define DEFINE_SETTER(name, func, descr)                              \
        static int name(const char *unit,                             \
                        const char *filename,                         \
                        unsigned line,                                \
                        const char *section,                          \
                        unsigned section_line,                        \
                        const char *lvalue,                           \
                        int ltype,                                    \
                        const char *rvalue,                           \
                        void *data,                                   \
                        void *userdata) {                             \
                                                                      \
                int r;                                                \
                                                                      \
                assert(filename);                                     \
                assert(lvalue);                                       \
                assert(rvalue);                                       \
                                                                      \
                r = func(rvalue);                                     \
                if (r < 0)                                            \
                        log_syntax(unit, LOG_ERR, filename, line, r,  \
                                   "Invalid " descr "'%s': %m",       \
                                   rvalue);                           \
                                                                      \
                return 0;                                             \
        }
 
DEFINE_SETTER(config_parse_level2, log_set_max_level_from_string, "log level");
DEFINE_SETTER(config_parse_target, log_set_target_from_string, "target");
DEFINE_SETTER(config_parse_color, log_show_color_from_string, "color");
DEFINE_SETTER(config_parse_location, log_show_location_from_string, "location");
DEFINE_SETTER(config_parse_time, log_show_time_from_string, "time");
 
static int config_parse_default_timeout_abort(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
        int r;
 
        r = config_parse_timeout_abort(
                        unit,
                        filename,
                        line,
                        section,
                        section_line,
                        lvalue,
                        ltype,
                        rvalue,
                        &arg_defaults.timeout_abort_usec,
                        userdata);
        if (r >= 0)
                arg_defaults.timeout_abort_set = r;
        return 0;
}
 
static int config_parse_oom_score_adjust(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        int oa, r;
 
        if (isempty(rvalue)) {
                arg_defaults.oom_score_adjust_set = false;
                return 0;
        }
 
        r = parse_oom_score_adjust(rvalue, &oa);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        arg_defaults.oom_score_adjust = oa;
        arg_defaults.oom_score_adjust_set = true;
 
        return 0;
}
 
static int config_parse_protect_system_pid1(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        int *v = ASSERT_PTR(data), r;
 
        /* This is modelled after the per-service ProtectSystem= setting, but a bit more restricted on one
         * hand, and more automatic in another. i.e. we currently only support yes/no (not "strict" or
         * "full"). And we will enable this automatically for the initrd unless configured otherwise.
         *
         * We might extend this later to match more closely what the per-service ProtectSystem= can do, but
         * this is not trivial, due to ordering constraints: besides /usr/ we don't really have much mounted
         * at the moment we enable this logic. */
 
        if (isempty(rvalue) || streq(rvalue, "auto")) {
                *v = -1;
                return 0;
        }
 
        r = parse_boolean(rvalue);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        *v = r;
        return 0;
}
 
static int config_parse_restrict_filesystem_access(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        RestrictFileSystemAccess *v = ASSERT_PTR(data);
        RestrictFileSystemAccess re;
 
        re = restrict_filesystem_access_from_string(rvalue);
        if (re < 0)
                return log_syntax_parse_error(unit, filename, line, re, lvalue, rvalue);
 
        *v = re;
        return 0;
}
 
static int config_parse_crash_reboot(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        CrashAction *v = ASSERT_PTR(data);
        int r;
 
        if (isempty(rvalue)) {
                *v = CRASH_REBOOT;
                return 0;
        }
 
        r = parse_boolean(rvalue);
        if (r < 0)
                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
 
        *v = r > 0 ? CRASH_REBOOT : CRASH_FREEZE;
        return 0;
}
 
static int parse_config_file(void) {
        const ConfigTableItem items[] = {
                { "Manager", "LogLevel",                          config_parse_level2,                0,                        NULL                                                   },
                { "Manager", "LogTarget",                         config_parse_target,                0,                        NULL                                                   },
                { "Manager", "LogColor",                          config_parse_color,                 0,                        NULL                                                   },
                { "Manager", "LogLocation",                       config_parse_location,              0,                        NULL                                                   },
                { "Manager", "LogTime",                           config_parse_time,                  0,                        NULL                                                   },
                { "Manager", "DumpCore",                          config_parse_bool,                  0,                        &arg_dump_core                                         },
                { "Manager", "CrashChVT", /* legacy */            config_parse_crash_chvt,            0,                        &arg_crash_chvt                                        },
                { "Manager", "CrashChangeVT",                     config_parse_crash_chvt,            0,                        &arg_crash_chvt                                        },
                { "Manager", "CrashShell",                        config_parse_bool,                  0,                        &arg_crash_shell                                       },
                { "Manager", "CrashReboot",                       config_parse_crash_reboot,          0,                        &arg_crash_action                                      },
                { "Manager", "CrashAction",                       config_parse_crash_action,          0,                        &arg_crash_action                                      },
                { "Manager", "ShowStatus",                        config_parse_show_status,           0,                        &arg_show_status                                       },
                { "Manager", "StatusUnitFormat",                  config_parse_status_unit_format,    0,                        &arg_status_unit_format                                },
                { "Manager", "CPUAffinity",                       config_parse_cpu_set,               0,                        &arg_cpu_affinity                                      },
                { "Manager", "NUMAPolicy",                        config_parse_numa_policy,           0,                        &arg_numa_policy.type                                  },
                { "Manager", "NUMAMask",                          config_parse_numa_mask,             0,                        &arg_numa_policy.nodes                                 },
                { "Manager", "JoinControllers",                   config_parse_warn_compat,           DISABLED_LEGACY,          NULL                                                   },
                { "Manager", "RuntimeWatchdogSec",                config_parse_watchdog_sec,          0,                        &arg_runtime_watchdog                                  },
                { "Manager", "RuntimeWatchdogPreSec",             config_parse_watchdog_sec,          0,                        &arg_pretimeout_watchdog                               },
                { "Manager", "RebootWatchdogSec",                 config_parse_watchdog_sec,          0,                        &arg_reboot_watchdog                                   },
                { "Manager", "ShutdownWatchdogSec",               config_parse_watchdog_sec,          0,                        &arg_reboot_watchdog                                   }, /* obsolete alias */
                { "Manager", "KExecWatchdogSec",                  config_parse_watchdog_sec,          0,                        &arg_kexec_watchdog                                    },
                { "Manager", "WatchdogDevice",                    config_parse_path,                  0,                        &arg_watchdog_device                                   },
                { "Manager", "RuntimeWatchdogPreGovernor",        config_parse_string,                CONFIG_PARSE_STRING_SAFE, &arg_watchdog_pretimeout_governor                      },
                { "Manager", "CapabilityBoundingSet",             config_parse_capability_set,        0,                        &arg_capability_bounding_set                           },
                { "Manager", "NoNewPrivileges",                   config_parse_bool,                  0,                        &arg_no_new_privs                                      },
                { "Manager", "ProtectSystem",                     config_parse_protect_system_pid1,   0,                        &arg_protect_system                                    },
                { "Manager", "RestrictFileSystemAccess",         config_parse_restrict_filesystem_access, 0,                   &arg_restrict_filesystem_access                         },
#if HAVE_SECCOMP
                { "Manager", "SystemCallArchitectures",           config_parse_syscall_archs,         0,                        &arg_syscall_archs                                     },
#else
                { "Manager", "SystemCallArchitectures",           config_parse_warn_compat,           DISABLED_CONFIGURATION,   NULL                                                   },
#endif
                { "Manager", "TimerSlackNSec",                    config_parse_nsec,                  0,                        &arg_timer_slack_nsec                                  },
                { "Manager", "DefaultTimerAccuracySec",           config_parse_sec,                   0,                        &arg_defaults.timer_accuracy_usec                      },
                { "Manager", "DefaultStandardOutput",             config_parse_output_restricted,     0,                        &arg_defaults.std_output                               },
                { "Manager", "DefaultStandardError",              config_parse_output_restricted,     0,                        &arg_defaults.std_error                                },
                { "Manager", "DefaultTimeoutStartSec",            config_parse_sec,                   0,                        &arg_defaults.timeout_start_usec                       },
                { "Manager", "DefaultTimeoutStopSec",             config_parse_sec,                   0,                        &arg_defaults.timeout_stop_usec                        },
                { "Manager", "DefaultTimeoutAbortSec",            config_parse_default_timeout_abort, 0,                        NULL                                                   },
                { "Manager", "DefaultDeviceTimeoutSec",           config_parse_sec,                   0,                        &arg_defaults.device_timeout_usec                      },
                { "Manager", "DefaultRestartSec",                 config_parse_sec,                   0,                        &arg_defaults.restart_usec                             },
                { "Manager", "DefaultStartLimitInterval",         config_parse_sec,                   0,                        &arg_defaults.start_limit.interval                     }, /* obsolete alias */
                { "Manager", "DefaultStartLimitIntervalSec",      config_parse_sec,                   0,                        &arg_defaults.start_limit.interval                     },
                { "Manager", "DefaultStartLimitBurst",            config_parse_unsigned,              0,                        &arg_defaults.start_limit.burst                        },
                { "Manager", "DefaultRestrictSUIDSGID",           config_parse_bool,                  0,                        &arg_defaults.restrict_suid_sgid                       },
                { "Manager", "DefaultEnvironment",                config_parse_environ,               arg_runtime_scope,        &arg_default_environment                               },
                { "Manager", "ManagerEnvironment",                config_parse_environ,               arg_runtime_scope,        &arg_manager_environment                               },
                { "Manager", "DefaultLimitCPU",                   config_parse_rlimit,                RLIMIT_CPU,               arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitFSIZE",                 config_parse_rlimit,                RLIMIT_FSIZE,             arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitDATA",                  config_parse_rlimit,                RLIMIT_DATA,              arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitSTACK",                 config_parse_rlimit,                RLIMIT_STACK,             arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitCORE",                  config_parse_rlimit,                RLIMIT_CORE,              arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitRSS",                   config_parse_rlimit,                RLIMIT_RSS,               arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitNOFILE",                config_parse_rlimit,                RLIMIT_NOFILE,            arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitAS",                    config_parse_rlimit,                RLIMIT_AS,                arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitNPROC",                 config_parse_rlimit,                RLIMIT_NPROC,             arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitMEMLOCK",               config_parse_rlimit,                RLIMIT_MEMLOCK,           arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitLOCKS",                 config_parse_rlimit,                RLIMIT_LOCKS,             arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitSIGPENDING",            config_parse_rlimit,                RLIMIT_SIGPENDING,        arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitMSGQUEUE",              config_parse_rlimit,                RLIMIT_MSGQUEUE,          arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitNICE",                  config_parse_rlimit,                RLIMIT_NICE,              arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitRTPRIO",                config_parse_rlimit,                RLIMIT_RTPRIO,            arg_defaults.rlimit                                    },
                { "Manager", "DefaultLimitRTTIME",                config_parse_rlimit,                RLIMIT_RTTIME,            arg_defaults.rlimit                                    },
                { "Manager", "DefaultCPUAccounting",              config_parse_warn_compat,           DISABLED_LEGACY,          NULL                                                   },
                { "Manager", "DefaultIOAccounting",               config_parse_bool,                  0,                        &arg_defaults.io_accounting                            },
                { "Manager", "DefaultIPAccounting",               config_parse_bool,                  0,                        &arg_defaults.ip_accounting                            },
                { "Manager", "DefaultBlockIOAccounting",          config_parse_warn_compat,           DISABLED_LEGACY,          NULL                                                   },
                { "Manager", "DefaultMemoryAccounting",           config_parse_bool,                  0,                        &arg_defaults.memory_accounting                        },
                { "Manager", "DefaultTasksAccounting",            config_parse_bool,                  0,                        &arg_defaults.tasks_accounting                         },
                { "Manager", "DefaultTasksMax",                   config_parse_tasks_max,             0,                        &arg_defaults.tasks_max                                },
                { "Manager", "DefaultMemoryPressureThresholdSec", config_parse_sec,                   0,                        &arg_defaults.pressure[PRESSURE_MEMORY].threshold_usec },
                { "Manager", "DefaultMemoryPressureWatch",        config_parse_pressure_watch,        0,                        &arg_defaults.pressure[PRESSURE_MEMORY].watch          },
                { "Manager", "DefaultCPUPressureThresholdSec",    config_parse_sec,                   0,                        &arg_defaults.pressure[PRESSURE_CPU].threshold_usec    },
                { "Manager", "DefaultCPUPressureWatch",           config_parse_pressure_watch,        0,                        &arg_defaults.pressure[PRESSURE_CPU].watch             },
                { "Manager", "DefaultIOPressureThresholdSec",     config_parse_sec,                   0,                        &arg_defaults.pressure[PRESSURE_IO].threshold_usec     },
                { "Manager", "DefaultIOPressureWatch",            config_parse_pressure_watch,        0,                        &arg_defaults.pressure[PRESSURE_IO].watch              },
                { "Manager", "CtrlAltDelBurstAction",             config_parse_emergency_action,      arg_runtime_scope,        &arg_cad_burst_action                                  },
                { "Manager", "DefaultOOMPolicy",                  config_parse_oom_policy,            0,                        &arg_defaults.oom_policy                               },
                { "Manager", "DefaultOOMScoreAdjust",             config_parse_oom_score_adjust,      0,                        NULL                                                   },
                { "Manager", "ReloadLimitIntervalSec",            config_parse_sec,                   0,                        &arg_reload_limit_interval_sec                         },
                { "Manager", "ReloadLimitBurst",                  config_parse_unsigned,              0,                        &arg_reload_limit_burst                                },
                { "Manager", "EventLoopRateLimitIntervalSec",     config_parse_sec,                   0,                        &arg_event_loop_ratelimit_interval_sec                 },
                { "Manager", "EventLoopRateLimitBurst",           config_parse_unsigned,              0,                        &arg_event_loop_ratelimit_burst                        },
                { "Manager", "DefaultMemoryZSwapWriteback",       config_parse_bool,                  0,                        &arg_defaults.memory_zswap_writeback                   },
                { "Manager", "MinimumUptimeSec",                  config_parse_sec,                   0,                        &arg_minimum_uptime_usec                               },
#if ENABLE_SMACK
                { "Manager", "DefaultSmackProcessLabel",          config_parse_string,                0,                        &arg_defaults.smack_process_label                      },
#else
                { "Manager", "DefaultSmackProcessLabel",          config_parse_warn_compat,           DISABLED_CONFIGURATION,   NULL                                                   },
#endif
                {}
        };
 
        if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM)
                (void) config_parse_standard_file_with_dropins(
                                "systemd/system.conf",
                                "Manager\0",
                                config_item_table_lookup, items,
                                CONFIG_PARSE_WARN,
                                /* userdata= */ NULL);
        else {
                _cleanup_strv_free_ char **files = NULL, **dirs = NULL;
                int r;
 
                assert(arg_runtime_scope == RUNTIME_SCOPE_USER);
 
                r = manager_find_user_config_paths(&files, &dirs);
                if (r < 0)
                        return log_error_errno(r, "Failed to determine config file paths: %m");
 
                (void) config_parse_many(
                                (const char* const*) files,
                                (const char* const*) dirs,
                                "user.conf.d",
                                "Manager\0",
                                config_item_table_lookup, items,
                                CONFIG_PARSE_WARN,
                                /* userdata= */ NULL);
        }
 
        /* Traditionally "0" was used to turn off the default unit timeouts. Fix this up so that we use
         * USEC_INFINITY like everywhere else. */
        if (arg_defaults.timeout_start_usec <= 0)
                arg_defaults.timeout_start_usec = USEC_INFINITY;
        if (arg_defaults.timeout_stop_usec <= 0)
                arg_defaults.timeout_stop_usec = USEC_INFINITY;
 
        return 0;
}
 
static void set_manager_defaults(Manager *m) {
        int r;
 
        assert(m);
 
        /* Propagates the various default unit property settings into the manager object, i.e. properties
         * that do not affect the manager itself, but are just what newly allocated units will have set if
         * they haven't set anything else. (Also see set_manager_settings() for the settings that affect the
         * manager's own behaviour) */
 
        r = manager_set_unit_defaults(m, &arg_defaults);
        if (r < 0)
                log_warning_errno(r, "Failed to set manager defaults, ignoring: %m");
 
        r = manager_default_environment(m);
        if (r < 0)
                log_warning_errno(r, "Failed to set manager default environment, ignoring: %m");
 
        r = manager_transient_environment_add(m, arg_default_environment);
        if (r < 0)
                log_warning_errno(r, "Failed to add to transient environment, ignoring: %m");
}
 
static void set_manager_settings(Manager *m) {
        int r;
 
        assert(m);
 
        /* Propagates the various manager settings into the manager object, i.e. properties that
         * affect the manager itself (as opposed to just being inherited into newly allocated
         * units, see set_manager_defaults() above). */
 
        m->confirm_spawn = arg_confirm_spawn;
        m->service_watchdogs = arg_service_watchdogs;
        m->cad_burst_action = arg_cad_burst_action;
        /* Note that we don't do structured initialization here, otherwise it will reset the rate limit
         * counter on every daemon-reload. */
        m->reload_reexec_ratelimit.interval = arg_reload_limit_interval_sec;
        m->reload_reexec_ratelimit.burst = arg_reload_limit_burst;