summaryrefslogtreecommitdiff
path: root/src/shared/bus-unit-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/bus-unit-util.c')
-rw-r--r--src/shared/bus-unit-util.c148
1 files changed, 53 insertions, 95 deletions
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index ace17da0c7..c9f352f796 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -5,11 +5,13 @@
#include "bus-unit-util.h"
#include "bus-util.h"
#include "cap-list.h"
+#include "cgroup-setup.h"
#include "cgroup-util.h"
#include "condition.h"
#include "cpu-set-util.h"
#include "escape.h"
#include "exec-util.h"
+#include "exit-status.h"
#include "hexdecoct.h"
#include "hostname-util.h"
#include "in-addr-util.h"
@@ -417,33 +419,42 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
int r;
if (STR_IN_SET(field, "DevicePolicy", "Slice"))
-
return bus_append_string(m, field, eq);
if (STR_IN_SET(field,
"CPUAccounting", "MemoryAccounting", "IOAccounting", "BlockIOAccounting",
"TasksAccounting", "IPAccounting"))
-
return bus_append_parse_boolean(m, field, eq);
if (STR_IN_SET(field, "CPUWeight", "StartupCPUWeight", "IOWeight", "StartupIOWeight"))
-
return bus_append_cg_weight_parse(m, field, eq);
if (STR_IN_SET(field, "CPUShares", "StartupCPUShares"))
-
return bus_append_cg_cpu_shares_parse(m, field, eq);
- if (STR_IN_SET(field, "BlockIOWeight", "StartupBlockIOWeight"))
+ if (STR_IN_SET(field, "AllowedCPUs", "AllowedMemoryNodes")) {
+ _cleanup_(cpu_set_reset) CPUSet cpuset = {};
+ _cleanup_free_ uint8_t *array = NULL;
+ size_t allocated;
+
+ r = parse_cpu_set(eq, &cpuset);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
+ r = cpu_set_to_dbus(&cpuset, &array, &allocated);
+ if (r < 0)
+ return log_error_errno(r, "Failed to serialize CPUSet: %m");
+
+ return bus_append_byte_array(m, field, array, allocated);
+ }
+
+ if (STR_IN_SET(field, "BlockIOWeight", "StartupBlockIOWeight"))
return bus_append_cg_blkio_weight_parse(m, field, eq);
if (streq(field, "DisableControllers"))
-
return bus_append_strv(m, "DisableControllers", eq, EXTRACT_UNQUOTE);
if (streq(field, "Delegate")) {
-
r = parse_boolean(eq);
if (r < 0)
return bus_append_strv(m, "DelegateControllers", eq, EXTRACT_UNQUOTE);
@@ -455,7 +466,15 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
return 1;
}
- if (STR_IN_SET(field, "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin", "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryLimit", "TasksMax")) {
+ if (STR_IN_SET(field, "MemoryMin",
+ "DefaultMemoryLow",
+ "DefaultMemoryMin",
+ "MemoryLow",
+ "MemoryHigh",
+ "MemoryMax",
+ "MemorySwapMax",
+ "MemoryLimit",
+ "TasksMax")) {
if (isempty(eq) || streq(eq, "infinity")) {
r = sd_bus_message_append(m, "(sv)", field, "t", CGROUP_LIMIT_MAX);
@@ -487,7 +506,6 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
}
if (streq(field, "CPUQuota")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY);
else {
@@ -522,7 +540,6 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
}
if (streq(field, "DeviceAllow")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", field, "a(ss)", 0);
else {
@@ -544,7 +561,6 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
}
if (cgroup_io_limit_type_from_string(field) >= 0 || STR_IN_SET(field, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", field, "a(st)", 0);
else {
@@ -578,7 +594,6 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
}
if (STR_IN_SET(field, "IODeviceWeight", "BlockIODeviceWeight")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", field, "a(st)", 0);
else {
@@ -774,17 +789,13 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
}
static int bus_append_automount_property(sd_bus_message *m, const char *field, const char *eq) {
-
if (streq(field, "Where"))
-
return bus_append_string(m, field, eq);
if (streq(field, "DirectoryMode"))
-
return bus_append_parse_mode(m, field, eq);
if (streq(field, "TimeoutIdleSec"))
-
return bus_append_parse_sec_rename(m, field, eq);
return 0;
@@ -800,7 +811,6 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
"WorkingDirectory", "RootDirectory", "SyslogIdentifier",
"ProtectSystem", "ProtectHome", "SELinuxContext", "RootImage",
"RuntimeDirectoryPreserve", "Personality", "KeyringMode", "NetworkNamespacePath"))
-
return bus_append_string(m, field, eq);
if (STR_IN_SET(field,
@@ -810,7 +820,6 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
"DynamicUser", "RemoveIPC", "ProtectKernelTunables", "ProtectKernelModules",
"ProtectControlGroups", "MountAPIVFS", "CPUSchedulingResetOnFork", "LockPersonality",
"ProtectHostname", "RestrictSUIDSGID"))
-
return bus_append_parse_boolean(m, field, eq);
if (STR_IN_SET(field,
@@ -818,73 +827,56 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
"ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths",
"RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory",
"SupplementaryGroups", "SystemCallArchitectures"))
-
return bus_append_strv(m, field, eq, EXTRACT_UNQUOTE);
if (STR_IN_SET(field, "SyslogLevel", "LogLevelMax"))
-
return bus_append_log_level_from_string(m, field, eq);
if (streq(field, "SyslogFacility"))
-
return bus_append_log_facility_unshifted_from_string(m, field, eq);
if (streq(field, "SecureBits"))
-
return bus_append_secure_bits_from_string(m, field, eq);
if (streq(field, "CPUSchedulingPolicy"))
-
return bus_append_sched_policy_from_string(m, field, eq);
if (STR_IN_SET(field, "CPUSchedulingPriority", "OOMScoreAdjust"))
-
return bus_append_safe_atoi(m, field, eq);
if (streq(field, "Nice"))
-
return bus_append_parse_nice(m, field, eq);
if (streq(field, "SystemCallErrorNumber"))
-
return bus_append_parse_errno(m, field, eq);
if (streq(field, "IOSchedulingClass"))
-
return bus_append_ioprio_class_from_string(m, field, eq);
if (streq(field, "IOSchedulingPriority"))
-
return bus_append_ioprio_parse_priority(m, field, eq);
if (STR_IN_SET(field,
"RuntimeDirectoryMode", "StateDirectoryMode", "CacheDirectoryMode",
"LogsDirectoryMode", "ConfigurationDirectoryMode", "UMask"))
-
return bus_append_parse_mode(m, field, eq);
if (streq(field, "TimerSlackNSec"))
-
return bus_append_parse_nsec(m, field, eq);
if (streq(field, "LogRateLimitIntervalSec"))
-
return bus_append_parse_sec_rename(m, field, eq);
if (streq(field, "LogRateLimitBurst"))
-
return bus_append_safe_atou(m, field, eq);
if (streq(field, "MountFlags"))
-
return bus_append_mount_propagation_flags_from_string(m, field, eq);
if (STR_IN_SET(field, "Environment", "UnsetEnvironment", "PassEnvironment"))
-
return bus_append_strv(m, field, eq, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE);
if (streq(field, "EnvironmentFile")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "EnvironmentFiles", "a(sb)", 0);
else
@@ -898,7 +890,6 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
}
if (streq(field, "LogExtraFields")) {
-
r = sd_bus_message_open_container(m, 'r', "sv");
if (r < 0)
return bus_log_create_error(r);
@@ -1336,17 +1327,13 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
}
static int bus_append_kill_property(sd_bus_message *m, const char *field, const char *eq) {
-
if (streq(field, "KillMode"))
-
return bus_append_string(m, field, eq);
if (STR_IN_SET(field, "SendSIGHUP", "SendSIGKILL"))
-
return bus_append_parse_boolean(m, field, eq);
- if (STR_IN_SET(field, "KillSignal", "FinalKillSignal", "WatchdogSignal"))
-
+ if (STR_IN_SET(field, "KillSignal", "RestartKillSignal", "FinalKillSignal", "WatchdogSignal"))
return bus_append_signal_from_string(m, field, eq);
return 0;
@@ -1355,19 +1342,15 @@ static int bus_append_kill_property(sd_bus_message *m, const char *field, const
static int bus_append_mount_property(sd_bus_message *m, const char *field, const char *eq) {
if (STR_IN_SET(field, "What", "Where", "Options", "Type"))
-
return bus_append_string(m, field, eq);
if (streq(field, "TimeoutSec"))
-
return bus_append_parse_sec_rename(m, field, eq);
if (streq(field, "DirectoryMode"))
-
return bus_append_parse_mode(m, field, eq);
if (STR_IN_SET(field, "SloppyOptions", "LazyUnmount", "ForceUnmount"))
-
return bus_append_parse_boolean(m, field, eq);
return 0;
@@ -1377,17 +1360,14 @@ static int bus_append_path_property(sd_bus_message *m, const char *field, const
int r;
if (streq(field, "MakeDirectory"))
-
return bus_append_parse_boolean(m, field, eq);
if (streq(field, "DirectoryMode"))
-
return bus_append_parse_mode(m, field, eq);
if (STR_IN_SET(field,
"PathExists", "PathExistsGlob", "PathChanged",
"PathModified", "DirectoryNotEmpty")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "Paths", "a(ss)", 0);
else
@@ -1419,19 +1399,15 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con
if (STR_IN_SET(field,
"PIDFile", "Type", "Restart", "BusName", "NotifyAccess",
"USBFunctionDescriptors", "USBFunctionStrings", "OOMPolicy"))
-
return bus_append_string(m, field, eq);
if (STR_IN_SET(field, "PermissionsStartOnly", "RootDirectoryStartOnly", "RemainAfterExit", "GuessMainPID"))
-
return bus_append_parse_boolean(m, field, eq);
if (STR_IN_SET(field, "RestartSec", "TimeoutStartSec", "TimeoutStopSec", "RuntimeMaxSec", "WatchdogSec"))
-
return bus_append_parse_sec_rename(m, field, eq);
if (streq(field, "TimeoutSec")) {
-
r = bus_append_parse_sec_rename(m, "TimeoutStartSec", eq);
if (r < 0)
return r;
@@ -1440,23 +1416,22 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con
}
if (streq(field, "FileDescriptorStoreMax"))
-
return bus_append_safe_atou(m, field, eq);
if (STR_IN_SET(field,
"ExecCondition", "ExecStartPre", "ExecStart", "ExecStartPost",
- "ExecStartPreEx", "ExecStartEx", "ExecStartPostEx",
- "ExecReload", "ExecStop", "ExecStopPost"))
+ "ExecConditionEx", "ExecStartPreEx", "ExecStartEx", "ExecStartPostEx",
+ "ExecReload", "ExecStop", "ExecStopPost",
+ "ExecReloadEx", "ExecStopEx", "ExecStopPostEx"))
return bus_append_exec_command(m, field, eq);
if (STR_IN_SET(field, "RestartPreventExitStatus", "RestartForceExitStatus", "SuccessExitStatus")) {
_cleanup_free_ int *status = NULL, *signal = NULL;
- size_t sz_status = 0, sz_signal = 0;
+ size_t n_status = 0, n_signal = 0;
const char *p;
for (p = eq;;) {
_cleanup_free_ char *word = NULL;
- int val;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r == 0)
@@ -1466,24 +1441,30 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con
if (r < 0)
return log_error_errno(r, "Invalid syntax in %s: %s", field, eq);
- r = safe_atoi(word, &val);
- if (r < 0) {
- val = signal_from_string(word);
- if (val < 0)
- return log_error_errno(r, "Invalid status or signal %s in %s: %m", word, field);
+ /* We need to call exit_status_from_string() first, because we want
+ * to parse numbers as exit statuses, not signals. */
- signal = reallocarray(signal, sz_signal + 1, sizeof(int));
- if (!signal)
- return log_oom();
+ r = exit_status_from_string(word);
+ if (r >= 0) {
+ assert(r >= 0 && r < 256);
- signal[sz_signal++] = val;
- } else {
- status = reallocarray(status, sz_status + 1, sizeof(int));
+ status = reallocarray(status, n_status + 1, sizeof(int));
if (!status)
return log_oom();
- status[sz_status++] = val;
- }
+ status[n_status++] = r;
+
+ } else if ((r = signal_from_string(word)) >= 0) {
+ signal = reallocarray(signal, n_signal + 1, sizeof(int));
+ if (!signal)
+ return log_oom();
+
+ signal[n_signal++] = r;
+
+ } else
+ /* original r from exit_status_to_string() */
+ return log_error_errno(r, "Invalid status or signal %s in %s: %m",
+ word, field);
}
r = sd_bus_message_open_container(m, SD_BUS_TYPE_STRUCT, "sv");
@@ -1502,11 +1483,11 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con
if (r < 0)
return bus_log_create_error(r);
- r = sd_bus_message_append_array(m, 'i', status, sz_status);
+ r = sd_bus_message_append_array(m, 'i', status, n_status * sizeof(int));
if (r < 0)
return bus_log_create_error(r);
- r = sd_bus_message_append_array(m, 'i', signal, sz_signal);
+ r = sd_bus_message_append_array(m, 'i', signal, n_signal * sizeof(int));
if (r < 0)
return bus_log_create_error(r);
@@ -1534,60 +1515,47 @@ static int bus_append_socket_property(sd_bus_message *m, const char *field, cons
if (STR_IN_SET(field,
"Accept", "Writable", "KeepAlive", "NoDelay", "FreeBind", "Transparent", "Broadcast",
"PassCredentials", "PassSecurity", "ReusePort", "RemoveOnStop", "SELinuxContextFromNet"))
-
return bus_append_parse_boolean(m, field, eq);
if (STR_IN_SET(field, "Priority", "IPTTL", "Mark"))
-
return bus_append_safe_atoi(m, field, eq);
if (streq(field, "IPTOS"))
-
return bus_append_ip_tos_from_string(m, field, eq);
if (STR_IN_SET(field, "Backlog", "MaxConnections", "MaxConnectionsPerSource", "KeepAliveProbes", "TriggerLimitBurst"))
-
return bus_append_safe_atou(m, field, eq);
if (STR_IN_SET(field, "SocketMode", "DirectoryMode"))
-
return bus_append_parse_mode(m, field, eq);
if (STR_IN_SET(field, "MessageQueueMaxMessages", "MessageQueueMessageSize"))
-
return bus_append_safe_atoi64(m, field, eq);
if (STR_IN_SET(field, "TimeoutSec", "KeepAliveTimeSec", "KeepAliveIntervalSec", "DeferAcceptSec", "TriggerLimitIntervalSec"))
-
return bus_append_parse_sec_rename(m, field, eq);
if (STR_IN_SET(field, "ReceiveBuffer", "SendBuffer", "PipeSize"))
-
return bus_append_parse_size(m, field, eq, 1024);
if (STR_IN_SET(field, "ExecStartPre", "ExecStartPost", "ExecReload", "ExecStopPost"))
-
return bus_append_exec_command(m, field, eq);
if (STR_IN_SET(field,
"SmackLabel", "SmackLabelIPIn", "SmackLabelIPOut", "TCPCongestion",
"BindToDevice", "BindIPv6Only", "FileDescriptorName",
"SocketUser", "SocketGroup"))
-
return bus_append_string(m, field, eq);
if (streq(field, "Symlinks"))
-
return bus_append_strv(m, field, eq, EXTRACT_UNQUOTE);
if (streq(field, "SocketProtocol"))
-
return bus_append_parse_ip_protocol(m, field, eq);
if (STR_IN_SET(field,
"ListenStream", "ListenDatagram", "ListenSequentialPacket", "ListenNetlink",
"ListenSpecial", "ListenMessageQueue", "ListenFIFO", "ListenUSBFunction")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "Listen", "a(ss)", 0);
else
@@ -1605,17 +1573,14 @@ static int bus_append_timer_property(sd_bus_message *m, const char *field, const
if (STR_IN_SET(field, "WakeSystem", "RemainAfterElapse", "Persistent",
"OnTimezoneChange", "OnClockChange"))
-
return bus_append_parse_boolean(m, field, eq);
if (STR_IN_SET(field, "AccuracySec", "RandomizedDelaySec"))
-
return bus_append_parse_sec_rename(m, field, eq);
if (STR_IN_SET(field,
"OnActiveSec", "OnBootSec", "OnStartupSec",
"OnUnitActiveSec","OnUnitInactiveSec")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "TimersMonotonic", "a(st)", 0);
else {
@@ -1633,7 +1598,6 @@ static int bus_append_timer_property(sd_bus_message *m, const char *field, const
}
if (streq(field, "OnCalendar")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "TimersCalendar", "a(ss)", 0);
else
@@ -1657,25 +1621,20 @@ static int bus_append_unit_property(sd_bus_message *m, const char *field, const
"JobTimeoutAction", "JobTimeoutRebootArgument",
"StartLimitAction", "FailureAction", "SuccessAction",
"RebootArgument", "CollectMode"))
-
return bus_append_string(m, field, eq);
if (STR_IN_SET(field,
"StopWhenUnneeded", "RefuseManualStart", "RefuseManualStop",
"AllowIsolate", "IgnoreOnIsolate", "DefaultDependencies"))
-
return bus_append_parse_boolean(m, field, eq);
if (STR_IN_SET(field, "JobTimeoutSec", "JobRunningTimeoutSec", "StartLimitIntervalSec"))
-
return bus_append_parse_sec_rename(m, field, eq);
if (streq(field, "StartLimitBurst"))
-
return bus_append_safe_atou(m, field, eq);
if (STR_IN_SET(field, "SuccessActionExitStatus", "FailureActionExitStatus")) {
-
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", field, "i", -1);
else {
@@ -1695,7 +1654,6 @@ static int bus_append_unit_property(sd_bus_message *m, const char *field, const
if (unit_dependency_from_string(field) >= 0 ||
STR_IN_SET(field, "Documentation", "RequiresMountsFor"))
-
return bus_append_strv(m, field, eq, EXTRACT_UNQUOTE);
t = condition_type_from_string(field);