+static int do_switch_root(const char *switch_root) {
+ int r;
+
+ if (path_equal(switch_root, "/"))
+ return 0;
+
+ if (chdir(switch_root) < 0) {
+ r = -errno;
+ goto fail;
+ }
+
+ if (mount(switch_root, "/", NULL, MS_MOVE, NULL) < 0) {
+ r = -errno;
+ chdir("/");
+ goto fail;
+ }
+
+ if (chroot(".") < 0)
+ log_warning("Failed to change root, ignoring: %m");
+
+ /* FIXME: remove old root */
+
+ return 0;
+
+fail:
+ log_error("Failed to switch root, ignoring: %s", strerror(-r));
+
+ return r;
+}
+