diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-04 04:15:25 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-04 04:15:25 +0900 |
| commit | ddfb865e2d526485935099a8cd454929ed5f6176 (patch) | |
| tree | ffcbb296924a904ea200259dd171d2ca86fc567d /system/dispatcher.go | |
| parent | 024d2ff7826a81db65eefa1843730b537ebdeef1 (diff) | |
system/dispatcher: wrap syscall helper functions
This allows tests to stub all kernel behaviour, like in the container package.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/dispatcher.go')
| -rw-r--r-- | system/dispatcher.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/system/dispatcher.go b/system/dispatcher.go new file mode 100644 index 00000000..c483c818 --- /dev/null +++ b/system/dispatcher.go @@ -0,0 +1,30 @@ +package system + +import "hakurei.app/system/acl" + +// syscallDispatcher provides methods that make state-dependent system calls as part of their behaviour. +// syscallDispatcher is embedded in [I], so all methods must be unexported. +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)) + + // aclUpdate provides [acl.Update]. + aclUpdate(name string, uid int, perms ...acl.Perm) error + + verbose(v ...any) + verbosef(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 (k direct) aclUpdate(name string, uid int, perms ...acl.Perm) error { + return acl.Update(name, uid, perms...) +} + +func (direct) verbose(v ...any) { msg.Verbose(v...) } +func (direct) verbosef(format string, v ...any) { msg.Verbosef(format, v...) } |
