All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m19s
Test / Hakurei (push) Successful in 3m10s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m35s
Test / Hakurei (race detector) (push) Successful in 5m16s
Test / Flake checks (push) Successful in 1m30s
This is the initial effort of splitting up host and container side of finalisation for params to shim. The new layout also enables much finer grained unit testing of each step, as well as partition access to per-app state for each step. Signed-off-by: Ophestra <cat@gensokyo.uk>
103 lines
3.3 KiB
Go
103 lines
3.3 KiB
Go
package app
|
|
|
|
import (
|
|
"io"
|
|
"io/fs"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"os/user"
|
|
"path/filepath"
|
|
|
|
"hakurei.app/container"
|
|
"hakurei.app/internal"
|
|
)
|
|
|
|
// osFile represents [os.File].
|
|
type osFile interface {
|
|
Name() string
|
|
io.Writer
|
|
fs.File
|
|
}
|
|
|
|
// syscallDispatcher provides methods that make state-dependent system calls as part of their behaviour.
|
|
type syscallDispatcher interface {
|
|
// new starts a goroutine with a new instance of syscallDispatcher.
|
|
// A syscallDispatcher must never be used in any goroutine other than the one owning it,
|
|
// just synchronising access is not enough, as this is for test instrumentation.
|
|
new(f func(k syscallDispatcher))
|
|
|
|
// getuid provides [os.Getuid].
|
|
getuid() int
|
|
// getgid provides [os.Getgid].
|
|
getgid() int
|
|
// lookupEnv provides [os.LookupEnv].
|
|
lookupEnv(key string) (string, bool)
|
|
// stat provides [os.Stat].
|
|
stat(name string) (os.FileInfo, error)
|
|
// open provides [os.Open].
|
|
open(name string) (osFile, error)
|
|
// readdir provides [os.ReadDir].
|
|
readdir(name string) ([]os.DirEntry, error)
|
|
// tempdir provides [os.TempDir].
|
|
tempdir() string
|
|
|
|
// evalSymlinks provides [filepath.EvalSymlinks].
|
|
evalSymlinks(path string) (string, error)
|
|
|
|
// lookPath provides exec.LookPath.
|
|
lookPath(file string) (string, error)
|
|
|
|
// lookupGroupId calls [user.LookupGroup] and returns the Gid field of the resulting [user.Group] struct.
|
|
lookupGroupId(name string) (string, error)
|
|
|
|
// cmdOutput provides the Output method of [exec.Cmd].
|
|
cmdOutput(cmd *exec.Cmd) ([]byte, error)
|
|
|
|
// overflowUid provides [container.OverflowUid].
|
|
overflowUid(msg container.Msg) int
|
|
// overflowGid provides [container.OverflowGid].
|
|
overflowGid(msg container.Msg) int
|
|
|
|
// mustHsuPath provides [internal.MustHsuPath].
|
|
mustHsuPath() *container.Absolute
|
|
|
|
// fatalf provides [log.Fatalf].
|
|
fatalf(format string, v ...any)
|
|
}
|
|
|
|
// direct implements syscallDispatcher on the current kernel.
|
|
type direct struct{}
|
|
|
|
func (k direct) new(f func(k syscallDispatcher)) { go f(k) }
|
|
|
|
func (direct) getuid() int { return os.Getuid() }
|
|
func (direct) getgid() int { return os.Getgid() }
|
|
func (direct) lookupEnv(key string) (string, bool) { return os.LookupEnv(key) }
|
|
func (direct) stat(name string) (os.FileInfo, error) { return os.Stat(name) }
|
|
func (direct) open(name string) (osFile, error) { return os.Open(name) }
|
|
func (direct) readdir(name string) ([]os.DirEntry, error) { return os.ReadDir(name) }
|
|
func (direct) tempdir() string { return os.TempDir() }
|
|
|
|
func (direct) evalSymlinks(path string) (string, error) { return filepath.EvalSymlinks(path) }
|
|
|
|
func (direct) lookPath(file string) (string, error) { return exec.LookPath(file) }
|
|
|
|
func (direct) lookupGroupId(name string) (gid string, err error) {
|
|
var group *user.Group
|
|
group, err = user.LookupGroup(name)
|
|
if group != nil {
|
|
gid = group.Gid
|
|
}
|
|
return
|
|
}
|
|
|
|
func (direct) cmdOutput(cmd *exec.Cmd) ([]byte, error) { return cmd.Output() }
|
|
|
|
func (direct) overflowUid(msg container.Msg) int { return container.OverflowUid(msg) }
|
|
func (direct) overflowGid(msg container.Msg) int { return container.OverflowGid(msg) }
|
|
|
|
func (direct) mustHsuPath() *container.Absolute { return internal.MustHsuPath() }
|
|
|
|
func (direct) fatalf(format string, v ...any) { log.Fatalf(format, v...) }
|