From b3014c1c69d5870104aa45f7caae7af041094171 Mon Sep 17 00:00:00 2001 From: Jonathan Dieter Date: Sat, 7 Dec 2019 14:17:35 +0000 Subject: Return empty runtime directory if we're not rootless Currently, we return a runtime directory of the form `/run/user/`, 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//crun`. Signed-off-by: Jonathan Dieter --- pkg/util/utils_supported.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/util/utils_supported.go b/pkg/util/utils_supported.go index 253460686..0b78a8150 100644 --- a/pkg/util/utils_supported.go +++ b/pkg/util/utils_supported.go @@ -20,6 +20,10 @@ import ( func GetRuntimeDir() (string, error) { var rootlessRuntimeDirError error + if !rootless.IsRootless() { + return "", nil + } + rootlessRuntimeDirOnce.Do(func() { runtimeDir := os.Getenv("XDG_RUNTIME_DIR") uid := fmt.Sprintf("%d", rootless.GetRootlessUID()) -- cgit v1.2.3-54-g00ecf