aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--container/errors.go4
-rw-r--r--container/errors_test.go3
-rw-r--r--container/inittmpfs.go10
-rw-r--r--container/inittmpfs_test.go11
4 files changed, 24 insertions, 4 deletions
diff --git a/container/errors.go b/container/errors.go
index 1a828e0f..8d8ad492 100644
--- a/container/errors.go
+++ b/container/errors.go
@@ -24,6 +24,10 @@ func messageFromError(err error) (string, bool) {
return m, ok
}
+ if m, ok := messagePrefix[TmpfsSizeError]("", err); ok {
+ return m, ok
+ }
+
return zeroString, false
}
diff --git a/container/errors_test.go b/container/errors_test.go
index eae5ee7d..f99812b8 100644
--- a/container/errors_test.go
+++ b/container/errors_test.go
@@ -39,6 +39,9 @@ func TestMessageFromError(t *testing.T) {
{"state", OpStateError("overlay"),
"impossible overlay state reached", true},
+ {"tmpfs", TmpfsSizeError(-1),
+ "tmpfs size -1 out of bounds", true},
+
{"unsupported", errUnique, zeroString, false},
}
for _, tc := range testCases {
diff --git a/container/inittmpfs.go b/container/inittmpfs.go
index 0d50e463..2835004a 100644
--- a/container/inittmpfs.go
+++ b/container/inittmpfs.go
@@ -3,14 +3,20 @@ package container
import (
"encoding/gob"
"fmt"
- "io/fs"
"math"
"os"
+ "strconv"
. "syscall"
)
func init() { gob.Register(new(MountTmpfsOp)) }
+type TmpfsSizeError int
+
+func (e TmpfsSizeError) Error() string {
+ return "tmpfs size " + strconv.Itoa(int(e)) + " out of bounds"
+}
+
// Tmpfs appends an [Op] that mounts tmpfs on container path [MountTmpfsOp.Path].
func (f *Ops) Tmpfs(target *Absolute, size int, perm os.FileMode) *Ops {
*f = append(*f, &MountTmpfsOp{SourceTmpfsEphemeral, target, MS_NOSUID | MS_NODEV, size, perm})
@@ -36,7 +42,7 @@ func (t *MountTmpfsOp) Valid() bool { return t !=
func (t *MountTmpfsOp) early(*setupState, syscallDispatcher) error { return nil }
func (t *MountTmpfsOp) apply(_ *setupState, k syscallDispatcher) error {
if t.Size < 0 || t.Size > math.MaxUint>>1 {
- return msg.WrapErr(fs.ErrInvalid, fmt.Sprintf("size %d out of bounds", t.Size))
+ return TmpfsSizeError(t.Size)
}
return k.mountTmpfs(t.FSName, toSysroot(t.Path.String()), t.Flags, t.Size, t.Perm)
}
diff --git a/container/inittmpfs_test.go b/container/inittmpfs_test.go
index 8110f446..97a591f2 100644
--- a/container/inittmpfs_test.go
+++ b/container/inittmpfs_test.go
@@ -1,17 +1,24 @@
package container
import (
- "io/fs"
"os"
"syscall"
"testing"
)
func TestMountTmpfsOp(t *testing.T) {
+ t.Run("size error", func(t *testing.T) {
+ tmpfsSizeError := TmpfsSizeError(-1)
+ want := "tmpfs size -1 out of bounds"
+ if got := tmpfsSizeError.Error(); got != want {
+ t.Errorf("Error: %q, want %q", got, want)
+ }
+ })
+
checkOpBehaviour(t, []opBehaviourTestCase{
{"size oob", new(Params), &MountTmpfsOp{
Size: -1,
- }, nil, nil, nil, msg.WrapErr(fs.ErrInvalid, "size -1 out of bounds")},
+ }, nil, nil, nil, TmpfsSizeError(-1)},
{"success", new(Params), &MountTmpfsOp{
FSName: "ephemeral",