Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions pkg/child/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"
"path/filepath"

"github.com/pkg/errors"
"golang.org/x/sys/unix"

"github.com/rootless-containers/rootlesskit/pkg/common"
"github.com/pkg/errors"
)

// generateEtcHosts makes sure the current hostname is resolved into
Expand Down Expand Up @@ -56,11 +56,9 @@ func mountEtcHosts(tempDir string) error {
if err := ioutil.WriteFile(myEtcHosts, newEtcHosts, 0644); err != nil {
return errors.Wrapf(err, "writing %s", myEtcHosts)
}
cmds := [][]string{
{"mount", "--bind", myEtcHosts, "/etc/hosts"},
}
if err := common.Execs(os.Stderr, os.Environ(), cmds); err != nil {
return errors.Wrapf(err, "executing %v", cmds)

if err := unix.Mount(myEtcHosts, "/etc/hosts", "", uintptr(unix.MS_BIND), ""); err != nil {
return errors.Wrapf(err, "failed to create bind mount /etc/hosts for %s", myEtcHosts)
}
return nil
}
11 changes: 4 additions & 7 deletions pkg/child/resolvconf.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package child

import (
"golang.org/x/sys/unix"
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"

"github.com/rootless-containers/rootlesskit/pkg/common"
)

func generateResolvConf(dns string) []byte {
Expand Down Expand Up @@ -36,11 +35,9 @@ func mountResolvConf(tempDir, dns string) error {
if err := ioutil.WriteFile(myResolvConf, generateResolvConf(dns), 0644); err != nil {
return errors.Wrapf(err, "writing %s", myResolvConf)
}
cmds := [][]string{
{"mount", "--bind", myResolvConf, "/etc/resolv.conf"},
}
if err := common.Execs(os.Stderr, os.Environ(), cmds); err != nil {
return errors.Wrapf(err, "executing %v", cmds)

if err := unix.Mount(myResolvConf, "/etc/resolv.conf", "", uintptr(unix.MS_BIND), ""); err != nil {
return errors.Wrapf(err, "failed to create bind mount /etc/resolv.conf for %s", myResolvConf)
}
return nil
}
24 changes: 12 additions & 12 deletions pkg/copyup/tmpfssymlink/tmpfssymlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"os"
"path/filepath"

"golang.org/x/sys/unix"

"github.com/pkg/errors"

"github.com/rootless-containers/rootlesskit/pkg/common"
"github.com/rootless-containers/rootlesskit/pkg/copyup"
)

Expand All @@ -33,24 +34,23 @@ func (d *childDriver) CopyUp(dirs []string) ([]string, error) {
// TODO: we can support copy-up /tmp by changing bind0TempDir
return copied, errors.New("/tmp cannot be copied up")
}
cmds := [][]string{
// TODO: read-only bind (does not work well for /run)
{"mount", "--rbind", d, bind0},
{"mount", "-n", "-t", "tmpfs", "none", d},

if err := unix.Mount(d, bind0, "", uintptr(unix.MS_BIND|unix.MS_REC), ""); err != nil {
return copied, errors.Wrapf(err, "failed to create bind mount on %s", d)
}
if err := common.Execs(os.Stderr, os.Environ(), cmds); err != nil {
return copied, errors.Wrapf(err, "executing %v", cmds)

if err := unix.Mount("none", d, "tmpfs", 0, ""); err != nil {
return copied, errors.Wrapf(err, "failed to mount tmpfs on %s", d)
}

bind1, err := ioutil.TempDir(d, ".ro")
if err != nil {
return copied, errors.Wrapf(err, "creating a directory under %s", d)
}
cmds = [][]string{
{"mount", "-n", "--move", bind0, bind1},
}
if err := common.Execs(os.Stderr, os.Environ(), cmds); err != nil {
return copied, errors.Wrapf(err, "executing %v", cmds)
if err := unix.Mount(bind0, bind1, "", uintptr(unix.MS_MOVE), ""); err != nil {
return copied, errors.Wrapf(err, "failed to move mount point from %s to %s", bind0, bind1)
}

files, err := ioutil.ReadDir(bind1)
if err != nil {
return copied, errors.Wrapf(err, "reading dir %s", bind1)
Expand Down