| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-bus.h" |
| 4 |
|
| 5 |
#include "bus-unit-util.h" |
| 6 |
#include "extract-word.h" |
| 7 |
#include "unit-def.h" |
| 8 |
#include "strv.h" |
| 9 |
#include "tests.h" |
| 10 |
|
| 11 |
static sd_bus *arg_bus = NULL; |
| 12 |
STATIC_DESTRUCTOR_REGISTER(arg_bus, sd_bus_unrefp); |
| 13 |
|
| 14 |
static void test_transient_settings_one(UnitType type, const char* const* lines) { |
| 15 |
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; |
| 16 |
int r; |
| 17 |
|
| 18 |
if (!arg_bus) |
| 19 |
return (void) log_tests_skipped("no bus connection"); |
| 20 |
|
| 21 |
ASSERT_OK(sd_bus_message_new(arg_bus, &m, SD_BUS_MESSAGE_METHOD_CALL)); |
| 22 |
|
| 23 |
STRV_FOREACH(s, lines) { |
| 24 |
const char *t = *s; |
| 25 |
int expect = 1; |
| 26 |
|
| 27 |
if (t[0] == '-') { |
| 28 |
_cleanup_free_ char *code = NULL; |
| 29 |
ASSERT_OK(extract_first_word(&t, &code, " ", 0)); |
| 30 |
ASSERT_OK(r = errno_from_name(code + 1)); |
| 31 |
expect = -r; |
| 32 |
} |
| 33 |
|
| 34 |
r = bus_append_unit_property_assignment(m, type, t); |
| 35 |
log_debug("%s → %d/%s", t, r, r < 0 ? ERRNO_NAME(r) : yes_no(r)); |
| 36 |
ASSERT_EQ(r, expect); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/* The tests data below is in a format intended to be easy to read and write: |
| 41 |
* Examples can be plain or prefixed with a negative numeric error code: |
| 42 |
* - unadorned examples must return 1 (success), |
| 43 |
* - otherwise, the function must return the given error. |
| 44 |
* Note that some functions leave the message in a broken state and subsequent |
| 45 |
* attempts to extend the message will return -ENXIO. |
| 46 |
*/ |
| 47 |
|
| 48 |
TEST(cgroup_properties) { |
| 49 |
const char* const *lines = STRV_MAKE_CONST( |
| 50 |
"DevicePolicy=strict", |
| 51 |
"DevicePolicy=auto", |
| 52 |
"DevicePolicy=closed", |
| 53 |
|
| 54 |
"Slice=system.slice", |
| 55 |
"Slice=user-1000.slice", |
| 56 |
"Slice=system-getty-this-is-a-very-long-long-slice.slice", |
| 57 |
"Slice=", |
| 58 |
|
| 59 |
"ManagedOOMSwap=auto", |
| 60 |
"ManagedOOMSwap=kill", |
| 61 |
"ManagedOOMSwap=", |
| 62 |
|
| 63 |
"ManagedOOMMemoryPressure=auto", |
| 64 |
"ManagedOOMMemoryPressure=kill", |
| 65 |
"ManagedOOMMemoryPressure=", |
| 66 |
|
| 67 |
"ManagedOOMPreference=none", |
| 68 |
"ManagedOOMPreference=avoid", |
| 69 |
"ManagedOOMPreference=omit", |
| 70 |
|
| 71 |
"MemoryPressureWatch=auto", |
| 72 |
"MemoryPressureWatch=off", |
| 73 |
"MemoryPressureWatch=on", |
| 74 |
"MemoryPressureWatch=skip", |
| 75 |
|
| 76 |
"DelegateSubgroup=foo", |
| 77 |
"DelegateSubgroup=bar.scope", |
| 78 |
"DelegateSubgroup=", |
| 79 |
|
| 80 |
"MemoryAccounting=true", |
| 81 |
"-EINVAL MemoryAccounting=false ", |
| 82 |
"-EINVAL MemoryAccounting= yes", |
| 83 |
"-EINVAL MemoryAccounting=\t\tno\t\t", |
| 84 |
"MemoryAccounting=1", |
| 85 |
"MemoryAccounting=0", |
| 86 |
"MemoryAccounting=on", |
| 87 |
"MemoryAccounting=off", |
| 88 |
"MemoryAccounting=True", |
| 89 |
"MemoryAccounting=FALSE", |
| 90 |
"MemoryAccounting=YES", |
| 91 |
"MemoryAccounting=No", |
| 92 |
|
| 93 |
"MemoryZSwapWriteback=true", |
| 94 |
"MemoryZSwapWriteback=false", |
| 95 |
"IOAccounting=yes", |
| 96 |
"IOAccounting=no", |
| 97 |
"TasksAccounting=1", |
| 98 |
"TasksAccounting=0", |
| 99 |
"IPAccounting=on", |
| 100 |
"IPAccounting=off", |
| 101 |
"CoredumpReceive=true", |
| 102 |
"CoredumpReceive=false", |
| 103 |
|
| 104 |
"CPUWeight=100", |
| 105 |
"StartupCPUWeight=100", |
| 106 |
"IOWeight=100", |
| 107 |
"StartupIOWeight=100", |
| 108 |
|
| 109 |
"AllowedCPUs=0-3", |
| 110 |
"AllowedCPUs=1,3,5,7", |
| 111 |
"StartupAllowedCPUs=0-1", |
| 112 |
"StartupAllowedCPUs=2,4,6", |
| 113 |
|
| 114 |
"AllowedMemoryNodes=0", |
| 115 |
"AllowedMemoryNodes=0-2", |
| 116 |
"AllowedMemoryNodes=0-2 3 5 7 3 2 1", |
| 117 |
"StartupAllowedMemoryNodes=0", |
| 118 |
"StartupAllowedMemoryNodes=1-3", |
| 119 |
|
| 120 |
"CPUSetPartition=member", |
| 121 |
"CPUSetPartition=root", |
| 122 |
"CPUSetPartition=isolated", |
| 123 |
"CPUSetPartition=", |
| 124 |
|
| 125 |
"DisableControllers=cpu", |
| 126 |
"DisableControllers= " |
| 127 |
" cpu cpuacct cpuset io blkio memory devices pids bpf-firewall bpf-devices " |
| 128 |
" cpu cpuacct cpuset io blkio memory\tdevices\tpids\tbpf-firewall\tbpf-devices ", |
| 129 |
|
| 130 |
"Delegate=yes", |
| 131 |
|
| 132 |
"MemoryMin=100M", |
| 133 |
"DefaultMemoryLow=50M", |
| 134 |
"DefaultMemoryMin=10M", |
| 135 |
"MemoryLow=2T", |
| 136 |
"MemoryHigh=4G", |
| 137 |
"MemoryMax=2G", |
| 138 |
"MemoryMax=infinity", |
| 139 |
"MemorySwapMax=1G", |
| 140 |
"MemorySwapMax=0", |
| 141 |
"MemoryZSwapMax=500M", |
| 142 |
"MemoryZSwapMax=1G", |
| 143 |
"TasksMax=1000", |
| 144 |
"TasksMax=infinity", |
| 145 |
|
| 146 |
"CPUQuota=1%", |
| 147 |
"CPUQuota=200%", |
| 148 |
"CPUQuotaPeriodSec=100ms", |
| 149 |
"CPUQuotaPeriodSec=1s", |
| 150 |
"-ERANGE CPUQuota=0%", |
| 151 |
|
| 152 |
"DeviceAllow=/dev/null rw", |
| 153 |
"DeviceAllow=/dev/zero r", |
| 154 |
|
| 155 |
"IODeviceWeight=/dev/sda 200", |
| 156 |
"IODeviceWeight=/dev/nvme0n1 500", |
| 157 |
"IODeviceLatencyTargetSec=/dev/sda 100ms", |
| 158 |
"IODeviceLatencyTargetSec=/dev/nvme0n1 10ms", |
| 159 |
|
| 160 |
"IPAddressAllow=10.0.0.0/8", |
| 161 |
"IPAddressAllow=192.168.1.0/24 ::1", |
| 162 |
"IPAddressDeny=0.0.0.0/0", |
| 163 |
"IPAddressDeny=192.168.100.0/24", |
| 164 |
|
| 165 |
"IPIngressFilterPath=/etc/systemd/bpf/ingress.bpf", |
| 166 |
"IPEgressFilterPath=/etc/systemd/bpf/egress.bpf", |
| 167 |
|
| 168 |
"BPFProgram=/usr/lib/systemd/bpf/custom.bpf", |
| 169 |
|
| 170 |
"SocketBindAllow=tcp:80", |
| 171 |
"SocketBindAllow=udp:53", |
| 172 |
"SocketBindDeny=tcp:1-1023", |
| 173 |
"SocketBindDeny=udp:9999-9999", |
| 174 |
"SocketBindDeny=any", |
| 175 |
|
| 176 |
"MemoryPressureThresholdSec=1s", |
| 177 |
"MemoryPressureThresholdSec=1 min 5s 23ms", |
| 178 |
|
| 179 |
"NFTSet=cgroup:inet:filter:my_service user:inet:filter:serviceuser", |
| 180 |
|
| 181 |
"ManagedOOMMemoryPressureDurationSec=30s", |
| 182 |
"ManagedOOMMemoryPressureDurationSec=infinity", |
| 183 |
"ManagedOOMMemoryPressureLimit=0%", |
| 184 |
"ManagedOOMMemoryPressureLimit=95.8%", |
| 185 |
"ManagedOOMMemoryPressureLimit=95.88%", |
| 186 |
"-EINVAL ManagedOOMMemoryPressureLimit=95.888%", /* too many digits after dot */ |
| 187 |
"ManagedOOMMemoryPressureLimit=100%", |
| 188 |
|
| 189 |
"IOReadBandwidthMax=/dev/sda 1M", |
| 190 |
"IOReadBandwidthMax=/dev/sdb 2000K", |
| 191 |
"IOReadBandwidthMax=/dev/nvme0n1 100M", |
| 192 |
"IOReadBandwidthMax=/dev/nvme0n1p1 1G", |
| 193 |
"IOReadBandwidthMax=/dev/mapper/root infinity", |
| 194 |
"IOWriteBandwidthMax=/dev/sda 1M", |
| 195 |
"IOWriteBandwidthMax=/dev/sdb 2M", |
| 196 |
"IOWriteBandwidthMax=/dev/nvme0n1 100M", |
| 197 |
"IOWriteBandwidthMax=/dev/mapper/home infinity", |
| 198 |
|
| 199 |
/* Various strange cases */ |
| 200 |
"DevicePolicy=", |
| 201 |
"DevicePolicy=value=with=equals", |
| 202 |
"DevicePolicy=auto domain", |
| 203 |
"DevicePolicy=policy with spaces", |
| 204 |
"Slice=complex-name_with.various-chars123", |
| 205 |
"ManagedOOMSwap=kill immediate", |
| 206 |
"ManagedOOMMemoryPressureLimit=50.5%", |
| 207 |
"IOReadBandwidthMax=/dev/disk/by-uuid/12345678-1234-1234-1234-123456789012 100M", |
| 208 |
"IOWriteBandwidthMax=/dev/disk/by-label/DATA 200M", |
| 209 |
"IOReadBandwidthMax=/dev/disk/by-partlabel/EFI\\x20System\\x20Partition 500M", |
| 210 |
"IOWriteBandwidthMax=/dev/disk/by-id/dm-uuid-CRYPT-LUKS2-00f7541884c34bff92f60faec9d8f217-luks-00f75418-84c3-4bff-92f6-0faec9d8f217 500M", |
| 211 |
"DelegateSubgroup=very.long.subgroup.name.with.dots", |
| 212 |
"MemoryPressureWatch=custom-value", |
| 213 |
|
| 214 |
/* Properties with special characters and edge cases */ |
| 215 |
"Slice=user-$(id -u).slice", |
| 216 |
"[email protected]", |
| 217 |
"DevicePolicy=auto,strict", |
| 218 |
"ManagedOOMSwap=auto;kill", |
| 219 |
|
| 220 |
/* Deprecated */ |
| 221 |
"MemoryLimit=1G", |
| 222 |
"MemoryLimit=infinity", |
| 223 |
"MemoryLimit=", |
| 224 |
"CPUShares=1024", |
| 225 |
"StartupCPUShares=1024", |
| 226 |
"BlockIOAccounting=true", |
| 227 |
"BlockIOWeight=100", |
| 228 |
"StartupBlockIOWeight=1000", |
| 229 |
"BlockIODeviceWeight=/dev/sda 500", |
| 230 |
"BlockIOReadBandwidth=/dev/sda 1M", |
| 231 |
"BlockIOWriteBandwidth=/dev/sda 1M", |
| 232 |
"CPUAccounting=true" |
| 233 |
); |
| 234 |
|
| 235 |
test_transient_settings_one(UNIT_SERVICE, lines); |
| 236 |
/* Also UNIT_SOCKET, UNIT_SLICE, UNIT_SCOPE, UNIT_MOUNT. */ |
| 237 |
} |
| 238 |
|
| 239 |
TEST(automount_properties) { |
| 240 |
const char* const *lines = STRV_MAKE_CONST( |
| 241 |
"Where=/mnt/data", |
| 242 |
"Where=/home/user/./../storage", |
| 243 |
"Where=non/absolute/path", // TODO: should this be allowed? |
| 244 |
|
| 245 |
"ExtraOptions=uid=1000,gid=1000", |
| 246 |
"ExtraOptions= rw,noatime,user_xattr ", |
| 247 |
|
| 248 |
"DirectoryMode=0755", |
| 249 |
"DirectoryMode=700", |
| 250 |
|
| 251 |
"TimeoutIdleSec=60s", |
| 252 |
"TimeoutIdleSec=1week 1 day 2h 3 minutes 300s 50 ms" |
| 253 |
); |
| 254 |
|
| 255 |
test_transient_settings_one(UNIT_AUTOMOUNT, lines); |
| 256 |
} |
| 257 |
|
| 258 |
TEST(execute_properties) { |
| 259 |
const char* const *lines = STRV_MAKE_CONST( |
| 260 |
/* String properties */ |
| 261 |
"User=myuser", |
| 262 |
"Group=mygroup", |
| 263 |
"UtmpIdentifier=myservice", |
| 264 |
"UtmpMode=init", |
| 265 |
"UtmpMode=login", |
| 266 |
"PAMName=login", |
| 267 |
"PAMName=system-auth", |
| 268 |
"TTYPath=/dev/tty1", |
| 269 |
"TTYPath=/dev/pts/0", |
| 270 |
"WorkingDirectory=/var/lib/myapp", |
| 271 |
"RootDirectory=/srv/container", |
| 272 |
"SyslogIdentifier=myservice", |
| 273 |
"ProtectSystem=strict", |
| 274 |
"ProtectSystem=true", |
| 275 |
"ProtectSystem=false", |
| 276 |
"ProtectHome=true", |
| 277 |
"ProtectHome=read-only", |
| 278 |
"ProtectHome=tmpfs", |
| 279 |
"PrivateTmp=true", |
| 280 |
"PrivateTmp=fAlSe", |
| 281 |
"PrivateTmpEx=0001", |
| 282 |
"PrivateTmpEx=0000", |
| 283 |
"PrivateTmp=asdf", |
| 284 |
"PrivateTmpEx=asdf", |
| 285 |
"PrivateUsers=no", |
| 286 |
"PrivateUsers=1", |
| 287 |
"PrivateUsersEx=true", |
| 288 |
"PrivateUsersEx=false", |
| 289 |
"PrivateUsers=whatever", |
| 290 |
"ProtectControlGroupsEx=true", |
| 291 |
"ProtectControlGroupsEx=false", |
| 292 |
|
| 293 |
"SELinuxContext=system_u:system_r:httpd_t:s0", |
| 294 |
"RootImage=/var/lib/machines/container.raw", |
| 295 |
"RootVerity=/var/lib/machines/container.verity", |
| 296 |
"RuntimeDirectoryPreserve=true", |
| 297 |
"RuntimeDirectoryPreserve=restart", |
| 298 |
"Personality=x86-64", |
| 299 |
"Personality=x86", |
| 300 |
"KeyringMode=inherit", |
| 301 |
"KeyringMode=private", |
| 302 |
"KeyringMode=shared", |
| 303 |
"ProtectProc=invisible", |
| 304 |
"ProtectProc=noaccess", |
| 305 |
"ProtectProc=ptraceable", |
| 306 |
"ProcSubset=pid", |
| 307 |
"ProcSubset=all", |
| 308 |
"NetworkNamespacePath=/proc/123/ns/net", |
| 309 |
"IPCNamespacePath=/proc/123/ns/ipc", |
| 310 |
"LogNamespace=myapp", |
| 311 |
"RootImagePolicy=closed", |
| 312 |
"RootImagePolicy=strict", |
| 313 |
"MountImagePolicy=closed", |
| 314 |
"MountImagePolicy=strict", |
| 315 |
"ExtensionImagePolicy=closed", |
| 316 |
"ExtensionImagePolicy=strict", |
| 317 |
|
| 318 |
/* PrivatePIDs is boolean, but a string. */ |
| 319 |
"PrivatePIDs=true", |
| 320 |
"PrivatePIDs=false", |
| 321 |
"PrivatePIDs=foooooooooo", |
| 322 |
|
| 323 |
/* Boolean properties */ |
| 324 |
"IgnoreSIGPIPE=true", |
| 325 |
"TTYVHangup=true", |
| 326 |
"TTYReset=true", |
| 327 |
"TTYVTDisallocate=true", |
| 328 |
"PrivateDevices=true", |
| 329 |
"PrivateNetwork=true", |
| 330 |
"PrivateMounts=true", |
| 331 |
"PrivateIPC=true", |
| 332 |
"NoNewPrivileges=true", |
| 333 |
"SyslogLevelPrefix=true", |
| 334 |
"MemoryDenyWriteExecute=true", |
| 335 |
"RestrictRealtime=true", |
| 336 |
"DynamicUser=true", |
| 337 |
"RemoveIPC=true", |
| 338 |
"ProtectKernelTunables=true", |
| 339 |
"ProtectKernelModules=true", |
| 340 |
"ProtectKernelLogs=true", |
| 341 |
"ProtectClock=true", |
| 342 |
"ProtectControlGroups=true", |
| 343 |
"MountAPIVFS=true", |
| 344 |
"BindLogSockets=true", |
| 345 |
"CPUSchedulingResetOnFork=true", |
| 346 |
"LockPersonality=true", |
| 347 |
"MemoryKSM=true", |
| 348 |
"RestrictSUIDSGID=true", |
| 349 |
"RootEphemeral=true", |
| 350 |
"SetLoginEnvironment=true", |
| 351 |
|
| 352 |
/* Path and directory strvs */ |
| 353 |
"ReadWriteDirectories=/var/lib/myapp", |
| 354 |
"ReadWriteDirectories=/var/lib/myapp /tmp/workdir", |
| 355 |
"ReadOnlyDirectories=/usr/share/data", |
| 356 |
"ReadOnlyDirectories=/usr/share/data /etc/config", |
| 357 |
"InaccessibleDirectories=/home /root", |
| 358 |
"ReadWritePaths=/var/lib/myapp /tmp/workdir", |
| 359 |
"ReadOnlyPaths=", |
| 360 |
"ReadOnlyPaths=/ /./ /../../ /usr/share/data /etc/config", |
| 361 |
"InaccessiblePaths=/home", |
| 362 |
"InaccessiblePaths=/home /root /var/cache", |
| 363 |
"ExecPaths=/usr/bin /usr/local/bin", |
| 364 |
"NoExecPaths=/tmp /var/tmp", |
| 365 |
"ExecSearchPath=/usr/bin:/usr/local/bin", |
| 366 |
"ExtensionDirectories=/var/lib/extensions /opt/extensions", |
| 367 |
"ConfigurationDirectory=myapp subdir", |
| 368 |
"SupplementaryGroups=wheel audio video", |
| 369 |
"SystemCallArchitectures=native x86-64", |
| 370 |
|
| 371 |
/* Log levels and facilities */ |
| 372 |
"SyslogLevel=info", |
| 373 |
"SyslogLevel=debug", |
| 374 |
"SyslogLevel=warning", |
| 375 |
"SyslogLevel=err", |
| 376 |
"-EINVAL SyslogLevel=error", |
| 377 |
"LogLevelMax=info", |
| 378 |
"LogLevelMax=debug", |
| 379 |
"LogLevelMax=warning", |
| 380 |
"SyslogFacility=daemon", |
| 381 |
"SyslogFacility=local0", |
| 382 |
"SyslogFacility=mail", |
| 383 |
|
| 384 |
/* Various */ |
| 385 |
"SecureBits=keep-caps", |
| 386 |
"SecureBits=keep-caps-locked", |
| 387 |
"SecureBits=no-setuid-fixup", |
| 388 |
|
| 389 |
"CPUSchedulingPolicy=other", |
| 390 |
"CPUSchedulingPolicy=fifo", |
| 391 |
"CPUSchedulingPolicy=rr", |
| 392 |
"CPUSchedulingPriority=50", |
| 393 |
"CPUSchedulingPriority=1", |
| 394 |
"CPUSchedulingPriority=99", |
| 395 |
"-ERANGE CPUSchedulingPriority=2147483648", |
| 396 |
|
| 397 |
"OOMScoreAdjust=100", |
| 398 |
"OOMScoreAdjust=-100", |
| 399 |
"OOMScoreAdjust=0", |
| 400 |
"CoredumpFilter=0x33", |
| 401 |
"CoredumpFilter=0x7f", |
| 402 |
"Nice=10", |
| 403 |
"Nice=-10", |
| 404 |
"SystemCallErrorNumber=EPERM", |
| 405 |
"SystemCallErrorNumber=EACCES", |
| 406 |
"SystemCallErrorNumber=kill", |
| 407 |
|
| 408 |
"IOSchedulingClass=1", |
| 409 |
"IOSchedulingPriority=4", |
| 410 |
|
| 411 |
"RuntimeDirectoryMode=0755", |
| 412 |
"RuntimeDirectoryMode=750", |
| 413 |
"StateDirectoryMode=0000", |
| 414 |
"CacheDirectoryMode=0755", |
| 415 |
"LogsDirectoryMode=0755", |
| 416 |
"ConfigurationDirectoryMode=0755", |
| 417 |
"UMask=0002", |
| 418 |
|
| 419 |
"TimerSlackNSec=50ms", |
| 420 |
"LogRateLimitIntervalSec=30s", |
| 421 |
"LogRateLimitBurst=1000", |
| 422 |
|
| 423 |
"TTYRows=24", |
| 424 |
"TTYColumns=80", |
| 425 |
|
| 426 |
"MountFlags=shared", |
| 427 |
"MountFlags=slave", |
| 428 |
"MountFlags=private", |
| 429 |
|
| 430 |
"Environment=PATH=/usr/bin:/bin", |
| 431 |
"Environment=HOME=/home/user USER=myuser", |
| 432 |
"UnsetEnvironment=TEMP", |
| 433 |
"UnsetEnvironment=TEMP TMP", |
| 434 |
"PassEnvironment=PATH", |
| 435 |
"PassEnvironment=PATH HOME USER", |
| 436 |
"EnvironmentFile=/etc/default/myservice", |
| 437 |
"EnvironmentFile=-/etc/default/myservice", |
| 438 |
|
| 439 |
"SetCredential=username:nonsecret", |
| 440 |
"SetCredential=token1:abcdef123456 token2: token3:asdf:asdf", |
| 441 |
"SetCredential=", |
| 442 |
/* "-EPIPE SetCredentialEncrypted=password:encrypted_data token:encrypted_too", */ |
| 443 |
|
| 444 |
"LoadCredential=", |
| 445 |
"LoadCredential=asdf", |
| 446 |
"LoadCredential=cert:/etc/ssl/cert.pem", |
| 447 |
"LoadCredential=key:/etc/ssl/key.pem", |
| 448 |
"LoadCredentialEncrypted=password:encrypted_file", |
| 449 |
"ImportCredential=*", |
| 450 |
"ImportCredential=prefix.*", |
| 451 |
"ImportCredentialEx=*", |
| 452 |
"ImportCredentialEx=prefix.*", |
| 453 |
|
| 454 |
"LogExtraFields=FIELD1=value1", |
| 455 |
"LogExtraFields=FIELD1=value1 FIELD2=value2", |
| 456 |
"LogFilterPatterns=~debug", |
| 457 |
"LogFilterPatterns=~debug ~trace", |
| 458 |
|
| 459 |
"StandardInput=null", |
| 460 |
"StandardInput=tty", |
| 461 |
"StandardInput=socket", |
| 462 |
"StandardOutput=journal", |
| 463 |
"StandardOutput=syslog", |
| 464 |
"StandardOutput=null", |
| 465 |
"StandardError=journal", |
| 466 |
"StandardError=syslog", |
| 467 |
"StandardError=null", |
| 468 |
"StandardInputText=Hello World", |
| 469 |
"StandardInputText=Multi\nLine\nText", |
| 470 |
"StandardInputData=SGVsbG8gV29ybGQ=", |
| 471 |
|
| 472 |
"AppArmorProfile=myprofile", |
| 473 |
"AppArmorProfile=unconfined", |
| 474 |
"SmackProcessLabel=mylabel", |
| 475 |
"SmackProcessLabel=_", |
| 476 |
|
| 477 |
"CapabilityBoundingSet=CAP_NET_BIND_SERVICE", |
| 478 |
"CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_SYS_TIME", |
| 479 |
"AmbientCapabilities=CAP_NET_BIND_SERVICE", |
| 480 |
"AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_SYS_TIME", |
| 481 |
|
| 482 |
"CPUAffinity=0-3", |
| 483 |
"CPUAffinity=0,2,4,6", |
| 484 |
"CPUAffinity=1", |
| 485 |
|
| 486 |
"NUMAPolicy=default", |
| 487 |
"NUMAPolicy=preferred", |
| 488 |
"NUMAPolicy=bind", |
| 489 |
"NUMAMask=0-3", |
| 490 |
"NUMAMask=0,2,4,6", |
| 491 |
|
| 492 |
"RestrictAddressFamilies=AF_INET", |
| 493 |
"RestrictAddressFamilies=AF_INET AF_INET6", |
| 494 |
"RestrictAddressFamilies=~AF_NETLINK", |
| 495 |
"RestrictFileSystems=ext4", |
| 496 |
"RestrictFileSystems=ext4 xfs", |
| 497 |
"RestrictFileSystems=~tmpfs", |
| 498 |
"SystemCallFilter=@system-service", |
| 499 |
"SystemCallFilter=read write open close", |
| 500 |
"SystemCallFilter=~@debug", |
| 501 |
"SystemCallLog=@system-service", |
| 502 |
"SystemCallLog=read write open", |
| 503 |
"RestrictNetworkInterfaces=lo", |
| 504 |
"RestrictNetworkInterfaces=lo eth0", |
| 505 |
"RestrictNetworkInterfaces=~wlan0", |
| 506 |
"RestrictNamespaces=cgroup", |
| 507 |
"RestrictNamespaces=cgroup ipc net", |
| 508 |
"RestrictNamespaces=~user", |
| 509 |
"DelegateNamespaces=pid", |
| 510 |
"DelegateNamespaces=pid net", |
| 511 |
|
| 512 |
"BindPaths=/host/path:/container/path", |
| 513 |
"BindPaths=/host/path:/container/path:rbind", |
| 514 |
"BindReadOnlyPaths=/host/ro:/container/ro", |
| 515 |
"BindReadOnlyPaths=/host/ro:/container/ro:rbind", |
| 516 |
|
| 517 |
"TemporaryFileSystem=/tmp", |
| 518 |
"TemporaryFileSystem=/tmp:rw,nodev,nosuid,size=100M /with/colons/in/options:rw,size=10%:::::::: \"/with/spaces path/:option1:option2\"", |
| 519 |
/* "-EINVAL TemporaryFileSystem=\"/tmp path", */ |
| 520 |
"TemporaryFileSystem=", |
| 521 |
|
| 522 |
"RootHash=/a/path", |
| 523 |
"RootHash=1234567890abcdef1234567890abcdef", |
| 524 |
"RootHashSignature=/a/path", |
| 525 |
"RootHashSignature=base64:zKFyIq7aZn4EpuCCmpcF9jPgD8JFE1g/xfT0Mas8X4M0WycyigRsQ4IH4yysufus0AORQsuk3oeGhRC7t1tLyKD0Ih0VcYedv5+p8e6itqrIwzecu98+rNyUVDhWBzS0PMwxEw==", |
| 526 |
|
| 527 |
"RootImageOptions=partition=root,rw", |
| 528 |
"RootImageOptions=partition=usr,ro", |
| 529 |
"MountImages=/path/to/image.raw:/mount/point", |
| 530 |
"MountImages=/path/to/image.raw:/mount/point:partition=1", |
| 531 |
"ExtensionImages=/path/to/ext.raw", |
| 532 |
"ExtensionImages=/path/to/ext.raw:/opt/extension", |
| 533 |
|
| 534 |
"StateDirectory=myapp", |
| 535 |
"StateDirectory=myapp subdir", |
| 536 |
"RuntimeDirectory=myapp", |
| 537 |
"RuntimeDirectory=myapp subdir", |
| 538 |
"CacheDirectory=myapp", |
| 539 |
"CacheDirectory=myapp subdir", |
| 540 |
"LogsDirectory=myapp", |
| 541 |
"LogsDirectory=myapp subdir", |
| 542 |
|
| 543 |
"ProtectHostname=true", |
| 544 |
"ProtectHostname=false", |
| 545 |
"ProtectHostname=private", |
| 546 |
"ProtectHostnameEx=true", |
| 547 |
"ProtectHostnameEx=false", |
| 548 |
"ProtectHostnameEx=private", |
| 549 |
"ProtectHostname=true:foo", |
| 550 |
"ProtectHostname=false:foo", |
| 551 |
"ProtectHostname=private:foo", |
| 552 |
"ProtectHostnameEx=true:foo", |
| 553 |
"ProtectHostnameEx=false:foo", |
| 554 |
"ProtectHostnameEx=private:foo", |
| 555 |
"ProtectHostname=private:a.b.c.d.example.org", |
| 556 |
|
| 557 |
"LimitCPU=15", |
| 558 |
"LimitCPU=15:35", |
| 559 |
"LimitCPU=infinity", |
| 560 |
"LimitFSIZE=123", |
| 561 |
"LimitDATA=1", |
| 562 |
"LimitSTACK=1:2", |
| 563 |
"LimitCORE=0", |
| 564 |
"LimitRSS=0", |
| 565 |
"LimitNPROC=0", |
| 566 |
"LimitNOFILE=1234", |
| 567 |
"LimitMEMLOCK=infinity", |
| 568 |
"LimitAS=44", |
| 569 |
"LimitLOCKS=22", |
| 570 |
"LimitSIGPENDING=11", |
| 571 |
"LimitMSGQUEUE=0", |
| 572 |
"LimitNICE=0", |
| 573 |
"LimitRTPRIO=0", |
| 574 |
"LimitRTTIME=0" |
| 575 |
); |
| 576 |
|
| 577 |
test_transient_settings_one(UNIT_SOCKET, lines); |
| 578 |
/* Also UNIT_SERVICE, UNIT_MOUNT. */ |
| 579 |
} |
| 580 |
|
| 581 |
TEST(kill_properties) { |
| 582 |
const char* const *lines = STRV_MAKE_CONST( |
| 583 |
"KillMode=control-group", |
| 584 |
"KillMode=process", |
| 585 |
"KillMode=mixed", |
| 586 |
"KillMode=none", |
| 587 |
|
| 588 |
"SendSIGHUP=true", |
| 589 |
"SendSIGKILL=true", |
| 590 |
|
| 591 |
"KillSignal=1", |
| 592 |
"KillSignal=64", /* _NSIG == 64 */ |
| 593 |
"-ERANGE KillSignal=0", |
| 594 |
"-ERANGE KillSignal=65", |
| 595 |
"RestartKillSignal=TERM", |
| 596 |
"RestartKillSignal=SIGTERM", |
| 597 |
"FinalKillSignal=WINCH", |
| 598 |
"FinalKillSignal=SIGWINCH", |
| 599 |
"FinalKillSignal=2", |
| 600 |
"WatchdogSignal=RTMIN", |
| 601 |
"WatchdogSignal=RTMIN+0" |
| 602 |
); |
| 603 |
|
| 604 |
test_transient_settings_one(UNIT_SCOPE, lines); |
| 605 |
/* Also UNIT_SERVICE, UNIT_SOCKET, UNIT_MOUNT. */ |
| 606 |
} |
| 607 |
|
| 608 |
TEST(mount_properties) { |
| 609 |
const char* const *lines = STRV_MAKE_CONST( |
| 610 |
"What=/dev/sda1", |
| 611 |
"What=UUID=12345678-1234-1234-1234-123456789012", |
| 612 |
|
| 613 |
"Where=/mnt/disk", |
| 614 |
"Where=non/absolute/var/lib/data", // TODO: should this be allowed? |
| 615 |
|
| 616 |
"Options=defaults", |
| 617 |
"Options= rw,noatime,user_xattr,acl more ", |
| 618 |
"Options=", |
| 619 |
|
| 620 |
"Type=ext4", |
| 621 |
"TimeoutSec= 90 s ", |
| 622 |
"DirectoryMode=0755", |
| 623 |
"SloppyOptions=true", |
| 624 |
"LazyUnmount=true", |
| 625 |
"ForceUnmount=true", |
| 626 |
"ReadwriteOnly=true" |
| 627 |
); |
| 628 |
|
| 629 |
test_transient_settings_one(UNIT_MOUNT, lines); |
| 630 |
} |
| 631 |
|
| 632 |
TEST(path_properties) { |
| 633 |
const char* const *lines = STRV_MAKE_CONST( |
| 634 |
"MakeDirectory=true", |
| 635 |
"DirectoryMode=0", |
| 636 |
"DirectoryMode=1", |
| 637 |
|
| 638 |
"PathExists=/var/lib/myapp/ready", |
| 639 |
"PathExists=/tmp/../././././././././.../.../.../.../.../.../lockfile", |
| 640 |
|
| 641 |
"PathExistsGlob=/var/log/*.log", |
| 642 |
"PathExistsGlob=/home/*/Desktop???", |
| 643 |
|
| 644 |
"PathChanged=/etc/myapp.conf", |
| 645 |
"PathModified=/etc/passwd", |
| 646 |
"DirectoryNotEmpty=/var/spool/mail", |
| 647 |
"TriggerLimitBurst=10", |
| 648 |
"PollLimitBurst=100", |
| 649 |
"TriggerLimitIntervalSec=2s", |
| 650 |
"PollLimitIntervalSec=5s" |
| 651 |
); |
| 652 |
|
| 653 |
test_transient_settings_one(UNIT_PATH, lines); |
| 654 |
} |
| 655 |
|
| 656 |
TEST(scope_properties) { |
| 657 |
const char* const *lines = STRV_MAKE_CONST( |
| 658 |
"RuntimeMaxSec=3600s", |
| 659 |
"RuntimeRandomizedExtraSec=60s", |
| 660 |
"TimeoutStopSec=90s", |
| 661 |
"OOMPolicy=stop", |
| 662 |
"OOMPolicy=continue", |
| 663 |
"User=_some_user", |
| 664 |
"User=1000", |
| 665 |
"Group=mygroup", |
| 666 |
"Group=users" |
| 667 |
); |
| 668 |
|
| 669 |
test_transient_settings_one(UNIT_SCOPE, lines); |
| 670 |
} |
| 671 |
|
| 672 |
TEST(service_properties) { |
| 673 |
const char* const *lines = STRV_MAKE_CONST( |
| 674 |
/* String properties — no validity checking */ |
| 675 |
"PIDFile=/var/run/myservice.pid", |
| 676 |
"PIDFile=/run/myservice.pid", |
| 677 |
"PIDFile=/tmp/daemon.pid", |
| 678 |
"Type=simple", |
| 679 |
"Type=forking", |
| 680 |
"Type=oneshot", |
| 681 |
"Type=dbus", |
| 682 |
"Type=notify", |
| 683 |
"Type=idle", |
| 684 |
"Type=exec", |
| 685 |
"Type= asdf ", |
| 686 |
"ExitType=main", |
| 687 |
"ExitType=cgroup", |
| 688 |
"Restart=no", |
| 689 |
"Restart=on-success", |
| 690 |
"Restart=on-failure", |
| 691 |
"Restart=on-abnormal", |
| 692 |
"Restart=on-watchdog", |
| 693 |
"Restart=on-abort", |
| 694 |
"Restart=always", |
| 695 |
"RestartMode=normal", |
| 696 |
"RestartMode=direct", |
| 697 |
"BusName=org.example.MyService", |
| 698 |
"BusName=com.company.daemon", |
| 699 |
"BusName=net.domain.service", |
| 700 |
"NotifyAccess=none", |
| 701 |
"NotifyAccess=main", |
| 702 |
"NotifyAccess=exec", |
| 703 |
"NotifyAccess=all", |
| 704 |
"USBFunctionDescriptors=/dev/usb-ffs/myfunction", |
| 705 |
"USBFunctionStrings=/dev/usb-ffs/myfunction", |
| 706 |
"OOMPolicy=stop", |
| 707 |
"OOMPolicy=continue", |
| 708 |
"OOMPolicy=kill", |
| 709 |
"TimeoutStartFailureMode=terminate", |
| 710 |
"TimeoutStartFailureMode=abort", |
| 711 |
"TimeoutStartFailureMode=kill", |
| 712 |
"TimeoutStopFailureMode=terminate", |
| 713 |
"TimeoutStopFailureMode=abort", |
| 714 |
"TimeoutStopFailureMode=kill", |
| 715 |
"FileDescriptorStorePreserve=no", |
| 716 |
"FileDescriptorStorePreserve=yes", |
| 717 |
"FileDescriptorStorePreserve=restart", |
| 718 |
|
| 719 |
/* Boolean properties */ |
| 720 |
"PermissionsStartOnly=true", |
| 721 |
"RootDirectoryStartOnly=true", |
| 722 |
"RemainAfterExit=true", |
| 723 |
"GuessMainPID=true", |
| 724 |
"-EINVAL GuessMainPID=WAT", |
| 725 |
|
| 726 |
/* Timespan properties */ |
| 727 |
"RestartSec=5s", |
| 728 |
"RestartSec=1 y 2 months 30s", |
| 729 |
"RestartMaxDelaySec=5min", |
| 730 |
"TimeoutStartSec=infinity", |
| 731 |
"TimeoutStopSec=infinity", |
| 732 |
"TimeoutAbortSec=0", |
| 733 |
"RuntimeMaxSec=24h", |
| 734 |
"RuntimeRandomizedExtraSec=30s", |
| 735 |
"WatchdogSec=30s", |
| 736 |
"TimeoutSec=90s", |
| 737 |
|
| 738 |
/* Unsigned integer values */ |
| 739 |
"FileDescriptorStoreMax=0", |
| 740 |
"FileDescriptorStoreMax=9999999", |
| 741 |
"RestartSteps=10", |
| 742 |
|
| 743 |
/* Exec command properties */ |
| 744 |
"ExecCondition=test -f /etc/myservice.conf", |
| 745 |
"ExecStartPre=/usr/bin/mkdir -p /var/lib/myservice", |
| 746 |
"ExecStartPre=-/usr/bin/systemctl is-active network.target", |
| 747 |
"ExecStartPre=@/usr/bin/systemctl is-active network.target", |
| 748 |
"ExecStartPre=:systemctl is-active network.target", |
| 749 |
"ExecStartPre=+systemctl is-active network.target", |
| 750 |
"ExecStartPre=!systemctl is-active network.target", |
| 751 |
"ExecStartPre=|systemctl is-active network.target", |
| 752 |
"ExecStartPre=!!true", |
| 753 |
"ExecStart=@:+!|foobar bar bar", |
| 754 |
"ExecStart=@:+!!|foobar bar bar", |
| 755 |
"ExecStartPost=post post" |
| 756 |
"ExecConditionEx=/usr/bin/test -f /etc/myservice.conf", |
| 757 |
"ExecStartPreEx=/usr/bin/mkdir -p /var/lib/myservice", |
| 758 |
"ExecStartEx=/usr/bin/myservice --config /etc/myservice.conf", |
| 759 |
"ExecStartPostEx=/usr/bin/logger 'Service started'", |
| 760 |
"ExecReload=/bin/kill -HUP $MAINPID", |
| 761 |
"ExecStop=kill -TERM $MAINPID", |
| 762 |
"ExecStopPost=+logger 'Service stopped'", |
| 763 |
"ExecStopPost=rm -f /var/lib/myservice/started", |
| 764 |
"ExecReloadEx=/bin/kill -HUP $MAINPID", |
| 765 |
"ExecStopEx=/bin/kill -TERM $MAINPID", |
| 766 |
"ExecStopPostEx=/usr/bin/logger 'Service stopped'", |
| 767 |
|
| 768 |
"RestartPreventExitStatus=1", |
| 769 |
"RestartPreventExitStatus=1 2 8 SIGTERM", |
| 770 |
"RestartPreventExitStatus=SIGKILL SIGTERM", |
| 771 |
"RestartForceExitStatus=1", |
| 772 |
"RestartForceExitStatus=1 2 8 SIGTERM", |
| 773 |
"RestartForceExitStatus=SIGKILL SIGTERM", |
| 774 |
"SuccessExitStatus=0", |
| 775 |
"SuccessExitStatus=0 1 2", |
| 776 |
"SuccessExitStatus=0 SIGTERM SIGKILL", |
| 777 |
|
| 778 |
"OpenFile=/a/path", |
| 779 |
"OpenFile=/etc/myservice.conf:SOME$NAME", |
| 780 |
"OpenFile=/etc/myservice.conf:SOME$NAME:read-only", |
| 781 |
"OpenFile=/etc/myservice.conf:SOME$NAME:append", |
| 782 |
"OpenFile=/etc/myservice.conf:SOME$NAME:truncate", |
| 783 |
"OpenFile=/etc/myservice.conf:SOME$NAME:graceful", |
| 784 |
"OpenFile=/etc/myservice.conf::read-only,graceful", |
| 785 |
"OpenFile=/etc/myservice.conf::truncate,graceful", |
| 786 |
"-EINVAL OpenFile=/etc/myservice.conf::append,truncate,read-only,graceful", |
| 787 |
|
| 788 |
"ReloadSignal=RTMAX", |
| 789 |
"ReloadSignal=RTMAX-0", |
| 790 |
"ReloadSignal=RTMAX-5", |
| 791 |
"-ERANGE ReloadSignal=RTMAX-100" |
| 792 |
); |
| 793 |
|
| 794 |
test_transient_settings_one(UNIT_SERVICE, lines); |
| 795 |
} |
| 796 |
|
| 797 |
TEST(socket_properties) { |
| 798 |
const char* const *lines = STRV_MAKE_CONST( |
| 799 |
/* Boolean properties */ |
| 800 |
"Accept=true", |
| 801 |
"FlushPending=true", |
| 802 |
"Writable=true", |
| 803 |
"KeepAlive=true", |
| 804 |
"NoDelay=true", |
| 805 |
"FreeBind=true", |
| 806 |
"Transparent=true", |
| 807 |
"Broadcast=true", |
| 808 |
"PassCredentials=true", |
| 809 |
"PassFileDescriptorsToExec=true", |
| 810 |
"PassSecurity=true", |
| 811 |
"PassPacketInfo=true", |
| 812 |
"ReusePort=true", |
| 813 |
"RemoveOnStop=true", |
| 814 |
"SELinuxContextFromNet=true", |
| 815 |
|
| 816 |
/* Integer properties */ |
| 817 |
"Priority=6", |
| 818 |
"Priority=0000000", |
| 819 |
"Priority=-1", |
| 820 |
"IPTTL=64", |
| 821 |
"IPTTL=255", |
| 822 |
"IPTTL=1", |
| 823 |
"Mark=1", |
| 824 |
"Mark=0", |
| 825 |
"Mark=255", |
| 826 |
|
| 827 |
/* IP TOS properties */ |
| 828 |
"IPTOS=0", |
| 829 |
"IPTOS=low-delay", |
| 830 |
"IPTOS=throughput", |
| 831 |
"IPTOS=reliability", |
| 832 |
"IPTOS=low-cost", |
| 833 |
|
| 834 |
/* Unsigned integer properties */ |
| 835 |
"Backlog=0", |
| 836 |
"Backlog=128", |
| 837 |
"MaxConnections=64", |
| 838 |
"MaxConnectionsPerSource=10", |
| 839 |
"KeepAliveProbes=9", |
| 840 |
"TriggerLimitBurst=10", |
| 841 |
"PollLimitBurst=10", |
| 842 |
|
| 843 |
/* Mode properties */ |
| 844 |
"SocketMode=0666", |
| 845 |
"SocketMode=644", |
| 846 |
"DirectoryMode=0755", |
| 847 |
"DirectoryMode=0", |
| 848 |
|
| 849 |
/* 64-bit integer properties */ |
| 850 |
"MessageQueueMaxMessages=10", |
| 851 |
"MessageQueueMessageSize=8192", |
| 852 |
|
| 853 |
/* Timespan properties */ |
| 854 |
"TimeoutSec=90s", |
| 855 |
"TimeoutSec=5min", |
| 856 |
"TimeoutSec=infinity", |
| 857 |
"KeepAliveTimeSec=7200s", |
| 858 |
"KeepAliveTimeSec=2h", |
| 859 |
"KeepAliveTimeSec=30min", |
| 860 |
"KeepAliveIntervalSec=75s", |
| 861 |
"KeepAliveIntervalSec=1min", |
| 862 |
"KeepAliveIntervalSec=30s", |
| 863 |
"DeferAcceptSec=1w", |
| 864 |
"TriggerLimitIntervalSec=2s", |
| 865 |
"PollLimitIntervalSec=2s", |
| 866 |
"DeferTriggerMaxSec=infinity", |
| 867 |
|
| 868 |
/* Size properties */ |
| 869 |
"ReceiveBuffer=262144", |
| 870 |
"ReceiveBuffer=1M", |
| 871 |
"ReceiveBuffer=512K", |
| 872 |
"SendBuffer=1.M", // TODO: should this accept multiple components? |
| 873 |
"PipeSize=512K", |
| 874 |
|
| 875 |
/* Exec command properties */ |
| 876 |
"ExecStartPre=true", |
| 877 |
"ExecStartPost=false", |
| 878 |
"ExecReload=kill", |
| 879 |
"ExecStopPost=signal", |
| 880 |
|
| 881 |
/* More string properties */ |
| 882 |
"SmackLabel=mylabel", |
| 883 |
"SmackLabel=_", |
| 884 |
"SmackLabelIPIn=mylabel", |
| 885 |
"SmackLabelIPIn=_", |
| 886 |
"SmackLabelIPOut=mylabel", |
| 887 |
"SmackLabelIPOut=_", |
| 888 |
"TCPCongestion=cubic", |
| 889 |
"TCPCongestion=reno", |
| 890 |
"TCPCongestion=bbr", |
| 891 |
"BindToDevice=eth0", |
| 892 |
"BindToDevice=wlan0", |
| 893 |
"BindToDevice=lo", |
| 894 |
"BindIPv6Only=default", |
| 895 |
"BindIPv6Only=both", |
| 896 |
"BindIPv6Only=ipv6-only", |
| 897 |
"FileDescriptorName=myfd", |
| 898 |
"FileDescriptorName=socket", |
| 899 |
"FileDescriptorName=listener", |
| 900 |
"SocketUser=myuser", |
| 901 |
"SocketUser=www-data", |
| 902 |
"SocketGroup=mygroup", |
| 903 |
"SocketGroup=www-data", |
| 904 |
"Timestamping=off", |
| 905 |
"Timestamping=us", |
| 906 |
"Timestamping=ns", |
| 907 |
"DeferTrigger=on", |
| 908 |
"DeferTrigger=off", |
| 909 |
"DeferTrigger=all", |
| 910 |
|
| 911 |
/* Path strv */ |
| 912 |
"Symlinks=/var/lib/socket/link", |
| 913 |
"Symlinks=/var/lib/socket/link /tmp/socket-link non/abs/path", |
| 914 |
|
| 915 |
/* Socket protocol properties */ |
| 916 |
"SocketProtocol=udp", |
| 917 |
"SocketProtocol=tcp", |
| 918 |
"SocketProtocol=sctp", |
| 919 |
|
| 920 |
/* Listen* properties */ |
| 921 |
"ListenStream=8080", |
| 922 |
"ListenStream=127.0.0.1:8080", |
| 923 |
"ListenStream=[::1]:8080", |
| 924 |
"ListenStream=/run/myservice.sock", |
| 925 |
"ListenDatagram=8080", |
| 926 |
"ListenDatagram=127.0.0.1:8080", |
| 927 |
"ListenDatagram=[::1]:8080", |
| 928 |
"ListenDatagram=/run/myservice.sock", |
| 929 |
"ListenSequentialPacket=/run/myservice.sock", |
| 930 |
"ListenSequentialPacket=/tmp/socket", |
| 931 |
"ListenNetlink=kobject-uevent", |
| 932 |
"ListenNetlink=audit", |
| 933 |
"ListenNetlink=route", |
| 934 |
"ListenSpecial=/dev/log", |
| 935 |
"ListenSpecial=/dev/kmsg", |
| 936 |
"ListenSpecial=/proc/kmsg", |
| 937 |
"ListenMessageQueue=/myqueue", |
| 938 |
"ListenMessageQueue=/system/queue", |
| 939 |
"ListenFIFO=/var/lib/myservice/fifo", |
| 940 |
"ListenFIFO=/tmp/myfifo", |
| 941 |
"ListenUSBFunction=/dev/usb-ffs/myfunction" |
| 942 |
); |
| 943 |
test_transient_settings_one(UNIT_SOCKET, lines); |
| 944 |
} |
| 945 |
|
| 946 |
TEST(timer_properties) { |
| 947 |
const char* const *lines = STRV_MAKE_CONST( |
| 948 |
"WakeSystem=true", |
| 949 |
"RemainAfterElapse=yes", |
| 950 |
"Persistent=true", |
| 951 |
"OnTimezoneChange=yes", |
| 952 |
"OnClockChange=true", |
| 953 |
"FixedRandomDelay=yes", |
| 954 |
"DeferReactivation=true", |
| 955 |
|
| 956 |
"AccuracySec=1s", |
| 957 |
"AccuracySec=10min", |
| 958 |
"AccuracySec=1h", |
| 959 |
"RandomizedDelaySec=30s", |
| 960 |
"RandomizedDelaySec=5min", |
| 961 |
"RandomizedDelaySec=0", |
| 962 |
"RandomizedOffsetSec=15s", |
| 963 |
"RandomizedOffsetSec=2min", |
| 964 |
"OnActiveSec=10s", |
| 965 |
"OnActiveSec=5min", |
| 966 |
"OnBootSec=30s", |
| 967 |
"OnBootSec=2min", |
| 968 |
"OnStartupSec=45s", |
| 969 |
"OnStartupSec=1min", |
| 970 |
"OnUnitActiveSec=20s", |
| 971 |
"OnUnitActiveSec=10min", |
| 972 |
"OnUnitInactiveSec=60s", |
| 973 |
"OnUnitInactiveSec=30min", |
| 974 |
"OnCalendar=daily", |
| 975 |
"OnCalendar=Mon,Tue *-*-* 12:00:00", |
| 976 |
"OnCalendar=*-*-* 06:00:00", |
| 977 |
"OnCalendar=Sat *-*-* 23:00:00" |
| 978 |
); |
| 979 |
|
| 980 |
test_transient_settings_one(UNIT_TIMER, lines); |
| 981 |
} |
| 982 |
|
| 983 |
TEST(unit_properties) { |
| 984 |
const char* const *lines = STRV_MAKE_CONST( |
| 985 |
"Description=My Service Unit", |
| 986 |
"SourcePath=/etc/systemd/system/myservice.service", |
| 987 |
"SourcePath=non/abs/lib/systemd/system/backup.service", |
| 988 |
"OnFailureJobMode=replace", |
| 989 |
"OnFailureJobMode=fail", |
| 990 |
"OnFailureJobMode=isolate", |
| 991 |
"JobTimeoutAction=none", |
| 992 |
"JobTimeoutAction=reboot", |
| 993 |
"JobTimeoutAction=poweroff", |
| 994 |
"JobTimeoutRebootArgument=emergency", |
| 995 |
"JobTimeoutRebootArgument=--force", |
| 996 |
"StartLimitAction=none", |
| 997 |
"StartLimitAction=reboot", |
| 998 |
"StartLimitAction=reboot-force", |
| 999 |
"FailureAction=none", |
| 1000 |
"FailureAction=restart", |
| 1001 |
"FailureAction=reboot", |
| 1002 |
"SuccessAction=none", |
| 1003 |
"SuccessAction=poweroff", |
| 1004 |
"SuccessAction=exit", |
| 1005 |
"RebootArgument=--force", |
| 1006 |
"RebootArgument=emergency", |
| 1007 |
"CollectMode=inactive", |
| 1008 |
"CollectMode=inactive-or-failed", |
| 1009 |
"StopWhenUnneeded=true", |
| 1010 |
"StopWhenUnneeded=false", |
| 1011 |
"RefuseManualStart=yes", |
| 1012 |
"RefuseManualStart=no", |
| 1013 |
"RefuseManualStop=true", |
| 1014 |
"RefuseManualStop=false", |
| 1015 |
"AllowIsolate=yes", |
| 1016 |
"AllowIsolate=no", |
| 1017 |
"IgnoreOnIsolate=true", |
| 1018 |
"IgnoreOnIsolate=false", |
| 1019 |
"SurviveFinalKillSignal=yes", |
| 1020 |
"SurviveFinalKillSignal=no", |
| 1021 |
"DefaultDependencies=true", |
| 1022 |
"DefaultDependencies=false", |
| 1023 |
"JobTimeoutSec=90s", |
| 1024 |
"JobTimeoutSec=5min", |
| 1025 |
"JobTimeoutSec=infinity", |
| 1026 |
"JobRunningTimeoutSec=30min", |
| 1027 |
"JobRunningTimeoutSec=1h", |
| 1028 |
"StartLimitIntervalSec=10s", |
| 1029 |
"StartLimitIntervalSec=60s", |
| 1030 |
"StartLimitBurst=5", |
| 1031 |
"StartLimitBurst=9999999", |
| 1032 |
"StartLimitBurst=0", |
| 1033 |
"SuccessActionExitStatus=0", |
| 1034 |
"SuccessActionExitStatus=", |
| 1035 |
"FailureActionExitStatus=1", |
| 1036 |
"FailureActionExitStatus=", |
| 1037 |
"Documentation=man:myservice(8)", |
| 1038 |
"Documentation=https://example.com/docs", |
| 1039 |
"Documentation=file:/usr/share/doc/myservice/README", |
| 1040 |
"RequiresMountsFor=/var/lib/myservice", |
| 1041 |
"RequiresMountsFor=\t\t\t \t/home\t\t\t\t\t/var/log \t", |
| 1042 |
"WantsMountsFor=/tmp", |
| 1043 |
"WantsMountsFor=/opt /usr/local", |
| 1044 |
"Markers=manual", |
| 1045 |
"Markers=needs-reload", |
| 1046 |
"Markers=manual needs-reload", |
| 1047 |
|
| 1048 |
|
| 1049 |
"Requires=a.service b.service", |
| 1050 |
"Requisite=a.service b.service", |
| 1051 |
"Wants=a.service b.service", |
| 1052 |
"BindsTo=a.service b.service", |
| 1053 |
"PartOf=a.service b.service", |
| 1054 |
"Upholds=a.service b.service", |
| 1055 |
"RequiredBy=a.service b.service", |
| 1056 |
"RequisiteOf=a.service b.service", |
| 1057 |
"WantedBy=a.service b.service", |
| 1058 |
"BoundBy=a.service b.service", |
| 1059 |
"ConsistsOf=a.service b.service", |
| 1060 |
"UpheldBy=a.service b.service", |
| 1061 |
"Conflicts=a.service b.service", |
| 1062 |
"ConflictedBy=a.service b.service", |
| 1063 |
"Before=a.service b.service", |
| 1064 |
"After=a.service b.service", |
| 1065 |
"OnSuccess=a.service b.service", |
| 1066 |
"OnSuccessOf=a.service b.service", |
| 1067 |
"OnFailure=a.service b.service", |
| 1068 |
"OnFailureOf=a.service b.service", |
| 1069 |
"Triggers=a.service b.service", |
| 1070 |
"TriggeredBy=a.service b.service", |
| 1071 |
"PropagatesReloadTo=a.service b.service", |
| 1072 |
"ReloadPropagatedFrom=a.service b.service", |
| 1073 |
"PropagatesStopTo=a.service b.service", |
| 1074 |
"StopPropagatedFrom=a.service b.service", |
| 1075 |
"JoinsNamespaceOf=a.service b.service", |
| 1076 |
"References=a.service b.service", |
| 1077 |
"ReferencedBy=a.service b.service", |
| 1078 |
"InSlice=a.service b.service", |
| 1079 |
"SliceOf=a.service b.service", |
| 1080 |
|
| 1081 |
// TODO: do better verification here? |
| 1082 |
"ConditionArchitecture=aarch64", |
| 1083 |
"ConditionArchitecture=|!aarch64", |
| 1084 |
"ConditionArchitecture=!aarch64", |
| 1085 |
"ConditionArchitecture=|aarch64", |
| 1086 |
"ConditionArchitecture=|!", |
| 1087 |
"ConditionFirmware=something", |
| 1088 |
"ConditionVirtualization=|foo", |
| 1089 |
"ConditionHost=|foo", |
| 1090 |
"ConditionKernelCommandLine=|foo", |
| 1091 |
"ConditionVersion=|foo", |
| 1092 |
"ConditionCredential=|foo", |
| 1093 |
"ConditionSecurity=|foo", |
| 1094 |
"ConditionCapability=|foo", |
| 1095 |
"ConditionACPower=|foo", |
| 1096 |
"ConditionMemory=|foo", |
| 1097 |
"ConditionCPUs=|foo", |
| 1098 |
"ConditionEnvironment=|foo", |
| 1099 |
"ConditionCPUFeature=|foo", |
| 1100 |
"ConditionOSRelease=|foo", |
| 1101 |
"ConditionMemoryPressure=|foo", |
| 1102 |
"ConditionCPUPressure=|foo", |
| 1103 |
"ConditionIOPressure=|foo", |
| 1104 |
"ConditionNeedsUpdate=|foo", |
| 1105 |
"ConditionFirstBoot=|foo", |
| 1106 |
"ConditionPathExists=|foo", |
| 1107 |
"ConditionPathExistsGlob=|foo", |
| 1108 |
"ConditionPathIsDirectory=|foo", |
| 1109 |
"ConditionPathIsSymbolicLink=|foo", |
| 1110 |
"ConditionPathIsMountPoint=|foo", |
| 1111 |
"ConditionPathIsReadWrite=|foo", |
| 1112 |
"ConditionPathIsEncrypted=|foo", |
| 1113 |
"ConditionPathIsSocket=|foo", |
| 1114 |
"ConditionDirectoryNotEmpty=|foo", |
| 1115 |
"ConditionFileNotEmpty=|foo", |
| 1116 |
"ConditionFileIsExecutable=|foo", |
| 1117 |
"ConditionUser=|foo", |
| 1118 |
"ConditionGroup=|foo", |
| 1119 |
"ConditionControlGroupController=|foo", |
| 1120 |
"ConditionKernelModuleLoaded=|foo", |
| 1121 |
"AssertArchitecture=|foo", |
| 1122 |
"AssertFirmware=|foo", |
| 1123 |
"AssertVirtualization=|foo", |
| 1124 |
"AssertHost=|foo", |
| 1125 |
"AssertKernelCommandLine=|foo", |
| 1126 |
"AssertVersion=|foo", |
| 1127 |
"AssertCredential=|foo", |
| 1128 |
"AssertSecurity=|foo", |
| 1129 |
"AssertCapability=|foo", |
| 1130 |
"AssertACPower=|foo", |
| 1131 |
"AssertMemory=|foo", |
| 1132 |
"AssertCPUs=|foo", |
| 1133 |
"AssertEnvironment=|foo", |
| 1134 |
"AssertCPUFeature=|foo", |
| 1135 |
"AssertOSRelease=|foo", |
| 1136 |
"AssertMemoryPressure=|foo", |
| 1137 |
"AssertCPUPressure=|foo", |
| 1138 |
"AssertIOPressure=|foo", |
| 1139 |
"AssertNeedsUpdate=|foo", |
| 1140 |
"AssertFirstBoot=|foo", |
| 1141 |
"AssertPathExists=|foo", |
| 1142 |
"AssertPathExistsGlob=|foo", |
| 1143 |
"AssertPathIsDirectory=|foo", |
| 1144 |
"AssertPathIsSymbolicLink=|foo", |
| 1145 |
"AssertPathIsMountPoint=|foo", |
| 1146 |
"AssertPathIsReadWrite=|foo", |
| 1147 |
"AssertPathIsEncrypted=|foo", |
| 1148 |
"AssertPathIsSocket=|foo", |
| 1149 |
"AssertDirectoryNotEmpty=|foo", |
| 1150 |
"AssertFileNotEmpty=|foo", |
| 1151 |
"AssertFileIsExecutable=|foo", |
| 1152 |
"AssertUser=|foo", |
| 1153 |
"AssertGroup=|foo", |
| 1154 |
"AssertControlGroupController=|foo", |
| 1155 |
"AssertKernelModuleLoaded=|foo" |
| 1156 |
); |
| 1157 |
|
| 1158 |
test_transient_settings_one(UNIT_TARGET, lines); |
| 1159 |
/* All unit types. */ |
| 1160 |
} |
| 1161 |
|
| 1162 |
TEST(bus_dump_transient_settings) { |
| 1163 |
for (UnitType t = 0; t < _UNIT_TYPE_MAX; t++) { |
| 1164 |
log_info("==================== %s ====================", t < 0 ? "unit" : unit_type_to_string(t)); |
| 1165 |
bus_dump_transient_settings(t); |
| 1166 |
} |
| 1167 |
} |
| 1168 |
|
| 1169 |
static int intro(void) { |
| 1170 |
int r; |
| 1171 |
|
| 1172 |
r = sd_bus_default_user(&arg_bus); |
| 1173 |
if (r < 0) |
| 1174 |
r = sd_bus_default_system(&arg_bus); |
| 1175 |
if (r < 0) |
| 1176 |
log_info_errno(r, "Failed to connect to bus: %m"); |
| 1177 |
|
| 1178 |
return EXIT_SUCCESS; |
| 1179 |
} |
| 1180 |
|
| 1181 |
DEFINE_TEST_MAIN_WITH_INTRO(LOG_DEBUG, intro); |