summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2023-04-30 19:21:23 +0100
committerLennart Poettering <lennart@poettering.net>2023-05-02 12:28:09 +0200
commitb8fba0cded2c3e14fe8c0b52aae3ecf2c9fa718e (patch)
tree4dc0bf43092c6d489fd173ac8d2754e4827972ab /src/core
parenta3b076f641fab2989745ee057e3576f970e0eff6 (diff)
downloadsystemd-b8fba0cded2c3e14fe8c0b52aae3ecf2c9fa718e.tar.gz
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 https://github.com/systemd/systemd/issues/27436
Diffstat (limited to 'src/core')
-rw-r--r--src/core/manager.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index ce9b27ece7..9e91aba632 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -3959,6 +3959,7 @@ static int manager_execute_generators(Manager *m, char **paths, bool remount_ro)
}
static int manager_run_generators(Manager *m) {
+ ForkFlags flags = FORK_RESET_SIGNALS | FORK_WAIT | FORK_NEW_MOUNTNS | FORK_MOUNTNS_SLAVE;
_cleanup_strv_free_ char **paths = NULL;
int r;
@@ -3989,9 +3990,12 @@ static int manager_run_generators(Manager *m) {
goto finish;
}
- r = safe_fork("(sd-gens)",
- FORK_RESET_SIGNALS | FORK_WAIT | FORK_NEW_MOUNTNS | FORK_MOUNTNS_SLAVE | FORK_PRIVATE_TMP,
- NULL);
+ /* On some systems /tmp/ doesn't exist, and on some other systems we cannot create it at all. Avoid
+ * trying to mount a private tmpfs on it as there's no one size fits all. */
+ if (is_dir("/tmp", /* follow= */ false) > 0)
+ flags |= FORK_PRIVATE_TMP;
+
+ r = safe_fork("(sd-gens)", flags, NULL);
if (r == 0) {
r = manager_execute_generators(m, paths, /* remount_ro= */ true);
_exit(r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE);