Add bind points for /dev/ and /etc/resolv.conf into the container when exec'ing

This commit is contained in:
Gregory Kurtzer
2020-12-06 10:00:04 -08:00
parent bbfe1023e9
commit 9de9778648

View File

@@ -1,13 +1,15 @@
// +build linux
// + build linux
package child
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/container"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/spf13/cobra"
"os"
"path"
"syscall"
)
@@ -25,10 +27,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}
syscall.Mount("", "/", "", syscall.MS_PRIVATE, "")
containerPath := container.RootFsDir(containerName)
syscall.Mount("", "/", "", syscall.MS_PRIVATE, "")
syscall.Mount("/dev", path.Join(containerPath, "/dev"), "", syscall.MS_BIND, "")
if util.IsFile(path.Join(containerPath, "/etc/resolv.conf")) == true {
syscall.Mount("/etc/resolv.conf", path.Join(containerPath, "/etc/resolv.conf"), "", syscall.MS_BIND, "")
}
syscall.Chroot(containerPath)
os.Chdir("/")