1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-26 08:55:40 +03:00

core: Adjust ExecDirectory-Stdout test to use DynamicUser

For test environments that set e.g. $RUNTIME_DIRECTORY to
/run/fake-runtime-dir, the test service file can't properly define the
StandardOutput path, as it must be absolute.

Instead, try using DynamicUser & StateDirectory, which should result in an
appropriate directory always seen at /var/lib/foo
This commit is contained in:
Andrew Potter 2024-10-24 15:41:56 -07:00
parent a2872389e3
commit 353f417f48
3 changed files with 26 additions and 13 deletions

View File

@ -1128,9 +1128,21 @@ static void test_exec_runtimedirectory(Manager *m) {
test(m, "exec-runtimedirectory-owner-" NOBODY_GROUP_NAME ".service", MANAGER_IS_SYSTEM(m) ? 0 : EXIT_GROUP, CLD_EXITED); test(m, "exec-runtimedirectory-owner-" NOBODY_GROUP_NAME ".service", MANAGER_IS_SYSTEM(m) ? 0 : EXIT_GROUP, CLD_EXITED);
} }
static void test_exec_runtimedirectory_stdoutput(Manager *m) { static void test_exec_statedirectory_stdoutput(Manager *m) {
(void) rm_rf("/run/test-exec_runtimedirectory_standardoutput", REMOVE_ROOT|REMOVE_PHYSICAL); if (MANAGER_IS_USER(m)) {
test(m, "exec-runtimedirectory-stdoutput.service", 0, CLD_EXITED); log_notice("Skipping %s for user manager", __func__);
return;
}
_cleanup_free_ char *bad = private_directory_bad(m);
if (bad) {
log_warning("%s: %s has bad permissions, skipping test.", __func__, bad);
return;
}
int status = can_unshare ? 0 : EXIT_NAMESPACE;
test(m, "exec-statedirectory-stdoutput.service", status, CLD_EXITED);
} }
static void test_exec_capabilityboundingset(Manager *m) { static void test_exec_capabilityboundingset(Manager *m) {
@ -1364,7 +1376,7 @@ static void run_tests(RuntimeScope scope, char **patterns) {
entry(test_exec_readwritepaths), entry(test_exec_readwritepaths),
entry(test_exec_restrictnamespaces), entry(test_exec_restrictnamespaces),
entry(test_exec_runtimedirectory), entry(test_exec_runtimedirectory),
entry(test_exec_runtimedirectory_stdoutput), entry(test_exec_statedirectory_stdoutput),
entry(test_exec_specifier), entry(test_exec_specifier),
entry(test_exec_standardinput), entry(test_exec_standardinput),
entry(test_exec_standardoutput), entry(test_exec_standardoutput),

View File

@ -1,9 +0,0 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Unit]
Description=Test for RuntimeDirectory used by StandardOutput
[Service]
ExecStart=sh -c 'printf "hello\nhello\n"'
Type=oneshot
RuntimeDirectory=test-exec_runtimedirectory_standardoutput
StandardOutput=file:/run/test-exec_runtimedirectory_standardoutput/test-exec-runtimedirectory_standardoutput-output

View File

@ -0,0 +1,10 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Unit]
Description=Test for StateDirectory used by StandardOutput
[Service]
ExecStart=sh -c 'printf "hello\nhello\n"'
Type=oneshot
DynamicUser=true
StateDirectory=test-exec_statedirectory_standardoutput
StandardOutput=file:/var/lib/test-exec_statedirectory_standardoutput/test-exec-statedirectory_standardoutput-output