aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--sandbox/container.go1
-rw-r--r--sandbox/container_test.go5
-rw-r--r--sandbox/init.go2
-rw-r--r--sandbox/sequential.go30
4 files changed, 35 insertions, 3 deletions
diff --git a/sandbox/container.go b/sandbox/container.go
index 3c8063ce..9b0d1cef 100644
--- a/sandbox/container.go
+++ b/sandbox/container.go
@@ -101,6 +101,7 @@ type (
Ops []Op
Op interface {
apply(params *InitParams) error
+ prefix() string
Is(op Op) bool
fmt.Stringer
diff --git a/sandbox/container_test.go b/sandbox/container_test.go
index 8de11e51..70b8560f 100644
--- a/sandbox/container_test.go
+++ b/sandbox/container_test.go
@@ -67,7 +67,7 @@ func TestContainer(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- container := sandbox.New(ctx, os.Args[0], "-test.v",
+ container := sandbox.New(ctx, "/tmp/sandbox.test", "-test.v",
"-test.run=TestHelperCheckContainer", "--", "check", tc.host)
container.Uid = 1000
container.Gid = 100
@@ -86,7 +86,8 @@ func TestContainer(t *testing.T) {
container.
Tmpfs("/tmp", 0, 0755).
- Bind(os.Args[0], os.Args[0], 0)
+ Bind(os.Args[0], os.Args[0], 0).
+ Link(os.Args[0], "/tmp/sandbox.test")
// in case test has cgo enabled
var libPaths []string
if entries, err := ldd.ExecFilter(ctx,
diff --git a/sandbox/init.go b/sandbox/init.go
index e80afbea..9d1c349f 100644
--- a/sandbox/init.go
+++ b/sandbox/init.go
@@ -147,7 +147,7 @@ func Init(prepare func(prefix string), setVerbose func(verbose bool)) {
log.Fatalf("invalid op %d", i)
}
- msg.Verbosef("mounting %s", op)
+ msg.Verbosef("%s %s", op.prefix(), op)
if err := op.apply(&params.InitParams); err != nil {
msg.PrintBaseErr(err,
fmt.Sprintf("cannot apply op %d:", i))
diff --git a/sandbox/sequential.go b/sandbox/sequential.go
index bcfded8f..35d9aa2e 100644
--- a/sandbox/sequential.go
+++ b/sandbox/sequential.go
@@ -28,6 +28,7 @@ func (b *BindMount) apply(*InitParams) error {
}
func (b *BindMount) Is(op Op) bool { vb, ok := op.(*BindMount); return ok && *b == *vb }
+func (*BindMount) prefix() string { return "mounting" }
func (b *BindMount) String() string {
if b.Source == b.Target {
return fmt.Sprintf("%q flags %#x", b.Source, b.Flags)
@@ -62,6 +63,7 @@ func (p MountProc) apply(*InitParams) error {
}
func (p MountProc) Is(op Op) bool { vp, ok := op.(MountProc); return ok && p == vp }
+func (MountProc) prefix() string { return "mounting" }
func (p MountProc) String() string { return fmt.Sprintf("proc on %q", string(p)) }
func (f *Ops) Proc(dest string) *Ops {
*f = append(*f, MountProc(dest))
@@ -142,6 +144,7 @@ func (d MountDev) apply(params *InitParams) error {
}
func (d MountDev) Is(op Op) bool { vd, ok := op.(MountDev); return ok && d == vd }
+func (MountDev) prefix() string { return "mounting" }
func (d MountDev) String() string { return fmt.Sprintf("dev on %q", string(d)) }
func (f *Ops) Dev(dest string) *Ops {
*f = append(*f, MountDev(dest))
@@ -171,6 +174,7 @@ func (m MountMqueue) apply(*InitParams) error {
}
func (m MountMqueue) Is(op Op) bool { vm, ok := op.(MountMqueue); return ok && m == vm }
+func (MountMqueue) prefix() string { return "mounting" }
func (m MountMqueue) String() string { return fmt.Sprintf("mqueue on %q", string(m)) }
func (f *Ops) Mqueue(dest string) *Ops {
*f = append(*f, MountMqueue(dest))
@@ -199,8 +203,34 @@ func (t *MountTmpfs) apply(*InitParams) error {
}
func (t *MountTmpfs) Is(op Op) bool { vt, ok := op.(*MountTmpfs); return ok && *t == *vt }
+func (*MountTmpfs) prefix() string { return "mounting" }
func (t *MountTmpfs) String() string { return fmt.Sprintf("tmpfs on %q size %d", t.Path, t.Size) }
func (f *Ops) Tmpfs(dest string, size int, perm os.FileMode) *Ops {
*f = append(*f, &MountTmpfs{dest, size, perm})
return f
}
+
+func init() { gob.Register(new(Symlink)) }
+
+// Symlink creates a symlink in the container filesystem.
+type Symlink [2]string
+
+func (l *Symlink) apply(*InitParams) error {
+ // symlink target is an arbitrary path value, so only validate link name here
+ if !path.IsAbs(l[1]) {
+ return msg.WrapErr(syscall.EBADE,
+ fmt.Sprintf("path %q is not absolute", l[1]))
+ }
+ if err := os.Symlink(l[0], toSysroot(l[1])); err != nil {
+ return msg.WrapErr(err, err.Error())
+ }
+ return nil
+}
+
+func (l *Symlink) Is(op Op) bool { vl, ok := op.(*Symlink); return ok && *l == *vl }
+func (*Symlink) prefix() string { return "creating" }
+func (l *Symlink) String() string { return fmt.Sprintf("symlink on %q target %q", l[1], l[0]) }
+func (f *Ops) Link(target, linkName string) *Ops {
+ *f = append(*f, &Symlink{target, linkName})
+ return f
+}