diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-04-28 16:56:39 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2023-04-28 23:26:20 +0100 |
commit | 5ae89ef34774a777c5af7af48b1ad431d10a425e (patch) | |
tree | 54c2755ddf182ea784e38633b2cc5340a84f1bde /src/core | |
parent | 77b7026668cd376744a99881777dce8c2f5da835 (diff) | |
download | systemd-5ae89ef34774a777c5af7af48b1ad431d10a425e.tar.gz |
core/systemctl: when switching root default to /sysroot/
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).
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/dbus-manager.c | 24 |
1 files changed, 15 insertions, 9 deletions
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)) { |