test-execute: check if private directories have bad permissions before running test_exec_dynamicuser()

If the directory (/var/lib/private is most likely) has borked permissions, the
test will fail with a cryptic message and EXIT_STATE_DIRECTORY or similar. The
message from the child with more details gets lost somewhere. Let's avoid running
the test in that case and provide a simple error message instead.

E.g. systemd-238-12.git07f8cd5.fc28.ppc64 (which I encountered on a test machine)
has /var/lib/private with 0755.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-09-04 18:02:57 +02:00
parent 9978e631cd
commit cced2b98ef
1 changed files with 22 additions and 0 deletions

View File

@ -543,7 +543,29 @@ static void test_exec_supplementarygroups(Manager *m) {
test(__func__, m, "exec-supplementarygroups-multiple-groups-withuid.service", 0, CLD_EXITED);
}
static char* private_directory_bad(Manager *m) {
/* This mirrors setup_exec_directory(). */
for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
_cleanup_free_ char *p = NULL;
struct stat st;
assert_se(p = path_join(m->prefix[dt], "private"));
if (stat(p, &st) >= 0 &&
(st.st_mode & (S_IRWXG|S_IRWXO)))
return TAKE_PTR(p);
}
return NULL;
}
static void test_exec_dynamicuser(Manager *m) {
_cleanup_free_ char *bad = private_directory_bad(m);
if (bad) {
log_warning("%s: %s has bad permissions, skipping test.", __func__, bad);
return;
}
test(__func__, m, "exec-dynamicuser-fixeduser.service", can_unshare ? 0 : EXIT_NAMESPACE, CLD_EXITED);
if (check_user_has_group_with_same_name("adm"))