aboutsummaryrefslogtreecommitdiffhomepage
path: root/hst
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-19 03:53:20 +0900
committerOphestra <cat@gensokyo.uk>2025-10-19 04:11:38 +0900
commit699c19e972a3cbcc714403aedffcb5ff74386cfc (patch)
tree4f279d0e917d21dc8e40409691b93bbbf44c7667 /hst
parentb5b30aea2eca15b8a0c9e01d6e3d0e844c99890c (diff)
hst/container: optional runtime and tmpdir sharing
Sharing and persisting these directories do not always make sense. Make it optional here. Closes #16. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'hst')
-rw-r--r--hst/container.go18
-rw-r--r--hst/container_test.go2
-rw-r--r--hst/hst_test.go4
3 files changed, 22 insertions, 2 deletions
diff --git a/hst/container.go b/hst/container.go
index 94017bf8..617d22db 100644
--- a/hst/container.go
+++ b/hst/container.go
@@ -63,6 +63,11 @@ const (
// FDevice mount /dev/ from the init mount namespace as-is in the container mount namespace.
FDevice
+ // FShareRuntime shares XDG_RUNTIME_DIR between containers under the same identity.
+ FShareRuntime
+ // FShareTmpdir shares TMPDIR between containers under the same identity.
+ FShareTmpdir
+
fMax
// FAll is [ContainerConfig.Flags] with all currently defined bits set.
@@ -133,6 +138,11 @@ type containerConfigJSON = struct {
// Corresponds to [FDevice].
Device bool `json:"device,omitempty"`
+
+ // Corresponds to [FShareRuntime].
+ ShareRuntime bool `json:"share_runtime,omitempty"`
+ // Corresponds to [FShareTmpdir]
+ ShareTmpdir bool `json:"share_tmpdir,omitempty"`
}
func (c *ContainerConfig) MarshalJSON() ([]byte, error) {
@@ -151,6 +161,8 @@ func (c *ContainerConfig) MarshalJSON() ([]byte, error) {
Multiarch: c.Flags&FMultiarch != 0,
MapRealUID: c.Flags&FMapRealUID != 0,
Device: c.Flags&FDevice != 0,
+ ShareRuntime: c.Flags&FShareRuntime != 0,
+ ShareTmpdir: c.Flags&FShareTmpdir != 0,
})
}
@@ -192,5 +204,11 @@ func (c *ContainerConfig) UnmarshalJSON(data []byte) error {
if v.Device {
c.Flags |= FDevice
}
+ if v.ShareRuntime {
+ c.Flags |= FShareRuntime
+ }
+ if v.ShareTmpdir {
+ c.Flags |= FShareTmpdir
+ }
return nil
}
diff --git a/hst/container_test.go b/hst/container_test.go
index 049d3540..cdeb5023 100644
--- a/hst/container_test.go
+++ b/hst/container_test.go
@@ -28,7 +28,7 @@ func TestContainerConfig(t *testing.T) {
{"hostnet hostabstract mapuid", &hst.ContainerConfig{Flags: hst.FHostNet | hst.FHostAbstract | hst.FMapRealUID},
`{"env":null,"filesystem":null,"shell":null,"home":null,"args":null,"host_net":true,"host_abstract":true,"map_real_uid":true}`},
{"all", &hst.ContainerConfig{Flags: hst.FAll},
- `{"env":null,"filesystem":null,"shell":null,"home":null,"args":null,"seccomp_compat":true,"devel":true,"userns":true,"host_net":true,"host_abstract":true,"tty":true,"multiarch":true,"map_real_uid":true,"device":true}`},
+ `{"env":null,"filesystem":null,"shell":null,"home":null,"args":null,"seccomp_compat":true,"devel":true,"userns":true,"host_net":true,"host_abstract":true,"tty":true,"multiarch":true,"map_real_uid":true,"device":true,"share_runtime":true,"share_tmpdir":true}`},
}
for _, tc := range testCases {
diff --git a/hst/hst_test.go b/hst/hst_test.go
index 0dd74886..b487dd5e 100644
--- a/hst/hst_test.go
+++ b/hst/hst_test.go
@@ -244,7 +244,9 @@ func TestTemplate(t *testing.T) {
"tty": true,
"multiarch": true,
"map_real_uid": true,
- "device": true
+ "device": true,
+ "share_runtime": true,
+ "share_tmpdir": true
}
}`