]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/switch-root.c
Merge pull request #2147 from vcaputo/sd-event-measure-latencies
[thirdparty/systemd.git] / src / shared / switch-root.c
index e8cedc69cc023f0a4dc41ade35932ba9dbb295ba..bf0739e5fa09d28bbea9215807c78db6b6b90f16 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/stat.h>
-#include <stdbool.h>
 #include <errno.h>
-#include <string.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdio.h>
 #include <sys/mount.h>
+#include <sys/stat.h>
 #include <unistd.h>
-#include <fcntl.h>
 
-#include "util.h"
-#include "path-util.h"
-#include "switch-root.h"
-#include "mkdir.h"
 #include "base-filesystem.h"
+#include "fd-util.h"
+#include "log.h"
 #include "missing.h"
+#include "mkdir.h"
+#include "path-util.h"
+#include "rm-rf.h"
+#include "stdio-util.h"
+#include "string-util.h"
+#include "switch-root.h"
+#include "user-util.h"
+#include "util.h"
 
 int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,  unsigned long mountflags) {
 
@@ -51,7 +58,7 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,
         if (path_equal(new_root, "/"))
                 return 0;
 
-        temporary_old_root = strappenda(new_root, oldroot);
+        temporary_old_root = strjoina(new_root, oldroot);
         mkdir_p_label(temporary_old_root, 0755);
 
         old_root_remove = in_initrd();
@@ -71,7 +78,7 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,
                 char new_mount[PATH_MAX];
                 struct stat sb;
 
-                snprintf(new_mount, sizeof(new_mount), "%s%s", new_root, i);
+                xsprintf(new_mount, "%s%s", new_root, i);
 
                 mkdir_p_label(new_mount, 0755);
 
@@ -104,7 +111,7 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,
          * to look like. They might even boot, if they are RO and
          * don't have the FS layout. Just ignore the error and
          * switch_root() nevertheless. */
-        (void) base_filesystem_create(new_root);
+        (void) base_filesystem_create(new_root, UID_INVALID, GID_INVALID);
 
         if (chdir(new_root) < 0)
                 return log_error_errno(errno, "Failed to change directory to %s: %m", new_root);
@@ -142,7 +149,7 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,
                 if (fstat(old_root_fd, &rb) < 0)
                         log_warning_errno(errno, "Failed to stat old root directory, leaving: %m");
                 else {
-                        rm_rf_children(old_root_fd, false, false, &rb);
+                        (void) rm_rf_children(old_root_fd, 0, &rb);
                         old_root_fd = -1;
                 }
         }