1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

Merge pull request #29130 from poettering/unit-defaults

core: introduce UnitDefaults structure for unit defaults
This commit is contained in:
Luca Boccassi 2023-09-09 19:15:46 +01:00 committed by GitHub
commit fd0a804271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 373 additions and 334 deletions

View File

@ -362,6 +362,27 @@ void rlimit_free_all(struct rlimit **rl) {
free_many((void**) rl, _RLIMIT_MAX);
}
int rlimit_copy_all(struct rlimit* target[static _RLIMIT_MAX], struct rlimit* const source[static _RLIMIT_MAX]) {
struct rlimit* copy[_RLIMIT_MAX] = {};
assert(target);
assert(source);
for (int i = 0; i < _RLIMIT_MAX; i++) {
if (!source[i])
continue;
copy[i] = newdup(struct rlimit, source[i], 1);
if (!copy[i]) {
rlimit_free_all(copy);
return -ENOMEM;
}
}
memcpy(target, copy, sizeof(struct rlimit*) * _RLIMIT_MAX);
return 0;
}
int rlimit_nofile_bump(int limit) {
int r;

View File

@ -4,6 +4,7 @@
#include <sys/resource.h>
#include "macro.h"
#include "missing_resource.h"
const char *rlimit_to_string(int i) _const_;
int rlimit_from_string(const char *s) _pure_;
@ -17,6 +18,7 @@ int rlimit_parse(int resource, const char *val, struct rlimit *ret);
int rlimit_format(const struct rlimit *rl, char **ret);
int rlimit_copy_all(struct rlimit* target[static _RLIMIT_MAX], struct rlimit* const source[static _RLIMIT_MAX]);
void rlimit_free_all(struct rlimit **rl);
#define RLIMIT_MAKE_CONST(lim) ((struct rlimit) { lim, lim })

View File

@ -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),

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

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,
@ -130,16 +128,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 +138,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 +321,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 +332,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 +361,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 +563,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 +594,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 +604,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 +644,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,59 +724,35 @@ 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;
}
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) */
/* 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) */
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;
r = manager_set_unit_defaults(m, &arg_defaults);
if (r < 0)
log_warning_errno(r, "Failed to set manager defaults, ignoring: %m");
/* 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();
r = manager_default_environment(m);
if (r < 0)
log_warning_errno(r, "Failed to set manager default environment, ignoring: %m");
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);
(void) manager_default_environment(m);
(void) manager_transient_environment_add(m, arg_default_environment);
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) {
@ -904,7 +863,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 +871,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 +1479,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 +1764,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 +2419,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 +2457,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 +2465,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 +2481,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 +2513,10 @@ 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);
unit_defaults_init(&arg_defaults, arg_runtime_scope);
arg_runtime_watchdog = 0;
arg_reboot_watchdog = 10 * USEC_PER_MINUTE;
arg_kexec_watchdog = 0;
@ -2574,29 +2527,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 +2546,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 +2557,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 +2573,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,

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);
@ -806,12 +808,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,15 +874,6 @@ 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),
.original_log_level = -1,
.original_log_target = _LOG_TARGET_INVALID,
@ -909,17 +902,14 @@ 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,
},
};
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,
@ -1673,9 +1663,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);
@ -4119,33 +4107,68 @@ int manager_get_effective_environment(Manager *m, char ***ret) {
return 0;
}
int manager_set_default_smack_process_label(Manager *m, const char *label) {
assert(m);
int manager_set_unit_defaults(Manager *m, const UnitDefaults *defaults) {
_cleanup_free_ char *label = NULL;
struct rlimit *rlimit[_RLIMIT_MAX];
int r;
assert(m);
assert(defaults);
if (streq_ptr(defaults->smack_process_label, "/"))
label = NULL;
else {
const char *l = defaults->smack_process_label;
#ifdef SMACK_DEFAULT_PROCESS_LABEL
if (!label)
return free_and_strdup(&m->default_smack_process_label, SMACK_DEFAULT_PROCESS_LABEL);
if (!l)
l = SMACK_DEFAULT_PROCESS_LABEL;
#endif
if (streq_ptr(label, "/"))
return free_and_strdup(&m->default_smack_process_label, NULL);
return free_and_strdup(&m->default_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]);
if (!default_rlimit[i])
continue;
m->rlimit[i] = newdup(struct rlimit, default_rlimit[i], 1);
if (!m->rlimit[i])
return log_oom();
if (l) {
label = strdup(l);
if (!label)
return -ENOMEM;
} else
label = NULL;
}
r = rlimit_copy_all(rlimit, defaults->rlimit);
if (r < 0)
return r;
m->defaults.std_output = defaults->std_output;
m->defaults.std_error = defaults->std_error;
m->defaults.restart_usec = defaults->restart_usec;
m->defaults.timeout_start_usec = defaults->timeout_start_usec;
m->defaults.timeout_stop_usec = defaults->timeout_stop_usec;
m->defaults.timeout_abort_usec = defaults->timeout_abort_usec;
m->defaults.timeout_abort_set = defaults->timeout_abort_set;
m->defaults.device_timeout_usec = defaults->device_timeout_usec;
m->defaults.start_limit_interval = defaults->start_limit_interval;
m->defaults.start_limit_burst = defaults->start_limit_burst;
m->defaults.cpu_accounting = defaults->cpu_accounting;
m->defaults.memory_accounting = defaults->memory_accounting;
m->defaults.io_accounting = defaults->io_accounting;
m->defaults.blockio_accounting = defaults->blockio_accounting;
m->defaults.tasks_accounting = defaults->tasks_accounting;
m->defaults.ip_accounting = defaults->ip_accounting;
m->defaults.tasks_max = defaults->tasks_max;
m->defaults.timer_accuracy_usec = defaults->timer_accuracy_usec;
m->defaults.oom_policy = defaults->oom_policy;
m->defaults.oom_score_adjust = defaults->oom_score_adjust;
m->defaults.oom_score_adjust_set = defaults->oom_score_adjust_set;
m->defaults.memory_pressure_watch = defaults->memory_pressure_watch;
m->defaults.memory_pressure_threshold_usec = defaults->memory_pressure_threshold_usec;
free_and_replace(m->defaults.smack_process_label, label);
rlimit_free_all(m->defaults.rlimit);
memcpy(m->defaults.rlimit, rlimit, sizeof(struct rlimit*) * _RLIMIT_MAX);
return 0;
}
@ -4853,6 +4876,50 @@ 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);
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",

View File

@ -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)
@ -534,9 +537,7 @@ int manager_transient_environment_add(Manager *m, char **plus);
int manager_client_environment_modify(Manager *m, char **minus, char **plus);
int manager_get_effective_environment(Manager *m, char ***ret);
int manager_set_default_smack_process_label(Manager *m, const char *label);
int manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit);
int manager_set_unit_defaults(Manager *m, const UnitDefaults *defaults);
void manager_trigger_run_queue(Manager *m);
@ -611,3 +612,6 @@ 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);

View File

@ -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;

View File

@ -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;

View File

@ -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;
@ -786,10 +786,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) {
@ -863,7 +863,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;

View File

@ -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_pid = PIDREF_NULL;
s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;

View File

@ -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_pid = PIDREF_NULL;
s->control_command_id = _SWAP_EXEC_COMMAND_INVALID;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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. */