aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/dbus
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-07-25 00:43:22 +0900
committerOphestra <cat@gensokyo.uk>2025-07-25 00:45:10 +0900
commite71ae3b8c5b4a8f103a078783fef2f56ee5450a2 (patch)
treee6b7a87006563da8c360ca248e261a7fe7e2820f /system/dbus
parent9d7a19d162e7003ce89804f00c526b77b2328baa (diff)
container: remove custom cmd initialisation
This part of the interface is very unintuitive and only used for testing, even in testing it is inelegant and can be done better. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/dbus')
-rw-r--r--system/dbus/dbus_test.go67
-rw-r--r--system/dbus/proc.go10
-rw-r--r--system/dbus/proc_test.go17
-rw-r--r--system/dbus/proxy.go5
-rw-r--r--system/dbus/stub_test.go9
5 files changed, 35 insertions, 73 deletions
diff --git a/system/dbus/dbus_test.go b/system/dbus/dbus_test.go
index 919e13a0..213bb376 100644
--- a/system/dbus/dbus_test.go
+++ b/system/dbus/dbus_test.go
@@ -1,22 +1,17 @@
package dbus_test
import (
- "bytes"
"context"
"errors"
"fmt"
"io"
"os"
- "os/exec"
"strings"
"syscall"
"testing"
"time"
- "hakurei.app/container"
"hakurei.app/helper"
- "hakurei.app/internal"
- "hakurei.app/internal/hlog"
"hakurei.app/system/dbus"
)
@@ -64,20 +59,23 @@ func TestFinalise(t *testing.T) {
}
func TestProxyStartWaitCloseString(t *testing.T) {
- oldWaitDelay := helper.WaitDelay
- helper.WaitDelay = 16 * time.Second
- t.Cleanup(func() { helper.WaitDelay = oldWaitDelay })
+ t.Run("sandbox", func(t *testing.T) { testProxyFinaliseStartWaitCloseString(t, true) })
+ t.Run("direct", func(t *testing.T) { testProxyFinaliseStartWaitCloseString(t, false) })
+}
+
+func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
+ {
+ oldWaitDelay := helper.WaitDelay
+ helper.WaitDelay = 16 * time.Second
+ t.Cleanup(func() { helper.WaitDelay = oldWaitDelay })
+ }
- t.Run("sandbox", func(t *testing.T) {
+ {
proxyName := dbus.ProxyName
dbus.ProxyName = os.Args[0]
t.Cleanup(func() { dbus.ProxyName = proxyName })
- testProxyFinaliseStartWaitCloseString(t, true)
- })
- t.Run("direct", func(t *testing.T) { testProxyFinaliseStartWaitCloseString(t, false) })
-}
+ }
-func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
var p *dbus.Proxy
t.Run("string for nil proxy", func(t *testing.T) {
@@ -122,36 +120,13 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
defer cancel()
+ output := new(strings.Builder)
if !useSandbox {
- p = dbus.NewDirect(ctx, final, nil)
+ p = dbus.NewDirect(ctx, final, output)
} else {
- p = dbus.New(ctx, final, nil)
+ p = dbus.New(ctx, final, output)
}
- p.CommandContext = func(ctx context.Context) (cmd *exec.Cmd) {
- return exec.CommandContext(ctx, os.Args[0], "-test.v",
- "-test.run=TestHelperInit", "--", "init")
- }
- p.CmdF = func(v any) {
- if useSandbox {
- z := v.(*container.Container)
- if z.Args[0] != dbus.ProxyName {
- panic(fmt.Sprintf("unexpected argv0 %q", os.Args[0]))
- }
- z.Args = append([]string{os.Args[0], "-test.run=TestHelperStub", "--"}, z.Args[1:]...)
- } else {
- cmd := v.(*exec.Cmd)
- if cmd.Args[0] != dbus.ProxyName {
- panic(fmt.Sprintf("unexpected argv0 %q", os.Args[0]))
- }
- cmd.Err = nil
- cmd.Path = os.Args[0]
- cmd.Args = append([]string{os.Args[0], "-test.run=TestHelperStub", "--"}, cmd.Args[1:]...)
- }
- }
- p.FilterF = func(v []byte) []byte { return bytes.SplitN(v, []byte("TestHelperInit\n"), 2)[1] }
- output := new(strings.Builder)
-
t.Run("invalid wait", func(t *testing.T) {
wantErr := "dbus: not started"
if err := p.Wait(); err == nil || err.Error() != wantErr {
@@ -176,9 +151,9 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
}
t.Run("string", func(t *testing.T) {
- wantSubstr := fmt.Sprintf("%s -test.run=TestHelperStub -- --args=3 --fd=4", os.Args[0])
+ wantSubstr := fmt.Sprintf("%s --args=3 --fd=4", os.Args[0])
if useSandbox {
- wantSubstr = fmt.Sprintf(`argv: ["%s" "-test.run=TestHelperStub" "--" "--args=3" "--fd=4"], filter: true, rules: 0, flags: 0x1, presets: 0xf`, os.Args[0])
+ wantSubstr = fmt.Sprintf(`argv: ["%s" "--args=3" "--fd=4"], filter: true, rules: 0, flags: 0x1, presets: 0xf`, os.Args[0])
}
if got := p.String(); !strings.Contains(got, wantSubstr) {
t.Errorf("String: %q, want %q",
@@ -203,11 +178,3 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
})
}
}
-
-func TestHelperInit(t *testing.T) {
- if len(os.Args) != 5 || os.Args[4] != "init" {
- return
- }
- container.SetOutput(hlog.Output{})
- container.Init(hlog.Prepare, internal.InstallOutput)
-}
diff --git a/system/dbus/proc.go b/system/dbus/proc.go
index 879bc775..dfa42e28 100644
--- a/system/dbus/proc.go
+++ b/system/dbus/proc.go
@@ -36,9 +36,6 @@ func (p *Proxy) Start() error {
if !p.useSandbox {
p.helper = helper.NewDirect(ctx, p.name, p.final, true, argF, func(cmd *exec.Cmd) {
- if p.CmdF != nil {
- p.CmdF(cmd)
- }
if p.output != nil {
cmd.Stdout, cmd.Stderr = p.output, p.output
}
@@ -56,7 +53,7 @@ func (p *Proxy) Start() error {
}
var libPaths []string
- if entries, err := ldd.ExecFilter(ctx, p.CommandContext, p.FilterF, toolPath); err != nil {
+ if entries, err := ldd.Exec(ctx, toolPath); err != nil {
return err
} else {
libPaths = ldd.Path(entries)
@@ -69,15 +66,10 @@ func (p *Proxy) Start() error {
z.SeccompFlags |= seccomp.AllowMultiarch
z.SeccompPresets |= seccomp.PresetStrict
z.Hostname = "hakurei-dbus"
- z.CommandContext = p.CommandContext
if p.output != nil {
z.Stdout, z.Stderr = p.output, p.output
}
- if p.CmdF != nil {
- p.CmdF(z)
- }
-
// these lib paths are unpredictable, so mount them first so they cannot cover anything
for _, name := range libPaths {
z.Bind(name, name, 0)
diff --git a/system/dbus/proc_test.go b/system/dbus/proc_test.go
new file mode 100644
index 00000000..5e93ace2
--- /dev/null
+++ b/system/dbus/proc_test.go
@@ -0,0 +1,17 @@
+package dbus_test
+
+import (
+ "os"
+ "testing"
+
+ "hakurei.app/container"
+ "hakurei.app/helper"
+ "hakurei.app/internal"
+ "hakurei.app/internal/hlog"
+)
+
+func TestMain(m *testing.M) {
+ container.TryArgv0(hlog.Output{}, hlog.Prepare, internal.InstallOutput)
+ helper.InternalHelperStub()
+ os.Exit(m.Run())
+}
diff --git a/system/dbus/proxy.go b/system/dbus/proxy.go
index 8fed8f27..2f625f68 100644
--- a/system/dbus/proxy.go
+++ b/system/dbus/proxy.go
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
- "os/exec"
"sync"
"syscall"
@@ -37,10 +36,6 @@ type Proxy struct {
useSandbox bool
name string
- CmdF func(any)
-
- CommandContext func(ctx context.Context) (cmd *exec.Cmd)
- FilterF func([]byte) []byte
mu, pmu sync.RWMutex
}
diff --git a/system/dbus/stub_test.go b/system/dbus/stub_test.go
deleted file mode 100644
index 79725399..00000000
--- a/system/dbus/stub_test.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package dbus_test
-
-import (
- "testing"
-
- "hakurei.app/helper"
-)
-
-func TestHelperStub(t *testing.T) { helper.InternalHelperStub() }