From 8ba6ef14967713bd06a9fbb3bcc6dedc2748a6f3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 2 Nov 2015 11:17:24 +0100 Subject: [PATCH] Setup: fix bad /dev bindmount Hotplug changes will create a Setup instance with a rootdir of /proc/$pid/root. Bindmounts on directories inside there are broken. Also the exitstatus of Setup::protected_call used the wrong process' $?. --- debian/changelog | 2 ++ src/PVE/LXC/Setup.pm | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1158080..1c686d9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,8 @@ pve-container (1.0-20) unstable; urgency=medium * fix bug #799: resize running CT with no loopdev. + * Setup: fix bad /dev bindmount + -- Proxmox Support Team Mon, 02 Nov 2015 11:16:25 +0100 pve-container (1.0-19) unstable; urgency=medium diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm index abf696d..5ebda97 100644 --- a/src/PVE/LXC/Setup.pm +++ b/src/PVE/LXC/Setup.pm @@ -71,12 +71,15 @@ sub protected_call { my $child = fork(); die "fork failed: $!\n" if !defined($child); + # can't bind to /proc/$pid/root/dev, it'll bind to the host's /dev + my $mountdev = ($rootdir !~ m@^/proc@); + if (!$child) { # avoid recursive forks $self->{in_chroot} = 1; $self->{plugin}->{in_chroot} = 1; eval { - PVE::Tools::run_command(['mount', '--bind', '/dev', "$rootdir/dev"]); + PVE::Tools::run_command(['mount', '--bind', '/dev', "$rootdir/dev"]) if $mountdev; chroot($rootdir) or die "failed to change root to: $rootdir: $!\n"; chdir('/') or die "failed to change to root directory\n"; $sub->(); @@ -88,9 +91,12 @@ sub protected_call { POSIX::_exit(0); } while (waitpid($child, 0) != $child) {} - eval { PVE::Tools::run_command(['umount', "$rootdir/dev"]); }; - warn $@ if $@; - return $? == 0; + my $status = $? == 0; + if ($mountdev) { + eval { PVE::Tools::run_command(['umount', "$rootdir/dev"]); }; + warn $@ if $@; + } + return $status; } sub template_fixup { -- 2.39.5