main: honor XDG_RUNTIME_DIR for rootless containers

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2017-07-20 17:44:06 +02:00 committed by Aleksa Sarai
parent 13fa5d2953
commit fdf85e35b3
No known key found for this signature in database
GPG Key ID: 9E18AA267DDB8DB4
2 changed files with 11 additions and 2 deletions

11
main.go
View File

@ -61,6 +61,15 @@ func main() {
} }
v = append(v, fmt.Sprintf("spec: %s", specs.Version)) v = append(v, fmt.Sprintf("spec: %s", specs.Version))
app.Version = strings.Join(v, "\n") 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{ app.Flags = []cli.Flag{
cli.BoolFlag{ cli.BoolFlag{
Name: "debug", Name: "debug",
@ -78,7 +87,7 @@ func main() {
}, },
cli.StringFlag{ cli.StringFlag{
Name: "root", Name: "root",
Value: "/run/runc", Value: root,
Usage: "root directory for storage of container state (this should be located in tmpfs)", Usage: "root directory for storage of container state (this should be located in tmpfs)",
}, },
cli.StringFlag{ cli.StringFlag{

View File

@ -50,7 +50,7 @@ value for "bundle" is the current directory.
--debug enable debug output for logging --debug enable debug output for logging
--log value set the log file path where internal debug information is written (default: "/dev/null") --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") --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") --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" --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 --help, -h show help