-static bool prepare_new_root(void) {
- int r = false;
- const char *dirs[] = { "/run/initramfs/oldroot",
- "/run/initramfs/proc",
- "/run/initramfs/sys",
- "/run/initramfs/dev",
- "/run/initramfs/run",
- NULL };
- const char **dir;
- const char *msg;
-
- msg = "Failed to mount bind /run/initramfs on /run/initramfs";
- if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) != 0)
- goto out;
-
- msg="Failed to make /run/initramfs private mount %m:";
- if (mount(NULL, "/run/initramfs", NULL, MS_PRIVATE, NULL) != 0)
- goto out;
-
- for (dir = &dirs[0]; *dir != NULL; dir++) {
- asprintf((char **) &msg, "mkdir %s: %%m", *dir);
- if (mkdir(*dir, 0755) != 0) {
- if (errno != EEXIST)
- goto out;
+static int prepare_new_root(void) {
+ static const char dirs[] =
+ "/run/initramfs/oldroot\0"
+ "/run/initramfs/proc\0"
+ "/run/initramfs/sys\0"
+ "/run/initramfs/dev\0"
+ "/run/initramfs/run\0";
+
+ const char *dir;
+
+ if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) {
+ log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m");
+ return -errno;
+ }
+
+ if (mount(NULL, "/run/initramfs", NULL, MS_PRIVATE, NULL) < 0) {
+ log_error("Failed to make /run/initramfs private mount: %m");
+ return -errno;
+ }
+
+ NULSTR_FOREACH(dir, dirs)
+ if (mkdir_p(dir, 0755) < 0 && errno != EEXIST) {
+ log_error("Failed to mkdir %s: %m", dir);
+ return -errno;