mirror of
https://github.com/opencontainers/runc.git
synced 2025-09-26 19:41:35 +08:00
main: improve XDG_RUNTIME_DIR handling
1. Variable xdgRuntimeDir is only checked to be non-empty. Change it to a boolean. 2. Refactor so that os.Getenv is not called twice. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
13
main.go
13
main.go
@@ -71,13 +71,12 @@ func main() {
|
||||
}
|
||||
app.Version = strings.Join(v, "\n")
|
||||
|
||||
xdgRuntimeDir := ""
|
||||
root := "/run/runc"
|
||||
if shouldHonorXDGRuntimeDir() {
|
||||
if runtimeDir := os.Getenv("XDG_RUNTIME_DIR"); runtimeDir != "" {
|
||||
root = runtimeDir + "/runc"
|
||||
xdgRuntimeDir = root
|
||||
}
|
||||
xdgDirUsed := false
|
||||
xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if xdgRuntimeDir != "" && shouldHonorXDGRuntimeDir() {
|
||||
root = xdgRuntimeDir + "/runc"
|
||||
xdgDirUsed = true
|
||||
}
|
||||
|
||||
app.Flags = []cli.Flag{
|
||||
@@ -135,7 +134,7 @@ func main() {
|
||||
featuresCommand,
|
||||
}
|
||||
app.Before = func(context *cli.Context) error {
|
||||
if !context.IsSet("root") && xdgRuntimeDir != "" {
|
||||
if !context.IsSet("root") && xdgDirUsed {
|
||||
// According to the XDG specification, we need to set anything in
|
||||
// XDG_RUNTIME_DIR to have a sticky bit if we don't want it to get
|
||||
// auto-pruned.
|
||||
|
@@ -52,9 +52,6 @@ func shouldUseRootlessCgroupManager(context *cli.Context) (bool, error) {
|
||||
}
|
||||
|
||||
func shouldHonorXDGRuntimeDir() bool {
|
||||
if os.Getenv("XDG_RUNTIME_DIR") == "" {
|
||||
return false
|
||||
}
|
||||
if os.Geteuid() != 0 {
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user