From 5ae89ef34774a777c5af7af48b1ad431d10a425e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 28 Apr 2023 16:56:39 +0200 Subject: core/systemctl: when switching root default to /sysroot/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We hardcode the path the initrd uses to prepare the final mount point at so many places, let's also imply it in "systemctl switch-root" if not specified. This adds the fallback both to systemctl and to PID 1 (this is because both to — different – checks on the path). --- src/core/dbus-manager.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 2feec0bd7d..f6c9ae6940 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1738,15 +1738,21 @@ static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_er if (r < 0) return r; - if (!path_is_valid(root)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "New root directory must be a valid path."); - if (!path_is_absolute(root)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "New root path '%s' is not absolute.", root); - if (path_equal(root, "/")) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "New root directory cannot be the old root directory."); + if (isempty(root)) + /* If path is not specified, default to "/sysroot" which is what we generally expect initrds + * to use */ + root = "/sysroot"; + else { + if (!path_is_valid(root)) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, + "New root directory must be a valid path."); + if (!path_is_absolute(root)) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, + "New root path '%s' is not absolute.", root); + if (path_equal(root, "/")) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, + "New root directory cannot be the old root directory."); + } /* Safety check */ if (isempty(init)) { -- cgit v1.2.1