sandbox: rename params struct
All checks were successful
Test / Create distribution (push) Successful in 25s
Test / Fortify (push) Successful in 2m33s
Test / Fpkg (push) Successful in 3m27s
Test / Data race detector (push) Successful in 4m3s
Test / Flake checks (push) Successful in 59s

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-03-17 21:45:08 +09:00
parent 7c063833e0
commit d7eddd54a2
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
3 changed files with 14 additions and 13 deletions

View File

@ -54,7 +54,6 @@ type (
// with behaviour identical to its [exec.Cmd] counterpart. // with behaviour identical to its [exec.Cmd] counterpart.
ExtraFiles []*os.File ExtraFiles []*os.File
InitParams
// Custom [exec.Cmd] initialisation function. // Custom [exec.Cmd] initialisation function.
CommandContext func(ctx context.Context) (cmd *exec.Cmd) CommandContext func(ctx context.Context) (cmd *exec.Cmd)
@ -72,9 +71,11 @@ type (
cmd *exec.Cmd cmd *exec.Cmd
ctx context.Context ctx context.Context
Params
} }
InitParams struct { // Params holds container configuration and is safe to serialise.
Params struct {
// Working directory in the container. // Working directory in the container.
Dir string Dir string
// Initial process environment. // Initial process environment.
@ -100,7 +101,7 @@ type (
Ops []Op Ops []Op
Op interface { Op interface {
apply(params *InitParams) error apply(params *Params) error
prefix() string prefix() string
Is(op Op) bool Is(op Op) bool
@ -210,7 +211,7 @@ func (p *Container) Serve() error {
p.setup = nil p.setup = nil
return setup.Encode( return setup.Encode(
&initParams{ &initParams{
p.InitParams, p.Params,
syscall.Getuid(), syscall.Getuid(),
syscall.Getgid(), syscall.Getgid(),
len(p.ExtraFiles), len(p.ExtraFiles),
@ -228,6 +229,6 @@ func (p *Container) String() string {
func New(ctx context.Context, name string, args ...string) *Container { func New(ctx context.Context, name string, args ...string) *Container {
return &Container{name: name, ctx: ctx, return &Container{name: name, ctx: ctx,
InitParams: InitParams{Args: append([]string{name}, args...), Dir: "/", Ops: new(Ops)}, Params: Params{Args: append([]string{name}, args...), Dir: "/", Ops: new(Ops)},
} }
} }

View File

@ -28,7 +28,7 @@ const (
) )
type initParams struct { type initParams struct {
InitParams Params
HostUid, HostGid int HostUid, HostGid int
// extra files count // extra files count
@ -148,7 +148,7 @@ func Init(prepare func(prefix string), setVerbose func(verbose bool)) {
} }
msg.Verbosef("%s %s", op.prefix(), op) msg.Verbosef("%s %s", op.prefix(), op)
if err := op.apply(&params.InitParams); err != nil { if err := op.apply(&params.Params); err != nil {
msg.PrintBaseErr(err, msg.PrintBaseErr(err,
fmt.Sprintf("cannot apply op %d:", i)) fmt.Sprintf("cannot apply op %d:", i))
msg.BeforeExit() msg.BeforeExit()

View File

@ -19,7 +19,7 @@ type BindMount struct {
Flags int Flags int
} }
func (b *BindMount) apply(*InitParams) error { func (b *BindMount) apply(*Params) error {
if !path.IsAbs(b.Source) || !path.IsAbs(b.Target) { if !path.IsAbs(b.Source) || !path.IsAbs(b.Target) {
return msg.WrapErr(syscall.EBADE, return msg.WrapErr(syscall.EBADE,
"path is not absolute") "path is not absolute")
@ -45,7 +45,7 @@ func init() { gob.Register(new(MountProc)) }
// MountProc mounts a private instance of proc. // MountProc mounts a private instance of proc.
type MountProc string type MountProc string
func (p MountProc) apply(*InitParams) error { func (p MountProc) apply(*Params) error {
v := string(p) v := string(p)
if !path.IsAbs(v) { if !path.IsAbs(v) {
@ -75,7 +75,7 @@ func init() { gob.Register(new(MountDev)) }
// MountDev mounts part of host dev. // MountDev mounts part of host dev.
type MountDev string type MountDev string
func (d MountDev) apply(params *InitParams) error { func (d MountDev) apply(params *Params) error {
v := string(d) v := string(d)
if !path.IsAbs(v) { if !path.IsAbs(v) {
@ -156,7 +156,7 @@ func init() { gob.Register(new(MountMqueue)) }
// MountMqueue mounts a private mqueue instance on container Path. // MountMqueue mounts a private mqueue instance on container Path.
type MountMqueue string type MountMqueue string
func (m MountMqueue) apply(*InitParams) error { func (m MountMqueue) apply(*Params) error {
v := string(m) v := string(m)
if !path.IsAbs(v) { if !path.IsAbs(v) {
@ -190,7 +190,7 @@ type MountTmpfs struct {
Perm os.FileMode Perm os.FileMode
} }
func (t *MountTmpfs) apply(*InitParams) error { func (t *MountTmpfs) apply(*Params) error {
if !path.IsAbs(t.Path) { if !path.IsAbs(t.Path) {
return msg.WrapErr(syscall.EBADE, return msg.WrapErr(syscall.EBADE,
fmt.Sprintf("path %q is not absolute", t.Path)) fmt.Sprintf("path %q is not absolute", t.Path))
@ -215,7 +215,7 @@ func init() { gob.Register(new(Symlink)) }
// Symlink creates a symlink in the container filesystem. // Symlink creates a symlink in the container filesystem.
type Symlink [2]string type Symlink [2]string
func (l *Symlink) apply(*InitParams) error { func (l *Symlink) apply(*Params) error {
// symlink target is an arbitrary path value, so only validate link name here // symlink target is an arbitrary path value, so only validate link name here
if !path.IsAbs(l[1]) { if !path.IsAbs(l[1]) {
return msg.WrapErr(syscall.EBADE, return msg.WrapErr(syscall.EBADE,