aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/container.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-29 02:33:10 +0900
committerOphestra <cat@gensokyo.uk>2025-09-29 06:11:47 +0900
commit46cd3a28c83e93b5d66c52d06a8366c11910d5c0 (patch)
tree6e25c5078b5cd9de78b7a6c9b253f1132358812b /container/container.go
parentad1bc6794f0053c3e63eab408a0d530d53e8b51c (diff)
container: remove global msg
This frees all container instances of side effects. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/container.go')
-rw-r--r--container/container.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/container/container.go b/container/container.go
index f49faa89..c19c2e7f 100644
--- a/container/container.go
+++ b/container/container.go
@@ -49,6 +49,7 @@ type (
cmd *exec.Cmd
ctx context.Context
+ msg Msg
Params
}
@@ -162,10 +163,10 @@ func (p *Container) Start() error {
// map to overflow id to work around ownership checks
if p.Uid < 1 {
- p.Uid = OverflowUid()
+ p.Uid = OverflowUid(p.msg)
}
if p.Gid < 1 {
- p.Gid = OverflowGid()
+ p.Gid = OverflowGid(p.msg)
}
if !p.RetainSession {
@@ -263,19 +264,19 @@ func (p *Container) Start() error {
}
return &StartError{false, "kernel version too old for LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET", ENOSYS, true, false}
} else {
- msg.Verbosef("landlock abi version %d", abi)
+ p.msg.Verbosef("landlock abi version %d", abi)
}
if rulesetFd, err := rulesetAttr.Create(0); err != nil {
return &StartError{true, "create landlock ruleset", err, false, false}
} else {
- msg.Verbosef("enforcing landlock ruleset %s", rulesetAttr)
+ p.msg.Verbosef("enforcing landlock ruleset %s", rulesetAttr)
if err = LandlockRestrictSelf(rulesetFd, 0); err != nil {
_ = Close(rulesetFd)
return &StartError{true, "enforce landlock ruleset", err, false, false}
}
if err = Close(rulesetFd); err != nil {
- msg.Verbosef("cannot close landlock ruleset: %v", err)
+ p.msg.Verbosef("cannot close landlock ruleset: %v", err)
// not fatal
}
}
@@ -283,7 +284,7 @@ func (p *Container) Start() error {
landlockOut:
}
- msg.Verbose("starting container init")
+ p.msg.Verbose("starting container init")
if err := p.cmd.Start(); err != nil {
return &StartError{false, "start container init", err, false, true}
}
@@ -325,7 +326,7 @@ func (p *Container) Serve() error {
Getuid(),
Getgid(),
len(p.ExtraFiles),
- msg.IsVerbose(),
+ p.msg.IsVerbose(),
},
)
if err != nil {
@@ -392,17 +393,21 @@ func (p *Container) ProcessState() *os.ProcessState {
}
// New returns the address to a new instance of [Container] that requires further initialisation before use.
-func New(ctx context.Context) *Container {
- p := &Container{ctx: ctx, Params: Params{Ops: new(Ops)}}
+func New(ctx context.Context, msg Msg) *Container {
+ if msg == nil {
+ msg = NewMsg(nil)
+ }
+
+ p := &Container{ctx: ctx, msg: msg, Params: Params{Ops: new(Ops)}}
c, cancel := context.WithCancel(ctx)
p.cancel = cancel
- p.cmd = exec.CommandContext(c, MustExecutable())
+ p.cmd = exec.CommandContext(c, MustExecutable(msg))
return p
}
// NewCommand calls [New] and initialises the [Params.Path] and [Params.Args] fields.
-func NewCommand(ctx context.Context, pathname *Absolute, name string, args ...string) *Container {
- z := New(ctx)
+func NewCommand(ctx context.Context, msg Msg, pathname *Absolute, name string, args ...string) *Container {
+ z := New(ctx, msg)
z.Path = pathname
z.Args = append([]string{name}, args...)
return z