diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-08-25 18:39:23 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-09-02 09:56:24 +0200 |
commit | 4da159bc53d3db4a98c923d3f57d656713ff5813 (patch) | |
tree | eb0bb7120e7151c71bb454fef37c21c846b0e5b1 /src/systemctl/systemctl-switch-root.c | |
parent | core,systemctl: refuse switching root to current root properly (diff) | |
download | systemd-4da159bc53d3db4a98c923d3f57d656713ff5813.tar.xz systemd-4da159bc53d3db4a98c923d3f57d656713ff5813.zip |
core,systemctl: refuse switching root if we're not in initrd
Diffstat (limited to 'src/systemctl/systemctl-switch-root.c')
-rw-r--r-- | src/systemctl/systemctl-switch-root.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/systemctl/systemctl-switch-root.c b/src/systemctl/systemctl-switch-root.c index cc31cf0e19..ae4a1a72c2 100644 --- a/src/systemctl/systemctl-switch-root.c +++ b/src/systemctl/systemctl-switch-root.c @@ -5,6 +5,7 @@ #include "bus-locator.h" #include "chase.h" #include "fd-util.h" +#include "initrd-util.h" #include "parse-util.h" #include "path-util.h" #include "proc-cmdline.h" @@ -63,6 +64,9 @@ int verb_switch_root(int argc, char *argv[], void *userdata) { } else root = "/sysroot"; + if (!in_initrd()) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not in initrd, refusing switch-root operation."); + if (argc >= 3) init = argv[2]; else { |