Skip to content

Commit 5ed087f

Browse files
committed
generators: skip private tmpfs if /tmp does not exist
When spawning generators within a sandbox we want a private /tmp, but it might not exist, and on some systems we might be unable to create it because users want a BTRFS subvolume instead. Fixes systemd/systemd#27436 (cherry picked from commit b8fba0c)
1 parent 93143b6 commit 5ed087f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/core/manager.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,6 +3855,7 @@ static int manager_execute_generators(Manager *m, char **paths, bool remount_ro)
38553855
}
38563856

38573857
static int manager_run_generators(Manager *m) {
3858+
ForkFlags flags = FORK_RESET_SIGNALS | FORK_WAIT | FORK_NEW_MOUNTNS | FORK_MOUNTNS_SLAVE;
38583859
_cleanup_strv_free_ char **paths = NULL;
38593860
int r;
38603861

@@ -3885,9 +3886,12 @@ static int manager_run_generators(Manager *m) {
38853886
goto finish;
38863887
}
38873888

3888-
r = safe_fork("(sd-gens)",
3889-
FORK_RESET_SIGNALS | FORK_WAIT | FORK_NEW_MOUNTNS | FORK_MOUNTNS_SLAVE | FORK_PRIVATE_TMP,
3890-
NULL);
3889+
/* On some systems /tmp/ doesn't exist, and on some other systems we cannot create it at all. Avoid
3890+
* trying to mount a private tmpfs on it as there's no one size fits all. */
3891+
if (is_dir("/tmp", /* follow= */ false) > 0)
3892+
flags |= FORK_PRIVATE_TMP;
3893+
3894+
r = safe_fork("(sd-gens)", flags, NULL);
38913895
if (r == 0) {
38923896
r = manager_execute_generators(m, paths, /* remount_ro= */ true);
38933897
_exit(r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE);

0 commit comments

Comments
 (0)