Merge pull request #7759 from yuwata/dbus-api

DBus-API: add more options in transient units
This commit is contained in:
Lennart Poettering
2018-01-03 18:41:32 +01:00
committed by GitHub
32 changed files with 2071 additions and 1769 deletions

View File

@@ -10,12 +10,12 @@ ones currently available in transient units are prefixed with `✓`.
## Generic Unit Settings
Only the most important generic unit settings are available for transient units.
Most generic unit settings are available for transient units.
```
✓ Description=
Documentation=
SourcePath=
Documentation=
SourcePath=
✓ Requires=
✓ Requisite=
✓ Wants=
@@ -27,69 +27,70 @@ Only the most important generic unit settings are available for transient units.
✓ PropagatesReloadTo=
✓ ReloadPropagatedFrom=
✓ PartOf=
JoinsNamespaceOf=
RequiresMountsFor=
StopWhenUnneeded=
RefuseManualStart=
RefuseManualStop=
AllowIsolate=
JoinsNamespaceOf=
RequiresMountsFor=
StopWhenUnneeded=
RefuseManualStart=
RefuseManualStop=
AllowIsolate=
✓ DefaultDependencies=
OnFailureJobMode=
OnFailureIsolate=
IgnoreOnIsolate=
JobTimeoutSec=
JobRunningTimeoutSec=
JobTimeoutAction=
JobTimeoutRebootArgument=
StartLimitIntervalSec=SECONDS
StartLimitBurst=UNSIGNED
StartLimitAction=ACTION
OnFailureJobMode=
✓ IgnoreOnIsolate=
✓ JobTimeoutSec=
JobRunningTimeoutSec=
JobTimeoutAction=
JobTimeoutRebootArgument=
✓ StartLimitIntervalSec=SECONDS
StartLimitBurst=UNSIGNED
StartLimitAction=ACTION
✓ FailureAction=
✓ SuccessAction=
✓ AddRef=
RebootArgument=STRING
ConditionPathExists=
ConditionPathExistsGlob=
ConditionPathIsDirectory=
ConditionPathIsSymbolicLink=
ConditionPathIsMountPoint=
ConditionPathIsReadWrite=
ConditionDirectoryNotEmpty=
ConditionFileNotEmpty=
ConditionFileIsExecutable=
ConditionNeedsUpdate=
ConditionFirstBoot=
ConditionKernelCommandLine=
ConditionArchitecture=
ConditionVirtualization=
ConditionSecurity=
ConditionCapability=
ConditionHost=
ConditionACPower=
ConditionUser=
ConditionGroup=
ConditionControlGroupController=
AssertPathExists=
AssertPathExistsGlob=
AssertPathIsDirectory=
AssertPathIsSymbolicLink=
AssertPathIsMountPoint=
AssertPathIsReadWrite=
AssertDirectoryNotEmpty=
AssertFileNotEmpty=
AssertFileIsExecutable=
AssertNeedsUpdate=
AssertFirstBoot=
AssertKernelCommandLine=
AssertArchitecture=
AssertVirtualization=
AssertSecurity=
AssertCapability=
AssertHost=
AssertACPower=
AssertUser=
AssertGroup=
AssertControlGroupController=
RebootArgument=STRING
ConditionPathExists=
ConditionPathExistsGlob=
ConditionPathIsDirectory=
ConditionPathIsSymbolicLink=
ConditionPathIsMountPoint=
ConditionPathIsReadWrite=
ConditionDirectoryNotEmpty=
ConditionFileNotEmpty=
ConditionFileIsExecutable=
ConditionNeedsUpdate=
ConditionFirstBoot=
ConditionKernelCommandLine=
ConditionKernelVersion=
ConditionArchitecture=
ConditionVirtualization=
ConditionSecurity=
ConditionCapability=
ConditionHost=
ConditionACPower=
ConditionUser=
ConditionGroup=
✓ ConditionControlGroupController=
AssertPathExists=
AssertPathExistsGlob=
AssertPathIsDirectory=
AssertPathIsSymbolicLink=
AssertPathIsMountPoint=
AssertPathIsReadWrite=
AssertDirectoryNotEmpty=
AssertFileNotEmpty=
AssertFileIsExecutable=
AssertNeedsUpdate=
AssertFirstBoot=
AssertKernelCommandLine=
AssertKernelVersion=
AssertArchitecture=
AssertVirtualization=
AssertSecurity=
AssertCapability=
AssertHost=
AssertACPower=
AssertUser=
✓ AssertGroup=
✓ AssertControlGroupController=
✓ CollectMode=
```
@@ -256,63 +257,63 @@ All process killing settings are available for transient units:
## Service Unit Settings
Only the most important service settings are available for transient units.
Most service unit settings are available for transient units.
```
PIDFile=
PIDFile=
✓ ExecStartPre=
✓ ExecStart=
✓ ExecStartPost=
✓ ExecReload=
✓ ExecStop=
✓ ExecStopPost=
RestartSec=
TimeoutStartSec=
TimeoutStopSec=
TimeoutSec=
RestartSec=
TimeoutStartSec=
TimeoutStopSec=
TimeoutSec=
✓ RuntimeMaxSec=
WatchdogSec=
WatchdogSec=
✓ Type=
✓ Restart=
PermissionsStartOnly=
RootDirectoryStartOnly=
PermissionsStartOnly=
RootDirectoryStartOnly=
✓ RemainAfterExit=
GuessMainPID=
RestartPreventExitStatus=
RestartForceExitStatus=
SuccessExitStatus=
GuessMainPID=
RestartPreventExitStatus=
RestartForceExitStatus=
SuccessExitStatus=
✓ NonBlocking=
BusName=
BusName=
✓ FileDescriptorStoreMax=
✓ NotifyAccess=
Sockets=
USBFunctionDescriptors=
USBFunctionStrings=
USBFunctionDescriptors=
USBFunctionStrings=
```
## Mount Unit Settings
Only the most important mount unit settings are currently available to transient units:
All mount unit settings are available to transient units:
```
✓ What=
Where=
Where=
✓ Options=
✓ Type=
TimeoutSec=
DirectoryMode=
SloppyOptions=
LazyUnmount=
ForceUnmount=
TimeoutSec=
DirectoryMode=
SloppyOptions=
LazyUnmount=
ForceUnmount=
```
## Automount Unit Settings
Only one automount unit setting is currently available to transient units:
All automount unit setting is available to transient units:
```
Where=
DirectoryMode=
Where=
DirectoryMode=
✓ TimeoutIdleSec=
```
@@ -343,8 +344,11 @@ of their own beyond the generic unit and resource control settings.
## Scope Unit Settings
Scope units are fully supported as transient units (in fact they only exist as
such), but they have no settings of their own beyond the generic unit,
resource control, and process killing settings.
such).
```
✓ TimeoutStopSec=
```
## Socket Unit Settings

View File

@@ -100,8 +100,6 @@
late system shutdown should disable
<varname>DefaultDependencies=</varname> option.</para></listitem>
</itemizedlist>
<para></para>
</refsect1>
<refsect1>

View File

@@ -20,6 +20,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
/*
* MAX_ERRNO is defined as 4095 in linux/err.h
* We use the same value here.
@@ -28,3 +29,6 @@
const char *errno_to_name(int id);
int errno_from_name(const char *name);
static inline bool errno_is_valid(int n) {
return n > 0 && n <= ERRNO_MAX;
}

View File

@@ -283,7 +283,8 @@ int parse_errno(const char *t) {
if (r < 0)
return r;
if (e < 0 || e > ERRNO_MAX)
/* 0 is also allowed here */
if (!errno_is_valid(e) && e != 0)
return -ERANGE;
return e;

View File

@@ -137,6 +137,13 @@ static inline bool pid_is_valid(pid_t p) {
return p > 0;
}
static inline int sched_policy_to_string_alloc_with_check(int n, char **s) {
if (!sched_policy_is_valid(n))
return -EINVAL;
return sched_policy_to_string_alloc(n, s);
}
int ioprio_parse_priority(const char *s, int *ret);
pid_t getpid_cached(void);

