From f33aea9ff9c5eb678c6f1de59132aab69a59757e Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 2 Nov 2025 12:22:32 +0900 Subject: [PATCH] internal/env: cleaner runtime dir fallback This now places rundir inside the fallback runtime dir, so special case in internal/outcome is avoided. Signed-off-by: Ophestra --- internal/env/env.go | 5 ++--- internal/env/env_test.go | 4 ++-- internal/outcome/main_test.go | 8 ++++---- internal/outcome/outcome.go | 8 ++++---- internal/outcome/sppulse_test.go | 16 ++++++++-------- internal/outcome/spwayland_test.go | 4 ++-- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/internal/env/env.go b/internal/env/env.go index ebb816d..cdacb20 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -29,12 +29,11 @@ func (env *Paths) Copy(v *hst.Paths, userid int) { if env.RuntimePath == nil { // fall back to path in share since hakurei has no hard XDG dependency - v.RunDirPath = v.SharePath.Append("run") - v.RuntimePath = v.RunDirPath.Append("compat") + v.RuntimePath = v.SharePath.Append("compat") } else { v.RuntimePath = env.RuntimePath - v.RunDirPath = env.RuntimePath.Append("hakurei") } + v.RunDirPath = v.RuntimePath.Append("hakurei") } // CopyPaths returns a populated [Paths]. diff --git a/internal/env/env_test.go b/internal/env/env_test.go index 8a07d6b..77ece8d 100644 --- a/internal/env/env_test.go +++ b/internal/env/env_test.go @@ -35,8 +35,8 @@ func TestPaths(t *testing.T) { }, hst.Paths{ TempDir: fhs.AbsTmp, SharePath: fhs.AbsTmp.Append("hakurei.3735928559"), - RuntimePath: fhs.AbsTmp.Append("hakurei.3735928559/run/compat"), - RunDirPath: fhs.AbsTmp.Append("hakurei.3735928559/run"), + RuntimePath: fhs.AbsTmp.Append("hakurei.3735928559/compat"), + RunDirPath: fhs.AbsTmp.Append("hakurei.3735928559/compat/hakurei"), }, ""}, {"full", &env.Paths{ diff --git a/internal/outcome/main_test.go b/internal/outcome/main_test.go index 85a177d..f25264b 100644 --- a/internal/outcome/main_test.go +++ b/internal/outcome/main_test.go @@ -68,10 +68,10 @@ func TestOutcomeMain(t *testing.T) { ). // ensureRuntimeDir - Ensure(m("/run/user/1971/hakurei"), 0700). - UpdatePermType(system.User, m("/run/user/1971/hakurei"), acl.Execute). Ensure(m("/run/user/1971"), 0700). UpdatePermType(system.User, m("/run/user/1971"), acl.Execute). + Ensure(m("/run/user/1971/hakurei"), 0700). + UpdatePermType(system.User, m("/run/user/1971/hakurei"), acl.Execute). // runtime Ephemeral(system.Process, m("/run/user/1971/hakurei/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), 0700). @@ -347,8 +347,8 @@ func TestOutcomeMain(t *testing.T) { Ensure(m("/tmp/hakurei.0/tmpdir/9"), 01700).UpdatePermType(system.User, m("/tmp/hakurei.0/tmpdir/9"), acl.Read, acl.Write, acl.Execute). Ephemeral(system.Process, m("/tmp/hakurei.0/ebf083d1b175911782d413369b64ce7c"), 0711). Wayland(m("/tmp/hakurei.0/ebf083d1b175911782d413369b64ce7c/wayland"), m("/run/user/1971/wayland-0"), "org.chromium.Chromium", "ebf083d1b175911782d413369b64ce7c"). - Ensure(m("/run/user/1971/hakurei"), 0700).UpdatePermType(system.User, m("/run/user/1971/hakurei"), acl.Execute). Ensure(m("/run/user/1971"), 0700).UpdatePermType(system.User, m("/run/user/1971"), acl.Execute). // this is ordered as is because the previous Ensure only calls mkdir if XDG_RUNTIME_DIR is unset + Ensure(m("/run/user/1971/hakurei"), 0700).UpdatePermType(system.User, m("/run/user/1971/hakurei"), acl.Execute). Ephemeral(system.Process, m("/run/user/1971/hakurei/ebf083d1b175911782d413369b64ce7c"), 0700).UpdatePermType(system.Process, m("/run/user/1971/hakurei/ebf083d1b175911782d413369b64ce7c"), acl.Execute). Link(m("/run/user/1971/pulse/native"), m("/run/user/1971/hakurei/ebf083d1b175911782d413369b64ce7c/pulse")). MustProxyDBus(&hst.BusConfig{ @@ -499,8 +499,8 @@ func TestOutcomeMain(t *testing.T) { Ensure(m("/tmp/hakurei.0/runtime/1"), 0700).UpdatePermType(system.User, m("/tmp/hakurei.0/runtime/1"), acl.Read, acl.Write, acl.Execute). Ensure(m("/tmp/hakurei.0/tmpdir"), 0700).UpdatePermType(system.User, m("/tmp/hakurei.0/tmpdir"), acl.Execute). Ensure(m("/tmp/hakurei.0/tmpdir/1"), 01700).UpdatePermType(system.User, m("/tmp/hakurei.0/tmpdir/1"), acl.Read, acl.Write, acl.Execute). - Ensure(m("/run/user/1971/hakurei"), 0700).UpdatePermType(system.User, m("/run/user/1971/hakurei"), acl.Execute). Ensure(m("/run/user/1971"), 0700).UpdatePermType(system.User, m("/run/user/1971"), acl.Execute). // this is ordered as is because the previous Ensure only calls mkdir if XDG_RUNTIME_DIR is unset + Ensure(m("/run/user/1971/hakurei"), 0700).UpdatePermType(system.User, m("/run/user/1971/hakurei"), acl.Execute). UpdatePermType(hst.EWayland, m("/run/user/1971/wayland-0"), acl.Read, acl.Write, acl.Execute). Ephemeral(system.Process, m("/run/user/1971/hakurei/8e2c76b066dabe574cf073bdb46eb5c1"), 0700).UpdatePermType(system.Process, m("/run/user/1971/hakurei/8e2c76b066dabe574cf073bdb46eb5c1"), acl.Execute). Link(m("/run/user/1971/pulse/native"), m("/run/user/1971/hakurei/8e2c76b066dabe574cf073bdb46eb5c1/pulse")). diff --git a/internal/outcome/outcome.go b/internal/outcome/outcome.go index 2397b72..9cf426f 100644 --- a/internal/outcome/outcome.go +++ b/internal/outcome/outcome.go @@ -196,10 +196,10 @@ func (state *outcomeStateSys) ensureRuntimeDir() { return } state.useRuntimeDir = true - state.sys.Ensure(state.sc.RunDirPath, 0700) - state.sys.UpdatePermType(system.User, state.sc.RunDirPath, acl.Execute) - state.sys.Ensure(state.sc.RuntimePath, 0700) // ensure this dir in case XDG_RUNTIME_DIR is unset - state.sys.UpdatePermType(system.User, state.sc.RuntimePath, acl.Execute) + state.sys. + // ensure this dir in case XDG_RUNTIME_DIR is unset + Ensure(state.sc.RuntimePath, 0700).UpdatePermType(system.User, state.sc.RuntimePath, acl.Execute). + Ensure(state.sc.RunDirPath, 0700).UpdatePermType(system.User, state.sc.RunDirPath, acl.Execute) } // instance returns the pathname to a process-specific directory within TMPDIR. diff --git a/internal/outcome/sppulse_test.go b/internal/outcome/sppulse_test.go index 9aecb19..84a53a7 100644 --- a/internal/outcome/sppulse_test.go +++ b/internal/outcome/sppulse_test.go @@ -127,10 +127,10 @@ func TestSpPulseOp(t *testing.T) { call("open", stub.ExpectArgs{"/proc/nonexistent/cookie"}, &stubOsFile{Reader: bytes.NewReader(sampleCookie)}, nil), }, newI(). // state.ensureRuntimeDir - Ensure(m(wantRunDirPath), 0700). - UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). Ensure(m(wantRuntimePath), 0700). UpdatePermType(system.User, m(wantRuntimePath), acl.Execute). + Ensure(m(wantRunDirPath), 0700). + UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). // state.runtime Ephemeral(system.Process, m(wantRuntimeSharePath), 0700). UpdatePerm(m(wantRuntimeSharePath), acl.Execute). @@ -159,10 +159,10 @@ func TestSpPulseOp(t *testing.T) { call("open", stub.ExpectArgs{"/proc/nonexistent/cookie"}, &stubOsFile{Reader: bytes.NewReader(sampleCookie[:len(sampleCookie)-0xe])}, nil), }, newI(). // state.ensureRuntimeDir - Ensure(m(wantRunDirPath), 0700). - UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). Ensure(m(wantRuntimePath), 0700). UpdatePermType(system.User, m(wantRuntimePath), acl.Execute). + Ensure(m(wantRunDirPath), 0700). + UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). // state.runtime Ephemeral(system.Process, m(wantRuntimeSharePath), 0700). UpdatePerm(m(wantRuntimeSharePath), acl.Execute). @@ -192,10 +192,10 @@ func TestSpPulseOp(t *testing.T) { call("open", stub.ExpectArgs{"/proc/nonexistent/cookie"}, &stubOsFile{Reader: bytes.NewReader(sampleCookie)}, nil), }, newI(). // state.ensureRuntimeDir - Ensure(m(wantRunDirPath), 0700). - UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). Ensure(m(wantRuntimePath), 0700). UpdatePermType(system.User, m(wantRuntimePath), acl.Execute). + Ensure(m(wantRunDirPath), 0700). + UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). // state.runtime Ephemeral(system.Process, m(wantRuntimeSharePath), 0700). UpdatePerm(m(wantRuntimeSharePath), acl.Execute). @@ -222,10 +222,10 @@ func TestSpPulseOp(t *testing.T) { call("verbose", stub.ExpectArgs{[]any{"cannot locate PulseAudio cookie (tried $PULSE_COOKIE, $XDG_CONFIG_HOME/pulse/cookie, $HOME/.pulse-cookie)"}}, nil, nil), }, newI(). // state.ensureRuntimeDir - Ensure(m(wantRunDirPath), 0700). - UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). Ensure(m(wantRuntimePath), 0700). UpdatePermType(system.User, m(wantRuntimePath), acl.Execute). + Ensure(m(wantRunDirPath), 0700). + UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). // state.runtime Ephemeral(system.Process, m(wantRuntimeSharePath), 0700). UpdatePerm(m(wantRuntimeSharePath), acl.Execute). diff --git a/internal/outcome/spwayland_test.go b/internal/outcome/spwayland_test.go index 5cee8de..281cb29 100644 --- a/internal/outcome/spwayland_test.go +++ b/internal/outcome/spwayland_test.go @@ -64,10 +64,10 @@ func TestSpWaylandOp(t *testing.T) { call("verbose", stub.ExpectArgs{[]any{"direct wayland access, PROCEED WITH CAUTION"}}, nil, nil), }, newI(). // state.ensureRuntimeDir - Ensure(m(wantRunDirPath), 0700). - UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). Ensure(m(wantRuntimePath), 0700). UpdatePermType(system.User, m(wantRuntimePath), acl.Execute). + Ensure(m(wantRunDirPath), 0700). + UpdatePermType(system.User, m(wantRunDirPath), acl.Execute). // toSystem UpdatePermType(hst.EWayland, m("/proc/nonexistent/wayland"), acl.Read, acl.Write, acl.Execute), nil, nil, insertsOps(afterSpRuntimeOp(nil)), []stub.Call{ // this op configures the container state and does not make calls during toContainer