Skip to content

Commit

Permalink
Return empty runtime directory if we're not rootless
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jdieter committed Dec 7, 2019
1 parent 82a83b9 commit b3014c1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/util/utils_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit b3014c1

Please sign in to comment.