View File

@@ -24,6 +24,14 @@
int secure_bits_to_string_alloc(int i, char **s);
int secure_bits_from_string(const char *s);
static inline bool secure_bits_is_valid(int i) {
return ((SECURE_ALL_BITS | SECURE_ALL_LOCKS) & i) == i;
}
static inline int secure_bits_to_string_alloc_with_check(int n, char **s) {
if (!secure_bits_is_valid(n))
return -EINVAL;
return secure_bits_to_string_alloc(n, s);
}

View File

@@ -55,3 +55,10 @@ static inline void block_signals_reset(sigset_t *ss) {
static inline bool SIGNAL_VALID(int signo) {
return signo > 0 && signo < _NSIG;
}
static inline const char* signal_to_string_with_check(int n) {
if (!SIGNAL_VALID(n))
return NULL;
return signal_to_string(n);
}

View File

@@ -821,6 +821,18 @@ static const char* const socket_address_bind_ipv6_only_table[_SOCKET_ADDRESS_BIN
DEFINE_STRING_TABLE_LOOKUP(socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
SocketAddressBindIPv6Only parse_socket_address_bind_ipv6_only_or_bool(const char *n) {
int r;
r = parse_boolean(n);
if (r > 0)
return SOCKET_ADDRESS_IPV6_ONLY;
if (r == 0)
return SOCKET_ADDRESS_BOTH;
return socket_address_bind_ipv6_only_from_string(n);
}
bool sockaddr_equal(const union sockaddr_union *a, const union sockaddr_union *b) {
assert(a);
assert(b);

View File

@@ -120,6 +120,7 @@ int getnameinfo_pretty(int fd, char **ret);
const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b) _const_;
SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s) _pure_;
SocketAddressBindIPv6Only parse_socket_address_bind_ipv6_only_or_bool(const char *s);
int netlink_family_to_string_alloc(int b, char **s);
int netlink_family_from_string(const char *s) _pure_;

View File

@@ -21,6 +21,7 @@
#include "automount.h"
#include "bus-util.h"
#include "dbus-automount.h"
#include "dbus-util.h"
#include "string-util.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, automount_result, AutomountResult);
@@ -41,7 +42,7 @@ static int bus_automount_set_transient_property(
UnitWriteFlags flags,
sd_bus_error *error) {
int r;
Unit *u = UNIT(a);
assert(a);
assert(name);
@@ -49,24 +50,16 @@ static int bus_automount_set_transient_property(
flags |= UNIT_PRIVATE;
if (streq(name, "TimeoutIdleUSec")) {
usec_t timeout_idle_usec;
if (streq(name, "Where"))
return bus_set_transient_path(u, name, &a->where, message, flags, error);
r = sd_bus_message_read(message, "t", &timeout_idle_usec);
if (r < 0)
return r;
if (streq(name, "TimeoutIdleUSec"))
return bus_set_transient_usec_fix_0(u, name, &a->timeout_idle_usec, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
char time[FORMAT_TIMESPAN_MAX];
if (streq(name, "DirectoryMode"))
return bus_set_transient_mode_t(u, name, &a->directory_mode, message, flags, error);
a->timeout_idle_usec = timeout_idle_usec;
unit_write_settingf(UNIT(a), flags, name, "TimeoutIdleSec=%s\n",
format_timespan(time, sizeof(time), timeout_idle_usec, USEC_PER_MSEC));
}
} else
return 0;
return 1;
return 0;
}
int bus_automount_set_property(

View File

@@ -28,6 +28,7 @@
#include "cgroup-util.h"
#include "cgroup.h"
#include "dbus-cgroup.h"
#include "dbus-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "path-util.h"
@@ -413,6 +414,41 @@ static int bus_cgroup_set_transient_property(
return 0;
}
static int bus_cgroup_set_boolean(
Unit *u,
const char *name,
bool *p,
CGroupMask mask,
sd_bus_message *message,
UnitWriteFlags flags,
sd_bus_error *error) {
int b, r;
assert(p);
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
*p = b;
unit_invalidate_cgroup(u, mask);
unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(b));
}
return 1;
}
static BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_weight, CGROUP_MASK_CPU, CGROUP_WEIGHT_IS_OK, CGROUP_WEIGHT_INVALID,);
static BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_shares, CGROUP_MASK_CPU, CGROUP_CPU_SHARES_IS_OK, CGROUP_CPU_SHARES_INVALID,);
static BUS_DEFINE_SET_CGROUP_WEIGHT(io_weight, CGROUP_MASK_IO, CGROUP_WEIGHT_IS_OK, CGROUP_WEIGHT_INVALID,);
static BUS_DEFINE_SET_CGROUP_WEIGHT(blockio_weight, CGROUP_MASK_BLKIO, CGROUP_BLKIO_WEIGHT_IS_OK, CGROUP_BLKIO_WEIGHT_INVALID,);
static BUS_DEFINE_SET_CGROUP_WEIGHT(memory, CGROUP_MASK_MEMORY, , CGROUP_LIMIT_MAX, "infinity");
static BUS_DEFINE_SET_CGROUP_WEIGHT(tasks_max, CGROUP_MASK_PIDS, , (uint64_t) -1, "infinity");
static BUS_DEFINE_SET_CGROUP_SCALE(memory, CGROUP_MASK_MEMORY, physical_memory_scale);
static BUS_DEFINE_SET_CGROUP_SCALE(tasks_max, CGROUP_MASK_PIDS, system_tasks_max_scale);
int bus_cgroup_set_property(
Unit *u,
CGroupContext *c,
@@ -431,74 +467,82 @@ int bus_cgroup_set_property(
flags |= UNIT_PRIVATE;
if (streq(name, "CPUAccounting")) {
int b;
if (streq(name, "CPUAccounting"))
return bus_cgroup_set_boolean(u, name, &c->cpu_accounting, CGROUP_MASK_CPUACCT|CGROUP_MASK_CPU, message, flags, error);
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (streq(name, "CPUWeight"))
return bus_cgroup_set_cpu_weight(u, name, &c->cpu_weight, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->cpu_accounting = b;
unit_invalidate_cgroup(u, CGROUP_MASK_CPUACCT|CGROUP_MASK_CPU);
unit_write_settingf(u, flags, name, "CPUAccounting=%s", yes_no(b));
}
if (streq(name, "StartupCPUWeight"))
return bus_cgroup_set_cpu_weight(u, name, &c->startup_cpu_weight, message, flags, error);
return 1;
if (streq(name, "CPUShares"))
return bus_cgroup_set_cpu_shares(u, name, &c->cpu_shares, message, flags, error);
} else if (STR_IN_SET(name, "CPUWeight", "StartupCPUWeight")) {
uint64_t weight;
if (streq(name, "StartupCPUShares"))
return bus_cgroup_set_cpu_shares(u, name, &c->startup_cpu_shares, message, flags, error);
r = sd_bus_message_read(message, "t", &weight);
if (r < 0)
return r;
if (streq(name, "IOAccounting"))
return bus_cgroup_set_boolean(u, name, &c->io_accounting, CGROUP_MASK_IO, message, flags, error);
if (!CGROUP_WEIGHT_IS_OK(weight))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= value out of range", name);
if (streq(name, "IOWeight"))
return bus_cgroup_set_io_weight(u, name, &c->io_weight, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "CPUWeight"))
c->cpu_weight = weight;
else /* "StartupCPUWeight" */
c->startup_cpu_weight = weight;
if (streq(name, "StartupIOWeight"))
return bus_cgroup_set_io_weight(u, name, &c->startup_io_weight, message, flags, error);
unit_invalidate_cgroup(u, CGROUP_MASK_CPU);
if (streq(name, "BlockIOAccounting"))
return bus_cgroup_set_boolean(u, name, &c->blockio_accounting, CGROUP_MASK_BLKIO, message, flags, error);
if (weight == CGROUP_WEIGHT_INVALID)
unit_write_settingf(u, flags, name, "%s=", name);
else
unit_write_settingf(u, flags, name, "%s=%" PRIu64, name, weight);
}
if (streq(name, "BlockIOWeight"))
return bus_cgroup_set_blockio_weight(u, name, &c->blockio_weight, message, flags, error);
return 1;
if (streq(name, "StartupBlockIOWeight"))
return bus_cgroup_set_blockio_weight(u, name, &c->startup_blockio_weight, message, flags, error);
} else if (STR_IN_SET(name, "CPUShares", "StartupCPUShares")) {
uint64_t shares;
if (streq(name, "MemoryAccounting"))
return bus_cgroup_set_boolean(u, name, &c->memory_accounting, CGROUP_MASK_MEMORY, message, flags, error);
r = sd_bus_message_read(message, "t", &shares);
if (r < 0)
return r;
if (streq(name, "MemoryLow"))
return bus_cgroup_set_memory(u, name, &c->memory_low, message, flags, error);
if (!CGROUP_CPU_SHARES_IS_OK(shares))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= value out of range", name);
if (streq(name, "MemoryHigh"))
return bus_cgroup_set_memory(u, name, &c->memory_high, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "CPUShares"))
c->cpu_shares = shares;
else /* "StartupCPUShares" */
c->startup_cpu_shares = shares;
if (streq(name, "MemorySwapMax"))
return bus_cgroup_set_memory(u, name, &c->memory_swap_max, message, flags, error);
unit_invalidate_cgroup(u, CGROUP_MASK_CPU);
if (streq(name, "MemoryMax"))
return bus_cgroup_set_memory(u, name, &c->memory_max, message, flags, error);
if (shares == CGROUP_CPU_SHARES_INVALID)
unit_write_settingf(u, flags, name, "%s=", name);
else
unit_write_settingf(u, flags, name, "%s=%" PRIu64, name, shares);
}
if (streq(name, "MemoryLimit"))
return bus_cgroup_set_memory(u, name, &c->memory_limit, message, flags, error);
return 1;
if (streq(name, "MemoryLowScale"))
return bus_cgroup_set_memory_scale(u, name, &c->memory_low, message, flags, error);
} else if (streq(name, "CPUQuotaPerSecUSec")) {
if (streq(name, "MemoryHighScale"))
return bus_cgroup_set_memory_scale(u, name, &c->memory_high, message, flags, error);
if (streq(name, "MemorySwapMaxScale"))
return bus_cgroup_set_memory_scale(u, name, &c->memory_swap_max, message, flags, error);
if (streq(name, "MemoryMaxScale"))
return bus_cgroup_set_memory_scale(u, name, &c->memory_max, message, flags, error);
if (streq(name, "MemoryLimitScale"))
return bus_cgroup_set_memory_scale(u, name, &c->memory_limit, message, flags, error);
if (streq(name, "TasksAccountingScale"))
return bus_cgroup_set_boolean(u, name, &c->tasks_accounting, CGROUP_MASK_PIDS, message, flags, error);
if (streq(name, "TasksMax"))
return bus_cgroup_set_tasks_max(u, name, &c->tasks_max, message, flags, error);
if (streq(name, "TasksMaxScale"))
return bus_cgroup_set_tasks_max_scale(u, name, &c->tasks_max, message, flags, error);
if (streq(name, "CPUQuotaPerSecUSec")) {
uint64_t u64;
r = sd_bus_message_read(message, "t", &u64);
@@ -524,47 +568,6 @@ int bus_cgroup_set_property(
return 1;
} else if (streq(name, "IOAccounting")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->io_accounting = b;
unit_invalidate_cgroup(u, CGROUP_MASK_IO);
unit_write_settingf(u, flags, name, "IOAccounting=%s", yes_no(b));
}
return 1;
} else if (STR_IN_SET(name, "IOWeight", "StartupIOWeight")) {
uint64_t weight;
r = sd_bus_message_read(message, "t", &weight);
if (r < 0)
return r;
if (!CGROUP_WEIGHT_IS_OK(weight))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= value out of range", name);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "IOWeight"))
c->io_weight = weight;
else /* "StartupIOWeight" */
c->startup_io_weight = weight;
unit_invalidate_cgroup(u, CGROUP_MASK_IO);
if (weight == CGROUP_WEIGHT_INVALID)
unit_write_settingf(u, flags, name, "%s=", name);
else
unit_write_settingf(u, flags, name, "%s=%" PRIu64, name, weight);
}
return 1;
} else if ((iol_type = cgroup_io_limit_type_from_string(name)) >= 0) {
const char *path;
unsigned n = 0;
@@ -691,7 +694,7 @@ int bus_cgroup_set_property(
free(a);
return -ENOMEM;
}
LIST_PREPEND(device_weights,c->io_device_weights, a);
LIST_PREPEND(device_weights, c->io_device_weights, a);
}
a->weight = weight;
@@ -735,47 +738,6 @@ int bus_cgroup_set_property(
return 1;
} else if (streq(name, "BlockIOAccounting")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->blockio_accounting = b;
unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO);
unit_write_settingf(u, flags, name, "BlockIOAccounting=%s", yes_no(b));
}
return 1;
} else if (STR_IN_SET(name, "BlockIOWeight", "StartupBlockIOWeight")) {
uint64_t weight;
r = sd_bus_message_read(message, "t", &weight);
if (r < 0)
return r;
if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= value out of range", name);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "BlockIOWeight"))
c->blockio_weight = weight;
else /* "StartupBlockIOWeight" */
c->startup_blockio_weight = weight;
unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO);
if (weight == CGROUP_BLKIO_WEIGHT_INVALID)
unit_write_settingf(u, flags, name, "%s=", name);
else
unit_write_settingf(u, flags, name, "%s=%" PRIu64, name, weight);
}
return 1;
} else if (STR_IN_SET(name, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) {
const char *path;
bool read = true;
@@ -918,7 +880,7 @@ int bus_cgroup_set_property(
free(a);
return -ENOMEM;
}
LIST_PREPEND(device_weights,c->blockio_device_weights, a);
LIST_PREPEND(device_weights, c->blockio_device_weights, a);
}
a->weight = weight;
@@ -963,89 +925,6 @@ int bus_cgroup_set_property(
return 1;
} else if (streq(name, "MemoryAccounting")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->memory_accounting = b;
unit_invalidate_cgroup(u, CGROUP_MASK_MEMORY);
unit_write_settingf(u, flags, name, "MemoryAccounting=%s", yes_no(b));
}
return 1;
} else if (STR_IN_SET(name, "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryLimit")) {
uint64_t v;
r = sd_bus_message_read(message, "t", &v);
if (r < 0)
return r;
if (v <= 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is too small", name);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "MemoryLow"))
c->memory_low = v;
else if (streq(name, "MemoryHigh"))
c->memory_high = v;
else if (streq(name, "MemorySwapMax"))
c->memory_swap_max = v;
else if (streq(name, "MemoryMax"))
c->memory_max = v;
else /* "MemoryLimit" */
c->memory_limit = v;
unit_invalidate_cgroup(u, CGROUP_MASK_MEMORY);
if (v == CGROUP_LIMIT_MAX)
unit_write_settingf(u, flags, name, "%s=infinity", name);
else
unit_write_settingf(u, flags, name, "%s=%" PRIu64, name, v);
}
return 1;
} else if (STR_IN_SET(name, "MemoryLowScale", "MemoryHighScale", "MemoryMaxScale", "MemorySwapMaxScale", "MemoryLimitScale")) {
uint32_t raw;
uint64_t v;
r = sd_bus_message_read(message, "u", &raw);
if (r < 0)
return r;
v = physical_memory_scale(raw, UINT32_MAX);
if (v <= 0 || v == UINT64_MAX)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is out of range", name);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
const char *e;
/* Chop off suffix */
assert_se(e = endswith(name, "Scale"));
name = strndupa(name, e - name);
if (streq(name, "MemoryLow"))
c->memory_low = v;
else if (streq(name, "MemoryHigh"))
c->memory_high = v;
else if (streq(name, "MemorySwapMax"))
c->memory_swap_max = v;
else if (streq(name, "MemoryMax"))
c->memory_max = v;
else /* "MemoryLimit" */
c->memory_limit = v;
unit_invalidate_cgroup(u, CGROUP_MASK_MEMORY);
unit_write_settingf(u, flags, name, "%s=%" PRIu32 "%%", name,
(uint32_t) (DIV_ROUND_UP((uint64_t) raw * 100U, (uint64_t) UINT32_MAX)));
}
return 1;
} else if (streq(name, "DevicePolicy")) {
const char *policy;
CGroupDevicePolicy p;
@@ -1156,63 +1035,6 @@ int bus_cgroup_set_property(
return 1;
} else if (streq(name, "TasksAccounting")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->tasks_accounting = b;
unit_invalidate_cgroup(u, CGROUP_MASK_PIDS);
unit_write_settingf(u, flags, name, "TasksAccounting=%s", yes_no(b));
}
return 1;
} else if (streq(name, "TasksMax")) {
uint64_t limit;
r = sd_bus_message_read(message, "t", &limit);
if (r < 0)
return r;
if (limit <= 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is too small", name);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->tasks_max = limit;
unit_invalidate_cgroup(u, CGROUP_MASK_PIDS);
if (limit == (uint64_t) -1)
unit_write_setting(u, flags, name, "TasksMax=infinity");
else
unit_write_settingf(u, flags, name, "TasksMax=%" PRIu64, limit);
}
return 1;
} else if (streq(name, "TasksMaxScale")) {
uint64_t limit;
uint32_t raw;
r = sd_bus_message_read(message, "u", &raw);
if (r < 0)
return r;
limit = system_tasks_max_scale(raw, UINT32_MAX);
if (limit <= 0 || limit >= UINT64_MAX)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= is out of range", name);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->tasks_max = limit;
unit_invalidate_cgroup(u, CGROUP_MASK_PIDS);
unit_write_settingf(u, flags, name, "TasksMax=%" PRIu32 "%%",
(uint32_t) (DIV_ROUND_UP((uint64_t) raw * 100U, (uint64_t) UINT32_MAX)));
}
return 1;
} else if (streq(name, "IPAccounting")) {
int b;

File diff suppressed because it is too large Load Diff

View File

@@ -44,4 +44,4 @@ int bus_property_get_exec_command(sd_bus *bus, const char *path, const char *int
int bus_property_get_exec_command_list(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error);
int bus_exec_context_set_transient_property(Unit *u, ExecContext *c, const char *name, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
int bus_exec_command_set_transient_property(Unit *u, const char *name, ExecCommand **exec_command, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
int bus_set_transient_exec_command(Unit *u, const char *name, ExecCommand **exec_command, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);

View File

@@ -20,6 +20,7 @@
#include "bus-util.h"
#include "dbus-kill.h"
#include "dbus-util.h"
#include "kill.h"
#include "signal-util.h"
@@ -34,6 +35,9 @@ const sd_bus_vtable bus_kill_vtable[] = {
SD_BUS_VTABLE_END
};
static BUS_DEFINE_SET_TRANSIENT_PARSE(kill_mode, KillMode, kill_mode_from_string);
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(kill_signal, "i", int32_t, int, "%" PRIi32, signal_to_string_with_check);
int bus_kill_context_set_transient_property(
Unit *u,
KillContext *c,
@@ -42,8 +46,6 @@ int bus_kill_context_set_transient_property(
UnitWriteFlags flags,
sd_bus_error *error) {
int r;
assert(u);
assert(c);
assert(name);
@@ -51,75 +53,17 @@ int bus_kill_context_set_transient_property(
flags |= UNIT_PRIVATE;
if (streq(name, "KillMode")) {
const char *m;
KillMode k;
if (streq(name, "KillMode"))
return bus_set_transient_kill_mode(u, name, &c->kill_mode, message, flags, error);
r = sd_bus_message_read(message, "s", &m);
if (r < 0)
return r;
if (streq(name, "SendSIGHUP"))
return bus_set_transient_bool(u, name, &c->send_sighup, message, flags, error);
k = kill_mode_from_string(m);
if (k < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Kill mode '%s' not known.", m);
if (streq(name, "SendSIGKILL"))
return bus_set_transient_bool(u, name, &c->send_sigkill, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->kill_mode = k;
unit_write_settingf(u, flags, name, "KillMode=%s", kill_mode_to_string(k));
}
return 1;
} else if (streq(name, "KillSignal")) {
int sig;
r = sd_bus_message_read(message, "i", &sig);
if (r < 0)
return r;
if (!SIGNAL_VALID(sig))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal %i out of range", sig);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->kill_signal = sig;
unit_write_settingf(u, flags, name, "KillSignal=%s", signal_to_string(sig));
}
return 1;
} else if (streq(name, "SendSIGHUP")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->send_sighup = b;
unit_write_settingf(u, flags, name, "SendSIGHUP=%s", yes_no(b));
}
return 1;
} else if (streq(name, "SendSIGKILL")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->send_sigkill = b;
unit_write_settingf(u, flags, name, "SendSIGKILL=%s", yes_no(b));
}
return 1;
}
if (streq(name, "KillSignal"))
return bus_set_transient_kill_signal(u, name, &c->kill_signal, message, flags, error);
return 0;
}

View File

@@ -2423,8 +2423,10 @@ const sd_bus_vtable bus_manager_vtable[] = {
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("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, default_restart_usec), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), /* obsolete alias name */
SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, default_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),

View File

@@ -23,6 +23,7 @@
#include "dbus-execute.h"
#include "dbus-kill.h"
#include "dbus-mount.h"
#include "dbus-util.h"
#include "mount.h"
#include "string-util.h"
#include "unit.h"
@@ -129,9 +130,7 @@ static int bus_mount_set_transient_property(
UnitWriteFlags flags,
sd_bus_error *error) {
const char *new_property;
char **property;
int r;
Unit *u = UNIT(m);
assert(m);
assert(name);
@@ -139,29 +138,34 @@ static int bus_mount_set_transient_property(
flags |= UNIT_PRIVATE;
if (streq(name, "Where"))
return bus_set_transient_path(u, name, &m->where, message, flags, error);
if (streq(name, "What"))
property = &m->parameters_fragment.what;
else if (streq(name, "Options"))
property = &m->parameters_fragment.options;
else if (streq(name, "Type"))
property = &m->parameters_fragment.fstype;
else
return 0;
return bus_set_transient_string(u, name, &m->parameters_fragment.what, message, flags, error);
r = sd_bus_message_read(message, "s", &new_property);
if (r < 0)
return r;
if (streq(name, "Options"))
return bus_set_transient_string(u, name, &m->parameters_fragment.options, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "Type"))
return bus_set_transient_string(u, name, &m->parameters_fragment.fstype, message, flags, error);
r = free_and_strdup(property, new_property);
if (r < 0)
return r;
if (streq(name, "TimeoutUSec"))
return bus_set_transient_usec_fix_0(u, name, &m->timeout_usec, message, flags, error);
unit_write_settingf(UNIT(m), flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, new_property);
}
if (streq(name, "DirectoryMode"))
return bus_set_transient_mode_t(u, name, &m->directory_mode, message, flags, error);
return 1;
if (streq(name, "SloppyOptions"))
return bus_set_transient_bool(u, name, &m->sloppy_options, message, flags, error);
if (streq(name, "LazyUnmount"))
return bus_set_transient_bool(u, name, &m->lazy_unmount, message, flags, error);
if (streq(name, "ForceUnmount"))
return bus_set_transient_bool(u, name, &m->force_unmount, message, flags, error);
return 0;
}
int bus_mount_set_property(

View File

@@ -21,6 +21,7 @@
#include "alloc-util.h"
#include "bus-util.h"
#include "dbus-path.h"
#include "dbus-util.h"
#include "list.h"
#include "path.h"
#include "path-util.h"
@@ -105,30 +106,38 @@ static int bus_path_set_transient_property(
flags |= UNIT_PRIVATE;
if (STR_IN_SET(name, "PathExists", "PathExistsGlob", "PathChanged", "PathModified", "DirectoryNotEmpty")) {
const char *str;
PathType b;
if (streq(name, "MakeDirectory"))
return bus_set_transient_bool(u, name, &p->make_directory, message, flags, error);
b = path_type_from_string(name);
if (b < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown path type");
if (streq(name, "DirectoryMode"))
return bus_set_transient_mode_t(u, name, &p->directory_mode, message, flags, error);
r = sd_bus_message_read(message, "s", &str);
if (streq(name, "Paths")) {
const char *type_name, *path;
bool empty = true;
r = sd_bus_message_enter_container(message, 'a', "(ss)");
if (r < 0)
return r;
if (!isempty(str) && !path_is_absolute(str))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path is not absolute");
while ((r = sd_bus_message_read(message, "(ss)", &type_name, &path)) > 0) {
PathType t;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (isempty(str)) {
path_free_specs(p);
unit_write_settingf(u, flags, name, "%s=", name);
} else {
t = path_type_from_string(type_name);
if (t < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown path type: %s", type_name);
if (isempty(path))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path in %s is empty", type_name);
if (!path_is_absolute(path))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path in %s is not absolute: %s", type_name, path);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
_cleanup_free_ char *k;
PathSpec *s;
k = strdup(str);
k = strdup(path);
if (!k)
return -ENOMEM;
@@ -139,48 +148,29 @@ static int bus_path_set_transient_property(
s->unit = u;
s->path = path_kill_slashes(k);
k = NULL;
s->type = b;
s->type = t;
s->inotify_fd = -1;
LIST_PREPEND(spec, p->specs, s);
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, str);
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", type_name, path);
}
empty = false;
}
return 1;
} else if (streq(name, "MakeDirectory")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
p->make_directory = b;
unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(b));
}
return 1;
} else if (streq(name, "DirectoryMode")) {
mode_t m;
r = sd_bus_message_read(message, "u", &m);
r = sd_bus_message_exit_container(message);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
p->directory_mode = m;
unit_write_settingf(u, flags, name, "%s=%040o", name, m);
if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) {
path_free_specs(p);
unit_write_settingf(u, flags, name, "PathExists=");
}
return 1;
} else if (streq(name, "Unit")) {
/* not implemented yet */
return 0;
}
return 0;

View File

@@ -26,6 +26,7 @@
#include "dbus-kill.h"
#include "dbus-scope.h"
#include "dbus-unit.h"
#include "dbus-util.h"
#include "dbus.h"
#include "scope.h"
#include "selinux-access.h"
@@ -84,6 +85,9 @@ static int bus_scope_set_transient_property(
flags |= UNIT_PRIVATE;
if (streq(name, "TimeoutStopUSec"))
return bus_set_transient_usec(UNIT(s), name, &s->timeout_stop_usec, message, flags, error);
if (streq(name, "PIDs")) {
unsigned n = 0;
uint32_t pid;
@@ -138,21 +142,6 @@ static int bus_scope_set_transient_property(
return r;
}
return 1;
} else if (streq(name, "TimeoutStopUSec")) {
uint64_t t;
r = sd_bus_message_read(message, "t", &t);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->timeout_stop_usec = t;
unit_write_settingf(UNIT(s), flags, name, "TimeoutStopSec=" USEC_FMT "us", t);
}
return 1;
}

View File

@@ -22,15 +22,20 @@
#include "alloc-util.h"
#include "async.h"
#include "bus-internal.h"
#include "bus-util.h"
#include "dbus-cgroup.h"
#include "dbus-execute.h"
#include "dbus-kill.h"
#include "dbus-service.h"
#include "dbus-util.h"
#include "exit-status.h"
#include "fd-util.h"
#include "fileio.h"
#include "parse-util.h"
#include "path-util.h"
#include "service.h"
#include "signal-util.h"
#include "string-util.h"
#include "strv.h"
#include "unit.h"
@@ -41,6 +46,71 @@ static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_restart, service_restart, Servi
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_notify_access, notify_access, NotifyAccess);
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_emergency_action, emergency_action, EmergencyAction);
static int property_get_exit_status_set(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
ExitStatusSet *status_set = userdata;
Iterator i;
void *id;
int r;
assert(bus);
assert(reply);
assert(status_set);
r = sd_bus_message_open_container(reply, 'r', "aiai");
if (r < 0)
return r;
r = sd_bus_message_open_container(reply, 'a', "i");
if (r < 0)
return r;
SET_FOREACH(id, status_set->status, i) {
int val = PTR_TO_INT(id);
if (val < 0 || val > 255)
continue;
r = sd_bus_message_append_basic(reply, 'i', &val);
if (r < 0)
return r;
}
r = sd_bus_message_close_container(reply);
if (r < 0)
return r;
r = sd_bus_message_open_container(reply, 'a', "i");
if (r < 0)
return r;
SET_FOREACH(id, status_set->signal, i) {
int val = PTR_TO_INT(id);
const char *str;
str = signal_to_string(val);
if (!str)
continue;
r = sd_bus_message_append_basic(reply, 'i', &val);
if (r < 0)
return r;
}
r = sd_bus_message_close_container(reply);
if (r < 0)
return r;
return sd_bus_message_close_container(reply);
}
const sd_bus_vtable bus_service_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Service, type), SD_BUS_VTABLE_PROPERTY_CONST),
@@ -57,6 +127,9 @@ const sd_bus_vtable bus_service_vtable[] = {
SD_BUS_PROPERTY("RootDirectoryStartOnly", "b", bus_property_get_bool, offsetof(Service, root_directory_start_only), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RemainAfterExit", "b", bus_property_get_bool, offsetof(Service, remain_after_exit), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("GuessMainPID", "b", bus_property_get_bool, offsetof(Service, guess_main_pid), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RestartPreventExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, restart_prevent_status), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RestartForceExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, restart_force_status), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("SuccessExitStatus", "(aiai)", property_get_exit_status_set, offsetof(Service, success_status), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("MainPID", "u", bus_property_get_pid, offsetof(Service, main_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Service, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("BusName", "s", NULL, offsetof(Service, bus_name), SD_BUS_VTABLE_PROPERTY_CONST),
@@ -88,6 +161,117 @@ const sd_bus_vtable bus_service_vtable[] = {
SD_BUS_VTABLE_END
};
static int bus_set_transient_exit_status(
Unit *u,
const char *name,
ExitStatusSet *status_set,
sd_bus_message *message,
UnitWriteFlags flags,
sd_bus_error *error) {
const int *status, *signal;
size_t sz_status, sz_signal, i;
int r;
r = sd_bus_message_enter_container(message, 'r', "aiai");
if (r < 0)
return r;
r = sd_bus_message_read_array(message, 'i', (const void **) &status, &sz_status);
if (r < 0)
return r;
r = sd_bus_message_read_array(message, 'i', (const void **) &signal, &sz_signal);
if (r < 0)
return r;
r = sd_bus_message_exit_container(message);
if (r < 0)
return r;
if (sz_status == 0 && sz_signal == 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) {
exit_status_set_free(status_set);
unit_write_settingf(u, flags, name, "%s=", name);
return 1;
}
for (i = 0; i < sz_status; i++) {
if (status[i] < 0 || status[i] > 255)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid status code in %s: %i", name, status[i]);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
r = set_ensure_allocated(&status_set->status, NULL);
if (r < 0)
return r;
r = set_put(status_set->status, INT_TO_PTR(status[i]));
if (r < 0)
return r;
unit_write_settingf(u, flags, name, "%s=%i", name, status[i]);
}
}
for (i = 0; i < sz_signal; i++) {
const char *str;
str = signal_to_string(signal[i]);
if (!str)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal in %s: %i", name, signal[i]);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
r = set_ensure_allocated(&status_set->signal, NULL);
if (r < 0)
return r;
r = set_put(status_set->signal, INT_TO_PTR(signal[i]));
if (r < 0)
return r;
unit_write_settingf(u, flags, name, "%s=%s", name, str);
}
}
return 1;
}
static int bus_set_transient_std_fd(
Unit *u,
const char *name,
int *p,
bool *b,
sd_bus_message *message,
UnitWriteFlags flags,
sd_bus_error *error) {
int fd, r;
assert(p);
assert(b);
r = sd_bus_message_read(message, "h", &fd);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
int copy;
copy = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (copy < 0)
return -errno;
asynchronous_close(*p);
*p = copy;
*b = true;
}
return 1;
}
static BUS_DEFINE_SET_TRANSIENT_PARSE(notify_access, NotifyAccess, notify_access_from_string);
static BUS_DEFINE_SET_TRANSIENT_PARSE(service_type, ServiceType, service_type_from_string);
static BUS_DEFINE_SET_TRANSIENT_PARSE(service_restart, ServiceRestart, service_restart_from_string);
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(bus_name, service_name_is_valid);
static int bus_service_set_transient_property(
Service *s,
const char *name,
@@ -95,6 +279,7 @@ static int bus_service_set_transient_property(
UnitWriteFlags flags,
sd_bus_error *error) {
Unit *u = UNIT(s);
ServiceExecCommand ci;
int r;
@@ -104,143 +289,82 @@ static int bus_service_set_transient_property(
flags |= UNIT_PRIVATE;
if (streq(name, "RemainAfterExit")) {
int b;
if (streq(name, "PermissionsStartOnly"))
return bus_set_transient_bool(u, name, &s->permissions_start_only, message, flags, error);
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (streq(name, "RootDirectoryStartOnly"))
return bus_set_transient_bool(u, name, &s->root_directory_start_only, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->remain_after_exit = b;
unit_write_settingf(UNIT(s), flags, name, "RemainAfterExit=%s", yes_no(b));
}
if (streq(name, "RemainAfterExit"))
return bus_set_transient_bool(u, name, &s->remain_after_exit, message, flags, error);
return 1;
if (streq(name, "GuessMainPID"))
return bus_set_transient_bool(u, name, &s->guess_main_pid, message, flags, error);
} else if (streq(name, "Type")) {
const char *t;
ServiceType k;
if (streq(name, "Type"))
return bus_set_transient_service_type(u, name, &s->type, message, flags, error);
r = sd_bus_message_read(message, "s", &t);
if (r < 0)
return r;
if (streq(name, "RestartUSec"))
return bus_set_transient_usec(u, name, &s->restart_usec, message, flags, error);
k = service_type_from_string(t);
if (k < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid service type %s", t);
if (streq(name, "TimeoutStartUSec")) {
r = bus_set_transient_usec(u, name, &s->timeout_start_usec, message, flags, error);
if (r >= 0 && !UNIT_WRITE_FLAGS_NOOP(flags))
s->start_timeout_defined = true;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->type = k;
unit_write_settingf(UNIT(s), flags, name, "Type=%s", service_type_to_string(s->type));
}
return r;
}
return 1;
} else if (streq(name, "RuntimeMaxUSec")) {
usec_t u;
if (streq(name, "TimeoutStopUSec"))
return bus_set_transient_usec(u, name, &s->timeout_stop_usec, message, flags, error);
r = sd_bus_message_read(message, "t", &u);
if (r < 0)
return r;
if (streq(name, "RuntimeMaxUSec"))
return bus_set_transient_usec(u, name, &s->runtime_max_usec, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->runtime_max_usec = u;
unit_write_settingf(UNIT(s), flags, name, "RuntimeMaxSec=" USEC_FMT "us", u);
}
if (streq(name, "WatchdogUSec"))
return bus_set_transient_usec(u, name, &s->watchdog_usec, message, flags, error);
return 1;
if (streq(name, "FileDescriptorStoreMax"))
return bus_set_transient_unsigned(u, name, &s->n_fd_store_max, message, flags, error);
} else if (streq(name, "Restart")) {
ServiceRestart sr;
const char *v;
if (streq(name, "NotifyAccess"))
return bus_set_transient_notify_access(u, name, &s->notify_access, message, flags, error);
r = sd_bus_message_read(message, "s", &v);
if (r < 0)
return r;
if (streq(name, "PIDFile"))
return bus_set_transient_path(u, name, &s->pid_file, message, flags, error);
if (isempty(v))
sr = SERVICE_RESTART_NO;
else {
sr = service_restart_from_string(v);
if (sr < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid restart setting: %s", v);
}
if (streq(name, "USBFunctionDescriptors"))
return bus_set_transient_path(u, name, &s->usb_function_descriptors, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->restart = sr;
unit_write_settingf(UNIT(s), flags, name, "Restart=%s", service_restart_to_string(sr));
}
if (streq(name, "USBFunctionStrings"))
return bus_set_transient_path(u, name, &s->usb_function_strings, message, flags, error);
return 1;
if (streq(name, "BusName"))
return bus_set_transient_bus_name(u, name, &s->bus_name, message, flags, error);
} else if (STR_IN_SET(name,
"StandardInputFileDescriptor",
"StandardOutputFileDescriptor",
"StandardErrorFileDescriptor")) {
int fd;
if (streq(name, "Restart"))
return bus_set_transient_service_restart(u, name, &s->restart, message, flags, error);
r = sd_bus_message_read(message, "h", &fd);
if (r < 0)
return r;
if (streq(name, "RestartPreventExitStatus"))
return bus_set_transient_exit_status(u, name, &s->restart_prevent_status, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
int copy;
if (streq(name, "RestartForceExitStatus"))
return bus_set_transient_exit_status(u, name, &s->restart_force_status, message, flags, error);
copy = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (copy < 0)
return -errno;
if (streq(name, "SuccessExitStatus"))
return bus_set_transient_exit_status(u, name, &s->success_status, message, flags, error);
if (streq(name, "StandardInputFileDescriptor")) {
asynchronous_close(s->stdin_fd);
s->stdin_fd = copy;
} else if (streq(name, "StandardOutputFileDescriptor")) {
asynchronous_close(s->stdout_fd);
s->stdout_fd = copy;
} else {
asynchronous_close(s->stderr_fd);
s->stderr_fd = copy;
}
if ((ci = service_exec_command_from_string(name)) >= 0)
return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, error);
s->exec_context.stdio_as_fds = true;
}
if (streq(name, "StandardInputFileDescriptor"))
return bus_set_transient_std_fd(u, name, &s->stdin_fd, &s->exec_context.stdio_as_fds, message, flags, error);
return 1;
if (streq(name, "StandardOutputFileDescriptor"))
return bus_set_transient_std_fd(u, name, &s->stdout_fd, &s->exec_context.stdio_as_fds, message, flags, error);
} else if (streq(name, "FileDescriptorStoreMax")) {
uint32_t u;
r = sd_bus_message_read(message, "u", &u);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->n_fd_store_max = (unsigned) u;
unit_write_settingf(UNIT(s), flags, name, "FileDescriptorStoreMax=%" PRIu32, u);
}
return 1;
} else if (streq(name, "NotifyAccess")) {
const char *t;
NotifyAccess k;
r = sd_bus_message_read(message, "s", &t);
if (r < 0)
return r;
k = notify_access_from_string(t);
if (k < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid notify access setting %s", t);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->notify_access = k;
unit_write_settingf(UNIT(s), flags, name, "NotifyAccess=%s", notify_access_to_string(s->notify_access));
}
return 1;
} else if ((ci = service_exec_command_from_string(name)) >= 0)
return bus_exec_command_set_transient_property(UNIT(s), name, &s->exec_command[ci], message, flags, error);
if (streq(name, "StandardErrorFileDescriptor"))
return bus_set_transient_std_fd(u, name, &s->stderr_fd, &s->exec_context.stdio_as_fds, message, flags, error);
return 0;
}

View File

@@ -24,6 +24,7 @@
#include "dbus-execute.h"
#include "dbus-kill.h"
#include "dbus-socket.h"
#include "dbus-util.h"
#include "fd-util.h"
#include "parse-util.h"
#include "path-util.h"
@@ -32,8 +33,6 @@
#include "socket-util.h"
#include "string-util.h"
#include "unit.h"
#include "user-util.h"
#include "utf8.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, socket_result, SocketResult);
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
@@ -171,6 +170,26 @@ const sd_bus_vtable bus_socket_vtable[] = {
SD_BUS_VTABLE_END
};
static inline bool check_size_t_truncation(uint64_t t) {
return (size_t) t == t;
}
static inline const char* socket_protocol_to_name_supported(int32_t i) {
if (!IN_SET(i, IPPROTO_UDPLITE, IPPROTO_SCTP))
return NULL;
return socket_protocol_to_name(i);
}
static BUS_DEFINE_SET_TRANSIENT(int, "i", int32_t, int, "%" PRIi32);
static BUS_DEFINE_SET_TRANSIENT(message_queue, "x", int64_t, long, "%" PRIi64);
static BUS_DEFINE_SET_TRANSIENT_IS_VALID(size_t_check_truncation, "t", uint64_t, size_t, "%" PRIu64, check_size_t_truncation);
static BUS_DEFINE_SET_TRANSIENT_PARSE(bind_ipv6_only, SocketAddressBindIPv6Only, parse_socket_address_bind_ipv6_only_or_bool);
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(fdname, fdname_is_valid);
static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(ifname, ifname_valid);
static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(ip_tos, "i", int32_t, int, "%" PRIi32, ip_tos_to_string_alloc);
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, socket_protocol_to_name_supported);
static int bus_socket_set_transient_property(
Socket *s,
const char *name,
@@ -188,333 +207,139 @@ static int bus_socket_set_transient_property(
flags |= UNIT_PRIVATE;
if (STR_IN_SET(name,
"Accept", "Writable", "KeepAlive", "NoDelay", "FreeBind", "Transparent", "Broadcast",
"PassCredentials", "PassSecurity", "ReusePort", "RemoveOnStop", "SELinuxContextFromNet")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "Accept"))
s->accept = b;
else if (streq(name, "Writable"))
s->writable = b;
else if (streq(name, "KeepAlive"))
s->keep_alive = b;
else if (streq(name, "NoDelay"))
s->no_delay = b;
else if (streq(name, "FreeBind"))
s->free_bind = b;
else if (streq(name, "Transparent"))
s->transparent = b;
else if (streq(name, "Broadcast"))
s->broadcast = b;
else if (streq(name, "PassCredentials"))
s->pass_cred = b;
else if (streq(name, "PassSecurity"))
s->pass_sec = b;
else if (streq(name, "ReusePort"))
s->reuse_port = b;
else if (streq(name, "RemoveOnStop"))
s->remove_on_stop = b;
else /* "SELinuxContextFromNet" */
s->selinux_context_from_net = b;
unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(b));
}
return 1;
} else if (STR_IN_SET(name, "Priority", "IPTTL", "Mark")) {
int32_t i;
r = sd_bus_message_read(message, "i", &i);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "Priority"))
s->priority = i;
else if (streq(name, "IPTTL"))
s->ip_ttl = i;
else /* "Mark" */
s->mark = i;
unit_write_settingf(u, flags, name, "%s=%i", name, i);
}
return 1;
} else if (streq(name, "IPTOS")) {
_cleanup_free_ char *str = NULL;
int32_t i;
r = sd_bus_message_read(message, "i", &i);
if (r < 0)
return r;
r = ip_tos_to_string_alloc(i, &str);
if (r < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s: %i", name, i);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->ip_tos = i;
unit_write_settingf(u, flags, name, "%s=%s", name, str);
}
return 1;
} else if (streq(name, "SocketProtocol")) {
const char *p;
int32_t i;
r = sd_bus_message_read(message, "i", &i);
if (r < 0)
return r;
p = socket_protocol_to_name(i);
if (!p)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s: %i", name, i);
if (!IN_SET(i, IPPROTO_UDPLITE, IPPROTO_SCTP))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unsupported socket protocol: %s", p);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->socket_protocol = i;
unit_write_settingf(u, flags, name, "%s=%s", name, p);
}
return 1;
} else if (STR_IN_SET(name, "Backlog", "MaxConnections", "MaxConnectionsPerSource", "KeepAliveProbes", "TriggerLimitBurst")) {
uint32_t n;
r = sd_bus_message_read(message, "u", &n);
if (r < 0)
return r;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "Backlog"))
s->backlog = n;
else if (streq(name, "MaxConnections"))
s->max_connections = n;
else if (streq(name, "MaxConnectionsPerSource"))
s->max_connections_per_source = n;
else if (streq(name, "KeepAliveProbes"))
s->keep_alive_cnt = n;
else /* "TriggerLimitBurst" */
s->trigger_limit.burst = n;
unit_write_settingf(u, flags, name, "%s=%u", name, n);
}
return 1;
} else if (STR_IN_SET(name, "SocketMode", "DirectoryMode")) {
mode_t m;
if (streq(name, "Accept"))
return bus_set_transient_bool(u, name, &s->accept, message, flags, error);
r = sd_bus_message_read(message, "u", &m);
if (r < 0)
return r;
if (streq(name, "Writable"))
return bus_set_transient_bool(u, name, &s->writable, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "SocketMode"))
s->socket_mode = m;
else /* "DirectoryMode" */
s->directory_mode = m;
if (streq(name, "KeepAlive"))
return bus_set_transient_bool(u, name, &s->keep_alive, message, flags, error);
unit_write_settingf(u, flags, name, "%s=%040o", name, m);
}
if (streq(name, "NoDelay"))
return bus_set_transient_bool(u, name, &s->no_delay, message, flags, error);
return 1;
if (streq(name, "FreeBind"))
return bus_set_transient_bool(u, name, &s->free_bind, message, flags, error);
} else if (STR_IN_SET(name, "MessageQueueMaxMessages", "MessageQueueMessageSize")) {
int64_t n;
if (streq(name, "Transparent"))
return bus_set_transient_bool(u, name, &s->transparent, message, flags, error);
r = sd_bus_message_read(message, "x", &n);
if (r < 0)
return r;
if (streq(name, "Broadcast"))
return bus_set_transient_bool(u, name, &s->broadcast, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "MessageQueueMaxMessages"))
s->mq_maxmsg = (long) n;
else /* "MessageQueueMessageSize" */
s->mq_msgsize = (long) n;
if (streq(name, "PassCredentials"))
return bus_set_transient_bool(u, name, &s->pass_cred, message, flags, error);
unit_write_settingf(u, flags, name, "%s=%" PRIi64, name, n);
}
if (streq(name, "PassSecurity"))
return bus_set_transient_bool(u, name, &s->pass_sec, message, flags, error);
return 1;
if (streq(name, "ReusePort"))
return bus_set_transient_bool(u, name, &s->reuse_port, message, flags, error);
} else if (STR_IN_SET(name, "TimeoutUSec", "KeepAliveTimeUSec", "KeepAliveIntervalUSec", "DeferAcceptUSec", "TriggerLimitIntervalUSec")) {
usec_t t;
if (streq(name, "RemoveOnStop"))
return bus_set_transient_bool(u, name, &s->remove_on_stop, message, flags, error);
r = sd_bus_message_read(message, "t", &t);
if (r < 0)
return r;
if (streq(name, "SELinuxContextFromNet"))
return bus_set_transient_bool(u, name, &s->selinux_context_from_net, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "TimeoutUSec"))
s->timeout_usec = t ?: USEC_INFINITY;
else if (streq(name, "KeepAliveTimeUSec"))
s->keep_alive_time = t;
else if (streq(name, "KeepAliveIntervalUSec"))
s->keep_alive_interval = t;
else if (streq(name, "DeferAcceptUSec"))
s->defer_accept = t;
else /* "TriggerLimitIntervalUSec" */
s->trigger_limit.interval = t;
if (streq(name, "Priority"))
return bus_set_transient_int(u, name, &s->priority, message, flags, error);
unit_write_settingf(u, flags, name, "%s=" USEC_FMT, name, t);
}
if (streq(name, "IPTTL"))
return bus_set_transient_int(u, name, &s->ip_ttl, message, flags, error);
return 1;
if (streq(name, "Mark"))
return bus_set_transient_int(u, name, &s->mark, message, flags, error);
} else if (STR_IN_SET(name, "ReceiveBuffer", "SendBuffer", "PipeSize")) {
uint64_t t;
if (streq(name, "Backlog"))
return bus_set_transient_unsigned(u, name, &s->backlog, message, flags, error);
r = sd_bus_message_read(message, "t", &t);
if (r < 0)
return r;
if (streq(name, "MaxConnections"))
return bus_set_transient_unsigned(u, name, &s->max_connections, message, flags, error);
if ((uint64_t) (size_t) t != t)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s: %" PRIu64, name, t);
if (streq(name, "MaxConnectionsPerSource"))
return bus_set_transient_unsigned(u, name, &s->max_connections_per_source, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "ReceiveBuffer"))
s->receive_buffer = t;
else if (streq(name, "SendBuffer"))
s->send_buffer = t;
else /* "PipeSize" */
s->pipe_size = t;
if (streq(name, "KeepAliveProbes"))
return bus_set_transient_unsigned(u, name, &s->keep_alive_cnt, message, flags, error);
unit_write_settingf(u, flags, name, "%s=%" PRIu64, name, t);
}
if (streq(name, "TriggerLimitBurst"))
return bus_set_transient_unsigned(u, name, &s->trigger_limit.burst, message, flags, error);
return 1;
if (streq(name, "SocketMode"))
return bus_set_transient_mode_t(u, name, &s->socket_mode, message, flags, error);
} else if (STR_IN_SET(name, "SmackLabel", "SmackLabelIPIn", "SmackLabelIPOut", "TCPCongestion")) {
const char *n;
if (streq(name, "DirectoryMode"))
return bus_set_transient_mode_t(u, name, &s->directory_mode, message, flags, error);
r = sd_bus_message_read(message, "s", &n);
if (r < 0)
return r;
if (streq(name, "MessageQueueMaxMessages"))
return bus_set_transient_message_queue(u, name, &s->mq_maxmsg, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "MessageQueueMessageSize"))
return bus_set_transient_message_queue(u, name, &s->mq_msgsize, message, flags, error);
if (streq(name, "SmackLabel"))
r = free_and_strdup(&s->smack, empty_to_null(n));
else if (streq(name, "SmackLabelIPin"))
r = free_and_strdup(&s->smack_ip_in, empty_to_null(n));
else if (streq(name, "SmackLabelIPOut"))
r = free_and_strdup(&s->smack_ip_out, empty_to_null(n));
else /* "TCPCongestion" */
r = free_and_strdup(&s->tcp_congestion, empty_to_null(n));
if (r < 0)
return r;
if (streq(name, "TimeoutUSec"))
return bus_set_transient_usec_fix_0(u, name, &s->timeout_usec, message, flags, error);
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, strempty(n));
}
if (streq(name, "KeepAliveTimeUSec"))
return bus_set_transient_usec(u, name, &s->keep_alive_time, message, flags, error);
return 1;
if (streq(name, "KeepAliveIntervalUSec"))
return bus_set_transient_usec(u, name, &s->keep_alive_interval, message, flags, error);
} else if (streq(name, "BindToDevice")) {
const char *n;
if (streq(name, "DeferAcceptUSec"))
return bus_set_transient_usec(u, name, &s->defer_accept, message, flags, error);
r = sd_bus_message_read(message, "s", &n);
if (r < 0)
return r;
if (streq(name, "TriggerLimitIntervalUSec"))
return bus_set_transient_usec(u, name, &s->trigger_limit.interval, message, flags, error);
if (n[0] && !streq(n, "*")) {
if (!ifname_valid(n))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid interface name for %s: %s", name, n);
} else
n = NULL;
if (streq(name, "SmackLabel"))
return bus_set_transient_string(u, name, &s->smack, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "SmackLabelIPin"))
return bus_set_transient_string(u, name, &s->smack_ip_in, message, flags, error);
r = free_and_strdup(&s->bind_to_device, empty_to_null(n));
if (r < 0)
return r;
if (streq(name, "SmackLabelIPOut"))
return bus_set_transient_string(u, name, &s->smack_ip_out, message, flags, error);
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, strempty(n));
}
if (streq(name, "TCPCongestion"))
return bus_set_transient_string(u, name, &s->tcp_congestion, message, flags, error);
return 1;
if (streq(name, "FileDescriptorName"))
return bus_set_transient_fdname(u, name, &s->fdname, message, flags, error);
} else if (streq(name, "BindIPv6Only")) {
SocketAddressBindIPv6Only b;
const char *n;
if (streq(name, "SocketUser"))
return bus_set_transient_user(u, name, &s->user, message, flags, error);
r = sd_bus_message_read(message, "s", &n);
if (r < 0)
return r;
if (streq(name, "SocketGroup"))
return bus_set_transient_user(u, name, &s->group, message, flags, error);
b = socket_address_bind_ipv6_only_from_string(n);
if (b < 0) {
r = parse_boolean(n);
if (r < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s: %s", name, n);
if (streq(name, "BindIPv6Only"))
return bus_set_transient_bind_ipv6_only(u, name, &s->bind_ipv6_only, message, flags, error);
b = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
}
if (streq(name, "ReceiveBuffer"))
return bus_set_transient_size_t_check_truncation(u, name, &s->receive_buffer, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
s->bind_ipv6_only = b;
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, n);
}
if (streq(name, "SendBuffer"))
return bus_set_transient_size_t_check_truncation(u, name, &s->send_buffer, message, flags, error);
return 1;
if (streq(name, "PipeSize"))
return bus_set_transient_size_t_check_truncation(u, name, &s->pipe_size, message, flags, error);
} else if (streq(name, "FileDescriptorName")) {
const char *n;
if (streq(name, "BindToDevice"))
return bus_set_transient_ifname(u, name, &s->bind_to_device, message, flags, error);
r = sd_bus_message_read(message, "s", &n);
if (r < 0)
return r;
if (streq(name, "IPTOS"))
return bus_set_transient_ip_tos(u, name, &s->ip_tos, message, flags, error);
if (!isempty(n) && !fdname_is_valid(n))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s: %s", name, n);
if (streq(name, "SocketProtocol"))
return bus_set_transient_socket_protocol(u, name, &s->socket_protocol, message, flags, error);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
r = free_and_strdup(&s->fdname, empty_to_null(n));
if (r < 0)
return r;
if ((ci = socket_exec_command_from_string(name)) >= 0)
return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, error);
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, strempty(n));
}
return 1;
} else if (STR_IN_SET(name, "SocketUser", "SocketGroup")) {
const char *n;
r = sd_bus_message_read(message, "s", &n);
if (r < 0)
return r;
if (!isempty(n) && !valid_user_group_name_or_id(n))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s: %s", name, n);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (streq(name, "SocketUser"))
r = free_and_strdup(&s->user, empty_to_null(n));
else /* "SocketGroup" */
r = free_and_strdup(&s->user, empty_to_null(n));
if (r < 0)
return r;
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, strempty(n));
}
return 1;
} else if (streq(name, "Symlinks")) {
if (streq(name, "Symlinks")) {
_cleanup_strv_free_ char **l = NULL;
char **p;
@@ -523,9 +348,6 @@ static int bus_socket_set_transient_property(
return r;
STRV_FOREACH(p, l) {
if (!utf8_is_valid(*p))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "String is not UTF-8 clean, ignoring assignment: %s", *p);
if (!path_is_absolute(*p))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Symlink path is not absolute: %s", *p);
}
@@ -623,9 +445,7 @@ static int bus_socket_set_transient_property(
}
return 1;
} else if ((ci = socket_exec_command_from_string(name)) >= 0)
return bus_exec_command_set_transient_property(UNIT(s), name, &s->exec_command[ci], message, flags, error);
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show More