From fdf85e35b3d4e45666b8fdb9d5f2d4dd5f911d28 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 20 Jul 2017 17:44:06 +0200 Subject: [PATCH] main: honor XDG_RUNTIME_DIR for rootless containers Signed-off-by: Giuseppe Scrivano --- main.go | 11 ++++++++++- man/runc.8.md | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 3eb2a3c1..4642335e 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,15 @@ func main() { } v = append(v, fmt.Sprintf("spec: %s", specs.Version)) app.Version = strings.Join(v, "\n") + + root := "/run/runc" + if os.Geteuid() != 0 { + runtimeDir := os.Getenv("XDG_RUNTIME_DIR") + if runtimeDir != "" { + root = runtimeDir + "/runc" + } + } + app.Flags = []cli.Flag{ cli.BoolFlag{ Name: "debug", @@ -78,7 +87,7 @@ func main() { }, cli.StringFlag{ Name: "root", - Value: "/run/runc", + Value: root, Usage: "root directory for storage of container state (this should be located in tmpfs)", }, cli.StringFlag{ diff --git a/man/runc.8.md b/man/runc.8.md index b5a8c54f..6c6d7a55 100644 --- a/man/runc.8.md +++ b/man/runc.8.md @@ -50,7 +50,7 @@ value for "bundle" is the current directory. --debug enable debug output for logging --log value set the log file path where internal debug information is written (default: "/dev/null") --log-format value set the format used by logs ('text' (default), or 'json') (default: "text") - --root value root directory for storage of container state (this should be located in tmpfs) (default: "/run/runc") + --root value root directory for storage of container state (this should be located in tmpfs) (default: "/run/runc" or $XDG_RUNTIME_DIR/runc for rootless containers) --criu value path to the criu binary used for checkpoint and restore (default: "criu") --systemd-cgroup enable systemd cgroup support, expects cgroupsPath to be of form "slice:prefix:name" for e.g. "system.slice:runc:434234" --help, -h show help