diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-09-08 13:37:52 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-09-08 14:19:45 +0200 |
commit | c9e120e06f929d8f4bbc4faaf87d641c6938dc08 (patch) | |
tree | edf805cdf2199496f3854a1118f0013bc99279ac /src | |
parent | Merge pull request #29123 from yuwata/conf-parser-cleanups-for-config-section (diff) | |
download | systemd-c9e120e06f929d8f4bbc4faaf87d641c6938dc08.tar.xz systemd-c9e120e06f929d8f4bbc4faaf87d641c6938dc08.zip |
manager: move various fields that declare unit defaults into a new structure UnitDefaults
This adds a new structure UnitDefaults which embedds the various default
settings for units we maintain. We so far maintained two sets of
variables for this, one in main.c as static variables and one in the
Manager structure. This moves them into a common structure.
This is most just search/replace, i.e. very dumb refactoring.
The fact that we now use a common structure for this allows us further
refactorings later.
Inspired by the discussions on #27890
Diffstat (limited to 'src')
-rw-r--r-- | src/core/dbus-manager.c | 110 | ||||
-rw-r--r-- | src/core/device.c | 2 | ||||
-rw-r--r-- | src/core/execute.c | 4 | ||||
-rw-r--r-- | src/core/load-fragment.c | 2 | ||||
-rw-r--r-- | src/core/main.c | 288 | ||||
-rw-r--r-- | src/core/manager.c | 53 | ||||
-rw-r--r-- | src/core/manager.h | 67 | ||||
-rw-r--r-- | src/core/mount.c | 6 | ||||
-rw-r--r-- | src/core/scope.c | 6 | ||||
-rw-r--r-- | src/core/service.c | 16 | ||||
-rw-r--r-- | src/core/socket.c | 6 | ||||
-rw-r--r-- | src/core/swap.c | 6 | ||||
-rw-r--r-- | src/core/timer.c | 2 | ||||
-rw-r--r-- | src/core/unit.c | 37 | ||||
-rw-r--r-- | src/test/test-cgroup-mask.c | 12 | ||||
-rw-r--r-- | src/test/test-execute.c | 2 |
16 files changed, 311 insertions, 308 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 3d1a38b21e..3dd6e8abe3 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -462,8 +462,8 @@ static int property_get_oom_score_adjust( assert(bus); assert(reply); - if (m->default_oom_score_adjust_set) - n = m->default_oom_score_adjust; + if (m->defaults.oom_score_adjust_set) + n = m->defaults.oom_score_adjust; else { n = 0; r = get_oom_score_adjust(&n); @@ -2989,8 +2989,8 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("ShowStatus", "b", property_get_show_status, 0, 0), SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_error), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, defaults.std_output), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, defaults.std_error), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("WatchdogDevice", "s", property_get_watchdog_device, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("WatchdogLastPingTimestamp", "t", property_get_watchdog_last_ping_realtime, 0, 0), SD_BUS_PROPERTY("WatchdogLastPingTimestampMonotonic", "t", property_get_watchdog_last_ping_monotonic, 0, 0), @@ -3005,60 +3005,60 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0), SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0), SD_BUS_PROPERTY("ExitCode", "y", bus_property_get_unsigned, offsetof(Manager, return_value), 0), - SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, default_timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultTimeoutAbortUSec", "t", property_get_default_timeout_abort_usec, 0, 0), - SD_BUS_PROPERTY("DefaultDeviceTimeoutUSec", "t", bus_property_get_usec, offsetof(Manager, default_device_timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, default_restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultDeviceTimeoutUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.device_timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.restart_usec), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST), /* The following two items are obsolete alias */ - SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), - SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), - SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, default_start_limit_burst), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, default_cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultIOAccounting", "b", bus_property_get_bool, offsetof(Manager, default_io_accounting), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultIPAccounting", "b", bus_property_get_bool, offsetof(Manager, default_ip_accounting), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, default_memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, default_tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultTasksMax", "t", bus_property_get_tasks_max, offsetof(Manager, default_tasks_max), 0), - SD_BUS_PROPERTY("DefaultMemoryPressureThresholdUSec", "t", bus_property_get_usec, offsetof(Manager, default_memory_pressure_threshold_usec), 0), - SD_BUS_PROPERTY("DefaultMemoryPressureWatch", "s", bus_property_get_cgroup_pressure_watch, offsetof(Manager, default_memory_pressure_watch), 0), + SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, defaults.start_limit_burst), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultIOAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.io_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultIPAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.ip_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitFSIZE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitDATA", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitDATASoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitSTACK", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitCORE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitCORESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitRSS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitRSSSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitNOFILE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitAS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitASSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitNPROC", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitLOCKS", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitNICESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultLimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultTasksMax", "t", bus_property_get_tasks_max, offsetof(Manager, defaults.tasks_max), 0), + SD_BUS_PROPERTY("DefaultMemoryPressureThresholdUSec", "t", bus_property_get_usec, offsetof(Manager, defaults.memory_pressure_threshold_usec), 0), + SD_BUS_PROPERTY("DefaultMemoryPressureWatch", "s", bus_property_get_cgroup_pressure_watch, offsetof(Manager, defaults.memory_pressure_watch), 0), SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy, offsetof(Manager, default_oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy, offsetof(Manager, defaults.oom_policy), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultOOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("CtrlAltDelBurstAction", "s", bus_property_get_emergency_action, offsetof(Manager, cad_burst_action), SD_BUS_VTABLE_PROPERTY_CONST), diff --git a/src/core/device.c b/src/core/device.c index b3429f4b3d..ffe85bdb29 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -129,7 +129,7 @@ static void device_init(Unit *u) { * indefinitely for plugged in devices, something which cannot * happen for the other units since their operations time out * anyway. */ - u->job_running_timeout = u->manager->default_device_timeout_usec; + u->job_running_timeout = u->manager->defaults.device_timeout_usec; u->ignore_on_isolate = true; diff --git a/src/core/execute.c b/src/core/execute.c index 701e1ead2a..ac71666bfa 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2735,14 +2735,14 @@ static int setup_smack( r = mac_smack_apply_pid(0, context->smack_process_label); if (r < 0) return r; - } else if (manager->default_smack_process_label) { + } else if (manager->defaults.smack_process_label) { _cleanup_free_ char *exec_label = NULL; r = mac_smack_read_fd(executable_fd, SMACK_ATTR_EXEC, &exec_label); if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r)) return r; - r = mac_smack_apply_pid(0, exec_label ?: manager->default_smack_process_label); + r = mac_smack_apply_pid(0, exec_label ?: manager->defaults.smack_process_label); if (r < 0) return r; } diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index cbc6da49af..d89f5ca229 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -3920,7 +3920,7 @@ int config_parse_tasks_max( int r; if (isempty(rvalue)) { - *tasks_max = u ? u->manager->default_tasks_max : TASKS_MAX_UNSET; + *tasks_max = u ? u->manager->defaults.tasks_max : TASKS_MAX_UNSET; return 0; } diff --git a/src/core/main.c b/src/core/main.c index 279f1b16ce..bd9e137871 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -130,16 +130,7 @@ static StatusUnitFormat arg_status_unit_format; static bool arg_switched_root; static PagerFlags arg_pager_flags; static bool arg_service_watchdogs; -static ExecOutput arg_default_std_output; -static ExecOutput arg_default_std_error; -static usec_t arg_default_restart_usec; -static usec_t arg_default_timeout_start_usec; -static usec_t arg_default_timeout_stop_usec; -static usec_t arg_default_timeout_abort_usec; -static usec_t arg_default_device_timeout_usec; -static bool arg_default_timeout_abort_set; -static usec_t arg_default_start_limit_interval; -static unsigned arg_default_start_limit_burst; +static UnitDefaults arg_defaults; static usec_t arg_runtime_watchdog; static usec_t arg_reboot_watchdog; static usec_t arg_kexec_watchdog; @@ -149,33 +140,18 @@ static char *arg_watchdog_pretimeout_governor; static char *arg_watchdog_device; static char **arg_default_environment; static char **arg_manager_environment; -static struct rlimit *arg_default_rlimit[_RLIMIT_MAX]; static uint64_t arg_capability_bounding_set; static bool arg_no_new_privs; static nsec_t arg_timer_slack_nsec; -static usec_t arg_default_timer_accuracy_usec; static Set* arg_syscall_archs; static FILE* arg_serialization; -static int arg_default_cpu_accounting; -static bool arg_default_io_accounting; -static bool arg_default_ip_accounting; -static bool arg_default_blockio_accounting; -static bool arg_default_memory_accounting; -static bool arg_default_tasks_accounting; -static TasksMax arg_default_tasks_max; -static usec_t arg_default_memory_pressure_threshold_usec; -static CGroupPressureWatch arg_default_memory_pressure_watch; static sd_id128_t arg_machine_id; static EmergencyAction arg_cad_burst_action; -static OOMPolicy arg_default_oom_policy; 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 int arg_default_oom_score_adjust; -static bool arg_default_oom_score_adjust_set; -static char *arg_default_smack_process_label; static usec_t arg_reload_limit_interval_sec; static unsigned arg_reload_limit_burst; @@ -347,7 +323,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (r < 0) log_warning_errno(r, "Failed to parse default standard output switch %s, ignoring: %m", value); else - arg_default_std_output = r; + arg_defaults.std_output = r; } else if (proc_cmdline_key_streq(key, "systemd.default_standard_error")) { @@ -358,7 +334,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (r < 0) log_warning_errno(r, "Failed to parse default standard error switch %s, ignoring: %m", value); else - arg_default_std_error = r; + arg_defaults.std_error = r; } else if (streq(key, "systemd.setenv")) { @@ -387,24 +363,24 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (proc_cmdline_value_missing(key, value)) return 0; - r = parse_sec(value, &arg_default_timeout_start_usec); + 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_default_timeout_start_usec <= 0) - arg_default_timeout_start_usec = USEC_INFINITY; + 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_default_device_timeout_usec); + 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_default_device_timeout_usec <= 0) - arg_default_device_timeout_usec = USEC_INFINITY; + if (arg_defaults.device_timeout_usec <= 0) + arg_defaults.device_timeout_usec = USEC_INFINITY; } else if (proc_cmdline_key_streq(key, "systemd.cpu_affinity")) { @@ -589,10 +565,19 @@ static int config_parse_default_timeout_abort( void *userdata) { int r; - r = config_parse_timeout_abort(unit, filename, line, section, section_line, lvalue, ltype, rvalue, - &arg_default_timeout_abort_usec, userdata); + r = config_parse_timeout_abort( + unit, + filename, + line, + section, + section_line, + lvalue, + ltype, + rvalue, + &arg_defaults.timeout_abort_usec, + userdata); if (r >= 0) - arg_default_timeout_abort_set = r; + arg_defaults.timeout_abort_set = r; return 0; } @@ -611,7 +596,7 @@ static int config_parse_oom_score_adjust( int oa, r; if (isempty(rvalue)) { - arg_default_oom_score_adjust_set = false; + arg_defaults.oom_score_adjust_set = false; return 0; } @@ -621,8 +606,8 @@ static int config_parse_oom_score_adjust( return 0; } - arg_default_oom_score_adjust = oa; - arg_default_oom_score_adjust_set = true; + arg_defaults.oom_score_adjust = oa; + arg_defaults.oom_score_adjust_set = true; return 0; } @@ -661,51 +646,51 @@ static int parse_config_file(void) { #endif { "Manager", "TimerSlackNSec", config_parse_nsec, 0, &arg_timer_slack_nsec }, - { "Manager", "DefaultTimerAccuracySec", config_parse_sec, 0, &arg_default_timer_accuracy_usec }, - { "Manager", "DefaultStandardOutput", config_parse_output_restricted, 0, &arg_default_std_output }, - { "Manager", "DefaultStandardError", config_parse_output_restricted, 0, &arg_default_std_error }, - { "Manager", "DefaultTimeoutStartSec", config_parse_sec, 0, &arg_default_timeout_start_usec }, - { "Manager", "DefaultTimeoutStopSec", config_parse_sec, 0, &arg_default_timeout_stop_usec }, + { "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_default_device_timeout_usec }, - { "Manager", "DefaultRestartSec", config_parse_sec, 0, &arg_default_restart_usec }, - { "Manager", "DefaultStartLimitInterval", config_parse_sec, 0, &arg_default_start_limit_interval }, /* obsolete alias */ - { "Manager", "DefaultStartLimitIntervalSec", config_parse_sec, 0, &arg_default_start_limit_interval }, - { "Manager", "DefaultStartLimitBurst", config_parse_unsigned, 0, &arg_default_start_limit_burst }, + { "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", "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_default_rlimit }, - { "Manager", "DefaultLimitFSIZE", config_parse_rlimit, RLIMIT_FSIZE, arg_default_rlimit }, - { "Manager", "DefaultLimitDATA", config_parse_rlimit, RLIMIT_DATA, arg_default_rlimit }, - { "Manager", "DefaultLimitSTACK", config_parse_rlimit, RLIMIT_STACK, arg_default_rlimit }, - { "Manager", "DefaultLimitCORE", config_parse_rlimit, RLIMIT_CORE, arg_default_rlimit }, - { "Manager", "DefaultLimitRSS", config_parse_rlimit, RLIMIT_RSS, arg_default_rlimit }, - { "Manager", "DefaultLimitNOFILE", config_parse_rlimit, RLIMIT_NOFILE, arg_default_rlimit }, - { "Manager", "DefaultLimitAS", config_parse_rlimit, RLIMIT_AS, arg_default_rlimit }, - { "Manager", "DefaultLimitNPROC", config_parse_rlimit, RLIMIT_NPROC, arg_default_rlimit }, - { "Manager", "DefaultLimitMEMLOCK", config_parse_rlimit, RLIMIT_MEMLOCK, arg_default_rlimit }, - { "Manager", "DefaultLimitLOCKS", config_parse_rlimit, RLIMIT_LOCKS, arg_default_rlimit }, - { "Manager", "DefaultLimitSIGPENDING", config_parse_rlimit, RLIMIT_SIGPENDING, arg_default_rlimit }, - { "Manager", "DefaultLimitMSGQUEUE", config_parse_rlimit, RLIMIT_MSGQUEUE, arg_default_rlimit }, - { "Manager", "DefaultLimitNICE", config_parse_rlimit, RLIMIT_NICE, arg_default_rlimit }, - { "Manager", "DefaultLimitRTPRIO", config_parse_rlimit, RLIMIT_RTPRIO, arg_default_rlimit }, - { "Manager", "DefaultLimitRTTIME", config_parse_rlimit, RLIMIT_RTTIME, arg_default_rlimit }, - { "Manager", "DefaultCPUAccounting", config_parse_tristate, 0, &arg_default_cpu_accounting }, - { "Manager", "DefaultIOAccounting", config_parse_bool, 0, &arg_default_io_accounting }, - { "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_default_ip_accounting }, - { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting }, - { "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", "DefaultMemoryPressureThresholdSec", config_parse_sec, 0, &arg_default_memory_pressure_threshold_usec }, - { "Manager", "DefaultMemoryPressureWatch", config_parse_memory_pressure_watch, 0, &arg_default_memory_pressure_watch }, + { "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_bool, 0, &arg_defaults.cpu_accounting }, + { "Manager", "DefaultIOAccounting", config_parse_bool, 0, &arg_defaults.io_accounting }, + { "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_defaults.ip_accounting }, + { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_defaults.blockio_accounting }, + { "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.memory_pressure_threshold_usec }, + { "Manager", "DefaultMemoryPressureWatch", config_parse_memory_pressure_watch, 0, &arg_defaults.memory_pressure_watch }, { "Manager", "CtrlAltDelBurstAction", config_parse_emergency_action, arg_runtime_scope, &arg_cad_burst_action }, - { "Manager", "DefaultOOMPolicy", config_parse_oom_policy, 0, &arg_default_oom_policy }, + { "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 }, #if ENABLE_SMACK - { "Manager", "DefaultSmackProcessLabel", config_parse_string, 0, &arg_default_smack_process_label }, + { "Manager", "DefaultSmackProcessLabel", config_parse_string, 0, &arg_defaults.smack_process_label }, #else { "Manager", "DefaultSmackProcessLabel", config_parse_warn_compat, DISABLED_CONFIGURATION, NULL }, #endif @@ -741,10 +726,10 @@ static int parse_config_file(void) { /* 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_default_timeout_start_usec <= 0) - arg_default_timeout_start_usec = USEC_INFINITY; - if (arg_default_timeout_stop_usec <= 0) - arg_default_timeout_stop_usec = USEC_INFINITY; + 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; } @@ -757,40 +742,33 @@ static void set_manager_defaults(Manager *m) { * 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) */ - m->default_timer_accuracy_usec = arg_default_timer_accuracy_usec; - m->default_std_output = arg_default_std_output; - m->default_std_error = arg_default_std_error; - m->default_timeout_start_usec = arg_default_timeout_start_usec; - m->default_timeout_stop_usec = arg_default_timeout_stop_usec; - m->default_timeout_abort_usec = arg_default_timeout_abort_usec; - m->default_timeout_abort_set = arg_default_timeout_abort_set; - m->default_device_timeout_usec = arg_default_device_timeout_usec; - m->default_restart_usec = arg_default_restart_usec; - m->default_start_limit_interval = arg_default_start_limit_interval; - m->default_start_limit_burst = arg_default_start_limit_burst; - - /* On 4.15+ with unified hierarchy, CPU accounting is essentially free as it doesn't require the CPU - * controller to be enabled, so the default is to enable it unless we got told otherwise. */ - if (arg_default_cpu_accounting >= 0) - m->default_cpu_accounting = arg_default_cpu_accounting; - else - m->default_cpu_accounting = cpu_accounting_is_cheap(); - - m->default_io_accounting = arg_default_io_accounting; - m->default_ip_accounting = arg_default_ip_accounting; - m->default_blockio_accounting = arg_default_blockio_accounting; - m->default_memory_accounting = arg_default_memory_accounting; - m->default_tasks_accounting = arg_default_tasks_accounting; - m->default_tasks_max = arg_default_tasks_max; - m->default_memory_pressure_watch = arg_default_memory_pressure_watch; - m->default_memory_pressure_threshold_usec = arg_default_memory_pressure_threshold_usec; - m->default_oom_policy = arg_default_oom_policy; - m->default_oom_score_adjust_set = arg_default_oom_score_adjust_set; - m->default_oom_score_adjust = arg_default_oom_score_adjust; - - (void) manager_set_default_smack_process_label(m, arg_default_smack_process_label); - - (void) manager_set_default_rlimits(m, arg_default_rlimit); + m->defaults.timer_accuracy_usec = arg_defaults.timer_accuracy_usec; + m->defaults.std_output = arg_defaults.std_output; + m->defaults.std_error = arg_defaults.std_error; + m->defaults.timeout_start_usec = arg_defaults.timeout_start_usec; + m->defaults.timeout_stop_usec = arg_defaults.timeout_stop_usec; + m->defaults.timeout_abort_usec = arg_defaults.timeout_abort_usec; + m->defaults.timeout_abort_set = arg_defaults.timeout_abort_set; + m->defaults.device_timeout_usec = arg_defaults.device_timeout_usec; + m->defaults.restart_usec = arg_defaults.restart_usec; + m->defaults.start_limit_interval = arg_defaults.start_limit_interval; + m->defaults.start_limit_burst = arg_defaults.start_limit_burst; + m->defaults.cpu_accounting = arg_defaults.cpu_accounting; + m->defaults.io_accounting = arg_defaults.io_accounting; + m->defaults.ip_accounting = arg_defaults.ip_accounting; + m->defaults.blockio_accounting = arg_defaults.blockio_accounting; + m->defaults.memory_accounting = arg_defaults.memory_accounting; + m->defaults.tasks_accounting = arg_defaults.tasks_accounting; + m->defaults.tasks_max = arg_defaults.tasks_max; + m->defaults.memory_pressure_watch = arg_defaults.memory_pressure_watch; + m->defaults.memory_pressure_threshold_usec = arg_defaults.memory_pressure_threshold_usec; + m->defaults.oom_policy = arg_defaults.oom_policy; + m->defaults.oom_score_adjust_set = arg_defaults.oom_score_adjust_set; + m->defaults.oom_score_adjust = arg_defaults.oom_score_adjust; + + (void) manager_set_default_smack_process_label(m, arg_defaults.smack_process_label); + + (void) manager_set_default_rlimits(m, arg_defaults.rlimit); (void) manager_default_environment(m); (void) manager_transient_environment_add(m, arg_default_environment); @@ -904,7 +882,7 @@ static int parse_argv(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to parse default standard output setting \"%s\": %m", optarg); - arg_default_std_output = r; + arg_defaults.std_output = r; break; case ARG_DEFAULT_STD_ERROR: @@ -912,7 +890,7 @@ static int parse_argv(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to parse default standard error output setting \"%s\": %m", optarg); - arg_default_std_error = r; + arg_defaults.std_error = r; break; case ARG_UNIT: @@ -1520,7 +1498,7 @@ static int become_shutdown(int objective, int retval) { assert(table[objective]); xsprintf(log_level, "--log-level=%d", log_get_max_level()); - xsprintf(timeout, "--timeout=%" PRI_USEC "us", arg_default_timeout_stop_usec); + xsprintf(timeout, "--timeout=%" PRI_USEC "us", arg_defaults.timeout_stop_usec); const char* command_line[10] = { SYSTEMD_SHUTDOWN_BINARY_PATH, @@ -1805,11 +1783,11 @@ static void finish_remaining_processes(ManagerObjective objective) { /* Kill all remaining processes from the initrd, but don't wait for them, so that we can handle the * SIGCHLD for them after deserializing. */ if (IN_SET(objective, MANAGER_SWITCH_ROOT, MANAGER_SOFT_REBOOT)) - broadcast_signal(SIGTERM, /* wait_for_exit= */ false, /* send_sighup= */ true, arg_default_timeout_stop_usec); + broadcast_signal(SIGTERM, /* wait_for_exit= */ false, /* send_sighup= */ true, arg_defaults.timeout_stop_usec); /* On soft reboot really make sure nothing is left */ if (objective == MANAGER_SOFT_REBOOT) - broadcast_signal(SIGKILL, /* wait_for_exit= */ false, /* send_sighup= */ false, arg_default_timeout_stop_usec); + broadcast_signal(SIGKILL, /* wait_for_exit= */ false, /* send_sighup= */ false, arg_defaults.timeout_stop_usec); } static int do_reexecute( @@ -2460,7 +2438,7 @@ static void save_rlimits(struct rlimit *saved_rlimit_nofile, static void fallback_rlimit_nofile(const struct rlimit *saved_rlimit_nofile) { struct rlimit *rl; - if (arg_default_rlimit[RLIMIT_NOFILE]) + if (arg_defaults.rlimit[RLIMIT_NOFILE]) return; /* Make sure forked processes get limits based on the original kernel setting */ @@ -2498,7 +2476,7 @@ static void fallback_rlimit_nofile(const struct rlimit *saved_rlimit_nofile) { * instance), then lower what we pass on to not confuse our children */ rl->rlim_cur = MIN(rl->rlim_cur, (rlim_t) FD_SETSIZE); - arg_default_rlimit[RLIMIT_NOFILE] = rl; + arg_defaults.rlimit[RLIMIT_NOFILE] = rl; } static void fallback_rlimit_memlock(const struct rlimit *saved_rlimit_memlock) { @@ -2506,7 +2484,7 @@ static void fallback_rlimit_memlock(const struct rlimit *saved_rlimit_memlock) { /* Pass the original value down to invoked processes */ - if (arg_default_rlimit[RLIMIT_MEMLOCK]) + if (arg_defaults.rlimit[RLIMIT_MEMLOCK]) return; rl = newdup(struct rlimit, saved_rlimit_memlock, 1); @@ -2522,7 +2500,7 @@ static void fallback_rlimit_memlock(const struct rlimit *saved_rlimit_memlock) { rl->rlim_cur = MAX(rl->rlim_cur, (rlim_t) DEFAULT_RLIMIT_MEMLOCK); } - arg_default_rlimit[RLIMIT_MEMLOCK] = rl; + arg_defaults.rlimit[RLIMIT_MEMLOCK] = rl; } static void setenv_manager_environment(void) { @@ -2554,16 +2532,39 @@ static void reset_arguments(void) { arg_switched_root = false; arg_pager_flags = 0; arg_service_watchdogs = true; - arg_default_std_output = EXEC_OUTPUT_JOURNAL; - arg_default_std_error = EXEC_OUTPUT_INHERIT; - arg_default_restart_usec = DEFAULT_RESTART_USEC; - arg_default_timeout_start_usec = manager_default_timeout(arg_runtime_scope); - arg_default_timeout_stop_usec = manager_default_timeout(arg_runtime_scope); - arg_default_timeout_abort_usec = manager_default_timeout(arg_runtime_scope); - arg_default_timeout_abort_set = false; - arg_default_device_timeout_usec = manager_default_timeout(arg_runtime_scope); - arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL; - arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST; + + unit_defaults_done(&arg_defaults); + + arg_defaults = (UnitDefaults) { + .std_output = EXEC_OUTPUT_JOURNAL, + .std_error = EXEC_OUTPUT_INHERIT, + .restart_usec = DEFAULT_RESTART_USEC, + .timeout_start_usec = manager_default_timeout(arg_runtime_scope), + .timeout_stop_usec = manager_default_timeout(arg_runtime_scope), + .timeout_abort_usec = manager_default_timeout(arg_runtime_scope), + .timeout_abort_set = false, + .device_timeout_usec = manager_default_timeout(arg_runtime_scope), + .start_limit_interval = DEFAULT_START_LIMIT_INTERVAL, + .start_limit_burst = DEFAULT_START_LIMIT_BURST, + + /* On 4.15+ with unified hierarchy, CPU accounting is essentially free as it doesn't require the CPU + * controller to be enabled, so the default is to enable it unless we got told otherwise. */ + .cpu_accounting = cpu_accounting_is_cheap(), + .memory_accounting = MEMORY_ACCOUNTING_DEFAULT, + .io_accounting = false, + .blockio_accounting = false, + .tasks_accounting = true, + .ip_accounting = false, + + .tasks_max = DEFAULT_TASKS_MAX, + .timer_accuracy_usec = 1 * USEC_PER_MINUTE, + + .memory_pressure_watch = CGROUP_PRESSURE_WATCH_AUTO, + .memory_pressure_threshold_usec = MEMORY_PRESSURE_DEFAULT_THRESHOLD_USEC, + + .oom_policy = OOM_STOP, + .oom_score_adjust_set = false, + }; arg_runtime_watchdog = 0; arg_reboot_watchdog = 10 * USEC_PER_MINUTE; arg_kexec_watchdog = 0; @@ -2574,29 +2575,17 @@ static void reset_arguments(void) { arg_default_environment = strv_free(arg_default_environment); arg_manager_environment = strv_free(arg_manager_environment); - rlimit_free_all(arg_default_rlimit); arg_capability_bounding_set = CAP_MASK_UNSET; arg_no_new_privs = false; arg_timer_slack_nsec = NSEC_INFINITY; - arg_default_timer_accuracy_usec = 1 * USEC_PER_MINUTE; arg_syscall_archs = set_free(arg_syscall_archs); /* arg_serialization — ignore */ - arg_default_cpu_accounting = -1; - arg_default_io_accounting = false; - arg_default_ip_accounting = false; - arg_default_blockio_accounting = false; - arg_default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT; - arg_default_tasks_accounting = true; - arg_default_tasks_max = DEFAULT_TASKS_MAX; - arg_default_memory_pressure_threshold_usec = MEMORY_PRESSURE_DEFAULT_THRESHOLD_USEC; - arg_default_memory_pressure_watch = CGROUP_PRESSURE_WATCH_AUTO; arg_machine_id = (sd_id128_t) {}; arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE; - arg_default_oom_policy = OOM_STOP; cpu_set_reset(&arg_cpu_affinity); numa_policy_reset(&arg_numa_policy); @@ -2605,9 +2594,6 @@ static void reset_arguments(void) { arg_random_seed_size = 0; arg_clock_usec = 0; - arg_default_oom_score_adjust_set = false; - arg_default_smack_process_label = mfree(arg_default_smack_process_label); - arg_reload_limit_interval_sec = 0; arg_reload_limit_burst = 0; } @@ -2619,7 +2605,7 @@ static void determine_default_oom_score_adjust(void) { * do this only if we don't run as root (i.e. only if we are run in user mode, for an unprivileged * user). */ - if (arg_default_oom_score_adjust_set) + if (arg_defaults.oom_score_adjust_set) return; if (getuid() == 0) @@ -2635,8 +2621,8 @@ static void determine_default_oom_score_adjust(void) { if (a == b) return; - arg_default_oom_score_adjust = b; - arg_default_oom_score_adjust_set = true; + arg_defaults.oom_score_adjust = b; + arg_defaults.oom_score_adjust_set = true; } static int parse_configuration(const struct rlimit *saved_rlimit_nofile, diff --git a/src/core/manager.c b/src/core/manager.c index 7492a0b1b8..45409ab6e4 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -806,12 +806,12 @@ int manager_setup_memory_pressure_event_source(Manager *m) { if (r < 0) log_full_errno(ERRNO_IS_NOT_SUPPORTED(r) || ERRNO_IS_PRIVILEGE(r) || (r == -EHOSTDOWN) ? LOG_DEBUG : LOG_NOTICE, r, "Failed to establish memory pressure event source, ignoring: %m"); - else if (m->default_memory_pressure_threshold_usec != USEC_INFINITY) { + else if (m->defaults.memory_pressure_threshold_usec != USEC_INFINITY) { /* If there's a default memory pressure threshold set, also apply it to the service manager itself */ r = sd_event_source_set_memory_pressure_period( m->memory_pressure_event_source, - m->default_memory_pressure_threshold_usec, + m->defaults.memory_pressure_threshold_usec, MEMORY_PRESSURE_DEFAULT_WINDOW_USEC); if (r < 0) log_warning_errno(r, "Failed to adjust memory pressure threshold, ignoring: %m"); @@ -872,14 +872,19 @@ int manager_new(RuntimeScope runtime_scope, ManagerTestRunFlags test_run_flags, .status_unit_format = STATUS_UNIT_FORMAT_DEFAULT, - .default_timer_accuracy_usec = USEC_PER_MINUTE, - .default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT, - .default_tasks_accounting = true, - .default_tasks_max = TASKS_MAX_UNSET, - .default_timeout_start_usec = manager_default_timeout(runtime_scope), - .default_timeout_stop_usec = manager_default_timeout(runtime_scope), - .default_restart_usec = DEFAULT_RESTART_USEC, - .default_device_timeout_usec = manager_default_timeout(runtime_scope), + .defaults = { + .timer_accuracy_usec = USEC_PER_MINUTE, + .memory_accounting = MEMORY_ACCOUNTING_DEFAULT, + .tasks_accounting = true, + .tasks_max = TASKS_MAX_UNSET, + .timeout_start_usec = manager_default_timeout(runtime_scope), + .timeout_stop_usec = manager_default_timeout(runtime_scope), + .restart_usec = DEFAULT_RESTART_USEC, + .device_timeout_usec = manager_default_timeout(runtime_scope), + .oom_policy = OOM_STOP, + .memory_pressure_watch = CGROUP_PRESSURE_WATCH_AUTO, + .memory_pressure_threshold_usec = USEC_INFINITY, + }, .original_log_level = -1, .original_log_target = _LOG_TARGET_INVALID, @@ -909,11 +914,6 @@ int manager_new(RuntimeScope runtime_scope, ManagerTestRunFlags test_run_flags, .first_boot = -1, .test_run_flags = test_run_flags, - .default_oom_policy = OOM_STOP, - - .default_memory_pressure_watch = CGROUP_PRESSURE_WATCH_AUTO, - .default_memory_pressure_threshold_usec = USEC_INFINITY, - .dump_ratelimit = { .interval = 10 * USEC_PER_MINUTE, .burst = 10, @@ -1673,9 +1673,7 @@ Manager* manager_free(Manager *m) { free(m->switch_root); free(m->switch_root_init); - free(m->default_smack_process_label); - - rlimit_free_all(m->rlimit); + unit_defaults_done(&m->defaults); assert(hashmap_isempty(m->units_requiring_mounts_for)); hashmap_free(m->units_requiring_mounts_for); @@ -4124,25 +4122,25 @@ int manager_set_default_smack_process_label(Manager *m, const char *label) { #ifdef SMACK_DEFAULT_PROCESS_LABEL if (!label) - return free_and_strdup(&m->default_smack_process_label, SMACK_DEFAULT_PROCESS_LABEL); + return free_and_strdup(&m->defaults.smack_process_label, SMACK_DEFAULT_PROCESS_LABEL); #endif if (streq_ptr(label, "/")) - return free_and_strdup(&m->default_smack_process_label, NULL); + return free_and_strdup(&m->defaults.smack_process_label, NULL); - return free_and_strdup(&m->default_smack_process_label, label); + return free_and_strdup(&m->defaults.smack_process_label, label); } int manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit) { assert(m); for (unsigned i = 0; i < _RLIMIT_MAX; i++) { - m->rlimit[i] = mfree(m->rlimit[i]); + m->defaults.rlimit[i] = mfree(m->defaults.rlimit[i]); if (!default_rlimit[i]) continue; - m->rlimit[i] = newdup(struct rlimit, default_rlimit[i], 1); - if (!m->rlimit[i]) + m->defaults.rlimit[i] = newdup(struct rlimit, default_rlimit[i], 1); + if (!m->defaults.rlimit[i]) return log_oom(); } @@ -4853,6 +4851,13 @@ ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s) { return s; } +void unit_defaults_done(UnitDefaults *defaults) { + assert(defaults); + + defaults->smack_process_label = mfree(defaults->smack_process_label); + rlimit_free_all(defaults->rlimit); +} + static const char *const manager_state_table[_MANAGER_STATE_MAX] = { [MANAGER_INITIALIZING] = "initializing", [MANAGER_STARTING] = "starting", diff --git a/src/core/manager.h b/src/core/manager.h index 3842c3f003..2309914a80 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -141,6 +141,38 @@ typedef enum ManagerTestRunFlags { assert_cc((MANAGER_TEST_FULL & UINT8_MAX) == MANAGER_TEST_FULL); +/* Various defaults for unit file settings. */ +typedef struct UnitDefaults { + ExecOutput std_output, std_error; + + usec_t restart_usec, timeout_start_usec, timeout_stop_usec, timeout_abort_usec, device_timeout_usec; + bool timeout_abort_set; + + usec_t start_limit_interval; + unsigned start_limit_burst; + + bool cpu_accounting; + bool memory_accounting; + bool io_accounting; + bool blockio_accounting; + bool tasks_accounting; + bool ip_accounting; + + TasksMax tasks_max; + usec_t timer_accuracy_usec; + + OOMPolicy oom_policy; + int oom_score_adjust; + bool oom_score_adjust_set; + + CGroupPressureWatch memory_pressure_watch; + usec_t memory_pressure_threshold_usec; + + char *smack_process_label; + + struct rlimit *rlimit[_RLIMIT_MAX]; +} UnitDefaults; + struct Manager { /* Note that the set of units we know of is allowed to be * inconsistent. However the subset of it that is loaded may @@ -356,40 +388,13 @@ struct Manager { bool no_console_output; bool service_watchdogs; - ExecOutput default_std_output, default_std_error; - - usec_t default_restart_usec, default_timeout_start_usec, default_timeout_stop_usec; - usec_t default_device_timeout_usec; - usec_t default_timeout_abort_usec; - bool default_timeout_abort_set; - - usec_t default_start_limit_interval; - unsigned default_start_limit_burst; - - bool default_cpu_accounting; - bool default_memory_accounting; - bool default_io_accounting; - bool default_blockio_accounting; - bool default_tasks_accounting; - bool default_ip_accounting; - - TasksMax default_tasks_max; - usec_t default_timer_accuracy_usec; - - OOMPolicy default_oom_policy; - int default_oom_score_adjust; - bool default_oom_score_adjust_set; - - CGroupPressureWatch default_memory_pressure_watch; - usec_t default_memory_pressure_threshold_usec; + UnitDefaults defaults; int original_log_level; LogTarget original_log_target; bool log_level_overridden; bool log_target_overridden; - struct rlimit *rlimit[_RLIMIT_MAX]; - /* non-zero if we are reloading or reexecuting, */ int n_reloading; @@ -466,8 +471,6 @@ struct Manager { /* Reference to RestrictFileSystems= BPF program */ struct restrict_fs_bpf *restrict_fs; - char *default_smack_process_label; - /* Allow users to configure a rate limit for Reload() operations */ RateLimit reload_ratelimit; /* Dump*() are slow, so always rate limit them to 10 per 10 minutes */ @@ -478,7 +481,7 @@ struct Manager { static inline usec_t manager_default_timeout_abort_usec(Manager *m) { assert(m); - return m->default_timeout_abort_set ? m->default_timeout_abort_usec : m->default_timeout_stop_usec; + return m->defaults.timeout_abort_set ? m->defaults.timeout_abort_usec : m->defaults.timeout_stop_usec; } #define MANAGER_IS_SYSTEM(m) ((m)->runtime_scope == RUNTIME_SCOPE_SYSTEM) @@ -611,3 +614,5 @@ int manager_override_watchdog_pretimeout_governor(Manager *m, const char *govern const char* oom_policy_to_string(OOMPolicy i) _const_; OOMPolicy oom_policy_from_string(const char *s) _pure_; + +void unit_defaults_done(UnitDefaults *defaults); diff --git a/src/core/mount.c b/src/core/mount.c index 931075a1ee..4b929ddaa4 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -172,10 +172,10 @@ static void mount_init(Unit *u) { assert(u); assert(u->load_state == UNIT_STUB); - m->timeout_usec = u->manager->default_timeout_start_usec; + m->timeout_usec = u->manager->defaults.timeout_start_usec; - m->exec_context.std_output = u->manager->default_std_output; - m->exec_context.std_error = u->manager->default_std_error; + m->exec_context.std_output = u->manager->defaults.std_output; + m->exec_context.std_error = u->manager->defaults.std_error; m->directory_mode = 0755; diff --git a/src/core/scope.c b/src/core/scope.c index 4ab4c048b3..a13c8ddf7a 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -41,7 +41,7 @@ static void scope_init(Unit *u) { assert(u->load_state == UNIT_STUB); s->runtime_max_usec = USEC_INFINITY; - s->timeout_stop_usec = u->manager->default_timeout_stop_usec; + s->timeout_stop_usec = u->manager->defaults.timeout_stop_usec; u->ignore_on_isolate = true; s->user = s->group = NULL; s->oom_policy = _OOM_POLICY_INVALID; @@ -197,7 +197,7 @@ static int scope_add_extras(Scope *s) { return r; if (s->oom_policy < 0) - s->oom_policy = s->cgroup_context.delegate ? OOM_CONTINUE : UNIT(s)->manager->default_oom_policy; + s->oom_policy = s->cgroup_context.delegate ? OOM_CONTINUE : UNIT(s)->manager->defaults.oom_policy; s->cgroup_context.memory_oom_group = s->oom_policy == OOM_KILL; @@ -377,7 +377,7 @@ static int scope_enter_start_chown(Scope *s) { assert(s); assert(s->user); - r = scope_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), u->manager->default_timeout_start_usec)); + r = scope_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), u->manager->defaults.timeout_start_usec)); if (r < 0) return r; diff --git a/src/core/service.c b/src/core/service.c index 2a02279f56..818e2cbdd5 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -120,11 +120,11 @@ static void service_init(Unit *u) { assert(u); assert(u->load_state == UNIT_STUB); - s->timeout_start_usec = u->manager->default_timeout_start_usec; - s->timeout_stop_usec = u->manager->default_timeout_stop_usec; - s->timeout_abort_usec = u->manager->default_timeout_abort_usec; - s->timeout_abort_set = u->manager->default_timeout_abort_set; - s->restart_usec = u->manager->default_restart_usec; + s->timeout_start_usec = u->manager->defaults.timeout_start_usec; + s->timeout_stop_usec = u->manager->defaults.timeout_stop_usec; + s->timeout_abort_usec = u->manager->defaults.timeout_abort_usec; + s->timeout_abort_set = u->manager->defaults.timeout_abort_set; + s->restart_usec = u->manager->defaults.restart_usec; s->restart_max_delay_usec = USEC_INFINITY; s->runtime_max_usec = USEC_INFINITY; s->type = _SERVICE_TYPE_INVALID; @@ -777,10 +777,10 @@ static void service_fix_stdio(Service *s) { if (s->exec_context.std_error == EXEC_OUTPUT_INHERIT && s->exec_context.std_output == EXEC_OUTPUT_INHERIT) - s->exec_context.std_error = UNIT(s)->manager->default_std_error; + s->exec_context.std_error = UNIT(s)->manager->defaults.std_error; if (s->exec_context.std_output == EXEC_OUTPUT_INHERIT) - s->exec_context.std_output = UNIT(s)->manager->default_std_output; + s->exec_context.std_output = UNIT(s)->manager->defaults.std_output; } static int service_setup_bus_name(Service *s) { @@ -854,7 +854,7 @@ static int service_add_extras(Service *s) { * delegation is on, in that case it we assume the payload knows better what to do and can process * things in a more focused way. */ if (s->oom_policy < 0) - s->oom_policy = s->cgroup_context.delegate ? OOM_CONTINUE : UNIT(s)->manager->default_oom_policy; + s->oom_policy = s->cgroup_context.delegate ? OOM_CONTINUE : UNIT(s)->manager->defaults.oom_policy; /* Let the kernel do the killing if that's requested. */ s->cgroup_context.memory_oom_group = s->oom_policy == OOM_KILL; diff --git a/src/core/socket.c b/src/core/socket.c index 88e45c7385..0603b9337e 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -83,7 +83,7 @@ static void socket_init(Unit *u) { assert(u->load_state == UNIT_STUB); s->backlog = SOMAXCONN_DELUXE; - s->timeout_usec = u->manager->default_timeout_start_usec; + s->timeout_usec = u->manager->defaults.timeout_start_usec; s->directory_mode = 0755; s->socket_mode = 0666; @@ -94,8 +94,8 @@ static void socket_init(Unit *u) { s->ip_ttl = -1; s->mark = -1; - s->exec_context.std_output = u->manager->default_std_output; - s->exec_context.std_error = u->manager->default_std_error; + s->exec_context.std_output = u->manager->defaults.std_output; + s->exec_context.std_error = u->manager->defaults.std_error; s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID; diff --git a/src/core/swap.c b/src/core/swap.c index c35545e031..4772b5e9fc 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -139,10 +139,10 @@ static void swap_init(Unit *u) { assert(s); assert(UNIT(s)->load_state == UNIT_STUB); - s->timeout_usec = u->manager->default_timeout_start_usec; + s->timeout_usec = u->manager->defaults.timeout_start_usec; - s->exec_context.std_output = u->manager->default_std_output; - s->exec_context.std_error = u->manager->default_std_error; + s->exec_context.std_output = u->manager->defaults.std_output; + s->exec_context.std_error = u->manager->defaults.std_error; s->control_command_id = _SWAP_EXEC_COMMAND_INVALID; diff --git a/src/core/timer.c b/src/core/timer.c index 5a68f07e9d..2df75a1821 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -42,7 +42,7 @@ static void timer_init(Unit *u) { t->next_elapse_monotonic_or_boottime = USEC_INFINITY; t->next_elapse_realtime = USEC_INFINITY; - t->accuracy_usec = u->manager->default_timer_accuracy_usec; + t->accuracy_usec = u->manager->defaults.timer_accuracy_usec; t->remain_after_elapse = true; } diff --git a/src/core/unit.c b/src/core/unit.c index 34cbde690b..6f13348ebf 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -129,8 +129,15 @@ Unit* unit_new(Manager *m, size_t size) { u->last_section_private = -1; - u->start_ratelimit = (RateLimit) { m->default_start_limit_interval, m->default_start_limit_burst }; - u->auto_start_stop_ratelimit = (const RateLimit) { 10 * USEC_PER_SEC, 16 }; + u->start_ratelimit = (RateLimit) { + m->defaults.start_limit_interval, + m->defaults.start_limit_burst + }; + + u->auto_start_stop_ratelimit = (const RateLimit) { + 10 * USEC_PER_SEC, + 16 + }; return u; } @@ -177,26 +184,26 @@ static void unit_init(Unit *u) { * context, _before_ the rest of the settings have * been initialized */ - cc->cpu_accounting = u->manager->default_cpu_accounting; - cc->io_accounting = u->manager->default_io_accounting; - cc->blockio_accounting = u->manager->default_blockio_accounting; - cc->memory_accounting = u->manager->default_memory_accounting; - cc->tasks_accounting = u->manager->default_tasks_accounting; - cc->ip_accounting = u->manager->default_ip_accounting; + cc->cpu_accounting = u->manager->defaults.cpu_accounting; + cc->io_accounting = u->manager->defaults.io_accounting; + cc->blockio_accounting = u->manager->defaults.blockio_accounting; + cc->memory_accounting = u->manager->defaults.memory_accounting; + cc->tasks_accounting = u->manager->defaults.tasks_accounting; + cc->ip_accounting = u->manager->defaults.ip_accounting; if (u->type != UNIT_SLICE) - cc->tasks_max = u->manager->default_tasks_max; + cc->tasks_max = u->manager->defaults.tasks_max; - cc->memory_pressure_watch = u->manager->default_memory_pressure_watch; - cc->memory_pressure_threshold_usec = u->manager->default_memory_pressure_threshold_usec; + cc->memory_pressure_watch = u->manager->defaults.memory_pressure_watch; + cc->memory_pressure_threshold_usec = u->manager->defaults.memory_pressure_threshold_usec; } ec = unit_get_exec_context(u); if (ec) { exec_context_init(ec); - if (u->manager->default_oom_score_adjust_set) { - ec->oom_score_adjust = u->manager->default_oom_score_adjust; + if (u->manager->defaults.oom_score_adjust_set) { + ec->oom_score_adjust = u->manager->defaults.oom_score_adjust; ec->oom_score_adjust_set = true; } @@ -4277,8 +4284,8 @@ int unit_patch_contexts(Unit *u) { if (ec) { /* This only copies in the ones that need memory */ for (unsigned i = 0; i < _RLIMIT_MAX; i++) - if (u->manager->rlimit[i] && !ec->rlimit[i]) { - ec->rlimit[i] = newdup(struct rlimit, u->manager->rlimit[i], 1); + if (u->manager->defaults.rlimit[i] && !ec->rlimit[i]) { + ec->rlimit[i] = newdup(struct rlimit, u->manager->defaults.rlimit[i], 1); if (!ec->rlimit[i]) return -ENOMEM; } diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c index 63753b2494..9ab253a65c 100644 --- a/src/test/test-cgroup-mask.c +++ b/src/test/test-cgroup-mask.c @@ -53,12 +53,12 @@ TEST_RET(cgroup_mask, .sd_booted = true) { /* Turn off all kinds of default accounting, so that we can * verify the masks resulting of our configuration and nothing * else. */ - m->default_cpu_accounting = - m->default_memory_accounting = - m->default_blockio_accounting = - m->default_io_accounting = - m->default_tasks_accounting = false; - m->default_tasks_max = TASKS_MAX_UNSET; + m->defaults.cpu_accounting = + m->defaults.memory_accounting = + m->defaults.blockio_accounting = + m->defaults.io_accounting = + m->defaults.tasks_accounting = false; + m->defaults.tasks_max = TASKS_MAX_UNSET; assert_se(manager_startup(m, NULL, NULL, NULL) >= 0); diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 0be66c2c7b..68796ce1ac 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -1259,7 +1259,7 @@ static void run_tests(RuntimeScope scope, char **patterns) { return (void) log_tests_skipped_errno(r, "manager_new"); assert_se(r >= 0); - m->default_std_output = EXEC_OUTPUT_NULL; /* don't rely on host journald */ + m->defaults.std_output = EXEC_OUTPUT_NULL; /* don't rely on host journald */ assert_se(manager_startup(m, NULL, NULL, NULL) >= 0); /* Uncomment below if you want to make debugging logs stored to journal. */ |