Skip to content

Commit b3014c1

Browse files
committed
Return empty runtime directory if we're not rootless
Currently, we return a runtime directory of the form `/run/user/<uid>`, even when running as root. Depending on configuration, that directory may be deleted when the user logs out, which is quite awkward when the container is started as a systemd service and then someone logs in and out as root. This patch fixes the problem by returning an empty runtime directory if the container is being started by root. The runtime should automatically use the default runtime directory (`/run/crun` when crun is used), which should be accessible to root. Tested in Fedora 31 by running containers under both root and a regular user. State for root containers is stored in `/run/crun`, while state for rootless containers is in `/run/user/<uid>/crun`. Signed-off-by: Jonathan Dieter <[email protected]>
1 parent 82a83b9 commit b3014c1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pkg/util/utils_supported.go

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
func GetRuntimeDir() (string, error) {
2121
var rootlessRuntimeDirError error
2222

23+
if !rootless.IsRootless() {
24+
return "", nil
25+
}
26+
2327
rootlessRuntimeDirOnce.Do(func() {
2428
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
2529
uid := fmt.Sprintf("%d", rootless.GetRootlessUID())

0 commit comments

Comments
 (0)