if (switch_root_dir) {
r = switch_root(/* new_root= */ switch_root_dir,
/* old_root_after= */ NULL,
- /* destroy_old_root= */ objective == MANAGER_SWITCH_ROOT);
+ /* flags= */ objective == MANAGER_SWITCH_ROOT ? SWITCH_ROOT_DESTROY_OLD_ROOT : 0);
if (r < 0)
log_error_errno(r, "Failed to switch root, trying to continue: %m");
}
int switch_root(const char *new_root,
const char *old_root_after, /* path below the new root, where to place the old root after the transition; may be NULL to unmount it */
- bool destroy_old_root) {
+ SwitchRootFlags flags) {
struct {
const char *path;
return 0;
}
- istmp = fd_is_temporary_fs(old_root_fd);
- if (istmp < 0)
- return log_error_errno(istmp, "Failed to stat root directory: %m");
- if (istmp > 0)
- log_debug("Root directory is on tmpfs, will do cleanup later.");
+ if (FLAGS_SET(flags, SWITCH_ROOT_DESTROY_OLD_ROOT)) {
+ istmp = fd_is_temporary_fs(old_root_fd);
+ if (istmp < 0)
+ return log_error_errno(istmp, "Failed to stat root directory: %m");
+ if (istmp > 0)
+ log_debug("Root directory is on tmpfs, will do cleanup later.");
+ } else
+ istmp = -1; /* don't know */
if (old_root_after) {
/* Determine where we shall place the old root after the transition */
return log_error_errno(errno, "Failed to change directory: %m");
}
- if (istmp && destroy_old_root) {
+ if (istmp > 0) {
struct stat rb;
if (fstat(old_root_fd, &rb) < 0)
#include <stdbool.h>
-int switch_root(const char *new_root, const char *old_root_after, bool destroy_old_root);
+typedef enum SwitchRootFlags {
+ SWITCH_ROOT_DESTROY_OLD_ROOT = 1 << 0, /* rm -rf old root when switching – under the condition that it is backed by non-persistent tmpfs/ramfs/… */
+} SwitchRootFlags;
+
+int switch_root(const char *new_root, const char *old_root_after, SwitchRootFlags flags);
return switch_root(
/* new_root= */ "/run/initramfs",
/* old_root_after= */ "/oldroot",
- /* destroy_old_root= */ false);
+ /* flags= */ 0);
}
/* Read the following fields from /proc/meminfo: