diff --git a/internal/outcome/shim.go b/internal/outcome/shim.go index 53d04ea..b07770b 100644 --- a/internal/outcome/shim.go +++ b/internal/outcome/shim.go @@ -147,6 +147,9 @@ func shimEntrypoint(k syscallDispatcher) { } } } + if stateParams.params.Ops == nil { // unreachable + k.fatal("invalid container params") + } // shim exit outcomes var cancelContainer atomic.Pointer[context.CancelFunc] @@ -187,10 +190,6 @@ func shimEntrypoint(k syscallDispatcher) { } }) - if stateParams.params.Ops == nil { - k.fatal("invalid container params") - } - // close setup socket if err := closeSetup(); err != nil { msg.Verbosef("cannot close setup pipe: %v", err) diff --git a/internal/outcome/shim_test.go b/internal/outcome/shim_test.go index e4de9c3..d493f70 100644 --- a/internal/outcome/shim_test.go +++ b/internal/outcome/shim_test.go @@ -106,31 +106,33 @@ func TestShimEntrypoint(t *testing.T) { Remount(fhs.AbsRoot, syscall.MS_RDONLY), } + templateState := outcomeState{ + Shim: &shimParams{PrivPID: 0xbad, WaitDelay: 0xf, Verbose: true, Ops: []outcomeOp{ + &spParamsOp{"xterm-256color", true}, + &spRuntimeOp{sessionTypeWayland}, + spTmpdirOp{}, + spAccountOp{}, + &spWaylandOp{}, + &spPulseOp{(*[pulseCookieSizeMax]byte)(bytes.Repeat([]byte{0}, pulseCookieSizeMax)), pulseCookieSizeMax}, + &spDBusOp{true}, + &spFilesystemOp{}, + }}, + + ID: &checkExpectInstanceId, + Identity: hst.IdentityMax, + UserID: 10, + Container: hst.Template().Container, + Mapuid: 1000, + Mapgid: 100, + Paths: &env.Paths{TempDir: fhs.AbsTmp, RuntimePath: fhs.AbsRunUser.Append("1000")}, + } + checkSimple(t, "shimEntrypoint", []simpleTestCase{ {"success", func(k *kstub) error { shimEntrypoint(k); return nil }, stub.Expect{Calls: []stub.Call{ call("getMsg", stub.ExpectArgs{}, nil, nil), call("getLogger", stub.ExpectArgs{}, (*log.Logger)(nil), nil), call("setDumpable", stub.ExpectArgs{uintptr(container.SUID_DUMP_DISABLE)}, nil, nil), - call("receive", stub.ExpectArgs{"HAKUREI_SHIM", outcomeState{ - Shim: &shimParams{PrivPID: 0xbad, WaitDelay: 0xf, Verbose: true, Ops: []outcomeOp{ - &spParamsOp{"xterm-256color", true}, - &spRuntimeOp{sessionTypeWayland}, - spTmpdirOp{}, - spAccountOp{}, - &spWaylandOp{}, - &spPulseOp{(*[pulseCookieSizeMax]byte)(bytes.Repeat([]byte{0}, pulseCookieSizeMax)), pulseCookieSizeMax}, - &spDBusOp{true}, - &spFilesystemOp{}, - }}, - - ID: &checkExpectInstanceId, - Identity: hst.IdentityMax, - UserID: 10, - Container: hst.Template().Container, - Mapuid: 1000, - Mapgid: 100, - Paths: &env.Paths{TempDir: fhs.AbsTmp, RuntimePath: fhs.AbsRunUser.Append("1000")}, - }, nil}, nil, nil), + call("receive", stub.ExpectArgs{"HAKUREI_SHIM", templateState, nil}, nil, nil), call("swapVerbose", stub.ExpectArgs{true}, false, nil), call("verbosef", stub.ExpectArgs{"process share directory at %q, runtime directory at %q", []any{m("/tmp/hakurei.10"), m("/run/user/1000/hakurei")}}, nil, nil), call("setupContSignal", stub.ExpectArgs{0xbad}, 0, nil),