]> git.proxmox.com Git - pve-container.git/commitdiff
prestart-hook: fix starting via lxc-start
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 2 Jan 2020 08:36:05 +0000 (09:36 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 2 Jan 2020 08:36:07 +0000 (09:36 +0100)
When starting via 'lxc-start' from the CLI the prestart hook
ended up mounting relative to the current working dir, so
the container refused to start and we created a bunch of
useless `var` directories.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/lxc-pve-prestart-hook

index 229af8eddc95247fade145d16c8431e2fc431679..1d62f3bdfb07f8d1b7eba97e88bbda67b114d53f 100755 (executable)
@@ -89,23 +89,26 @@ PVE::LXC::Tools::lxc_hook('pre-start', 'lxc', sub {
                $rootgid,
            );
 
-           my $ddir;
+           my ($dest_dir, $dest_base_fd);
            if ($rootdir_fd) {
                # Mount relative to the rootdir fd.
-               $ddir = './' . $mountpoint->{mp};
+               $dest_base_fd = $rootdir_fd;
+               $dest_dir = './' . $mountpoint->{mp};
            } else {
                # Assert that 'rootfs' is the first one:
                die "foreach_mount() error\n" if $opt ne 'rootfs';
 
-               # Mount the rootfs absolutely (rootdir_fd=undef uses AT_FDCWD).
+               # Mount the rootfs absolutely.
                # $rootdir is not controlled by the container, so this is fine.
-               $ddir = $rootdir;
+               sysopen($dest_base_fd, '/', O_PATH | O_DIRECTORY)
+                   or die "failed to open '.': $!\n";
+               $dest_dir = $rootdir;
            }
 
            PVE::LXC::mountpoint_insert_staged(
                $mount_fd,
-               $rootdir_fd,
-               $ddir,
+               $dest_base_fd,
+               $dest_dir,
                $opt,
                $rootuid,
                $rootgid,