1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

core: introduce unit_defaults_init() common initialization helper

THis adds a helper for initializing UnitDefaults to our default values.
Previously we'd do that differently in two different locations. Let's
unify this in one, and apply the exact same settings at both as
defaults.
This commit is contained in:
Lennart Poettering 2023-09-08 14:26:17 +02:00
parent bfb27b06da
commit ea09a416ed
3 changed files with 43 additions and 46 deletions

View File

@ -102,8 +102,6 @@
#include <sanitizer/lsan_interface.h>
#endif
#define DEFAULT_TASKS_MAX ((TasksMax) { 15U, 100U }) /* 15% */
static enum {
ACTION_RUN,
ACTION_HELP,
@ -2517,37 +2515,8 @@ static void reset_arguments(void) {
arg_service_watchdogs = true;
unit_defaults_done(&arg_defaults);
unit_defaults_init(&arg_defaults, arg_runtime_scope);
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;

View File

@ -112,6 +112,8 @@
/* How many units and jobs to process of the bus queue before returning to the event loop. */
#define MANAGER_BUS_MESSAGE_BUDGET 100U
#define DEFAULT_TASKS_MAX ((TasksMax) { 15U, 100U }) /* 15% */
static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static int manager_dispatch_cgroups_agent_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata);
@ -872,20 +874,6 @@ int manager_new(RuntimeScope runtime_scope, ManagerTestRunFlags test_run_flags,
.status_unit_format = STATUS_UNIT_FORMAT_DEFAULT,
.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,
@ -920,6 +908,8 @@ int manager_new(RuntimeScope runtime_scope, ManagerTestRunFlags test_run_flags,
},
};
unit_defaults_init(&m->defaults, runtime_scope);
#if ENABLE_EFI
if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0)
boot_timestamps(m->timestamps + MANAGER_TIMESTAMP_USERSPACE,
@ -4886,6 +4876,43 @@ ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s) {
return s;
}
void unit_defaults_init(UnitDefaults *defaults, RuntimeScope scope) {
assert(defaults);
assert(scope >= 0);
assert(scope < _RUNTIME_SCOPE_MAX);
*defaults = (UnitDefaults) {
.std_output = EXEC_OUTPUT_JOURNAL,
.std_error = EXEC_OUTPUT_INHERIT,
.restart_usec = DEFAULT_RESTART_USEC,
.timeout_start_usec = manager_default_timeout(scope),
.timeout_stop_usec = manager_default_timeout(scope),
.timeout_abort_usec = manager_default_timeout(scope),
.timeout_abort_set = false,
.device_timeout_usec = manager_default_timeout(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,
};
}
void unit_defaults_done(UnitDefaults *defaults) {
assert(defaults);

View File

@ -613,4 +613,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_init(UnitDefaults *defaults, RuntimeScope scope);
void unit_defaults_done(UnitDefaults *defaults);