summaryrefslogtreecommitdiff
path: root/src/shared/switch-root.c
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 00:42:49 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 00:42:49 -0500
commitccef261c077d31dce02aa92e519b23b3a2a58303 (patch)
tree582fafc98c76e98e912f453fb55ca57f29273d57 /src/shared/switch-root.c
parent5d4922bba91c6d60b3b9f38fb29fda0f6ba8338d (diff)
parent5fb2a20a29c2cc0494d5a31e175a8e3ff0b2d3e2 (diff)
Merge tag 'systemd/v232-4.parabola1' into systemd/parabola
Diffstat (limited to 'src/shared/switch-root.c')
-rw-r--r--src/shared/switch-root.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c
index 47d3a5a1fa..4eff4f692e 100644
--- a/src/shared/switch-root.c
+++ b/src/shared/switch-root.c
@@ -75,17 +75,29 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,
NULSTR_FOREACH(i, move_mounts) {
char new_mount[PATH_MAX];
struct stat sb;
+ size_t n;
- xsprintf(new_mount, "%s%s", new_root, i);
+ n = snprintf(new_mount, sizeof new_mount, "%s%s", new_root, i);
+ if (n >= sizeof new_mount) {
+ bool move = mountflags & MS_MOVE;
+
+ log_warning("New path is too long, %s: %s%s",
+ move ? "forcing unmount instead" : "ignoring",
+ new_root, i);
+
+ if (move)
+ if (umount2(i, MNT_FORCE) < 0)
+ log_warning_errno(errno, "Failed to unmount %s: %m", i);
+ continue;
+ }
mkdir_p_label(new_mount, 0755);
- if ((stat(new_mount, &sb) < 0) ||
+ if (stat(new_mount, &sb) < 0 ||
sb.st_dev != new_root_stat.st_dev) {
/* Mount point seems to be mounted already or
- * stat failed. Unmount the old mount
- * point. */
+ * stat failed. Unmount the old mount point. */
if (umount2(i, MNT_DETACH) < 0)
log_warning_errno(errno, "Failed to unmount %s: %m", i);
continue;
@@ -97,10 +109,9 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot,
if (umount2(i, MNT_FORCE) < 0)
log_warning_errno(errno, "Failed to unmount %s: %m", i);
- }
- if (mountflags & MS_BIND)
- log_error_errno(errno, "Failed to bind mount %s to %s: %m", i, new_mount);
+ } else if (mountflags & MS_BIND)
+ log_error_errno(errno, "Failed to bind mount %s to %s: %m", i, new_mount);
}
}