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")
|
app.Version = strings.Join(v, "\n")
|
||||||
|
|
||||||
xdgRuntimeDir := ""
|
|
||||||
root := "/run/runc"
|
root := "/run/runc"
|
||||||
if shouldHonorXDGRuntimeDir() {
|
xdgDirUsed := false
|
||||||
if runtimeDir := os.Getenv("XDG_RUNTIME_DIR"); runtimeDir != "" {
|
xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
|
||||||
root = runtimeDir + "/runc"
|
if xdgRuntimeDir != "" && shouldHonorXDGRuntimeDir() {
|
||||||
xdgRuntimeDir = root
|
root = xdgRuntimeDir + "/runc"
|
||||||
}
|
xdgDirUsed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
@@ -135,7 +134,7 @@ func main() {
|
|||||||
featuresCommand,
|
featuresCommand,
|
||||||
}
|
}
|
||||||
app.Before = func(context *cli.Context) error {
|
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
|
// 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
|
// XDG_RUNTIME_DIR to have a sticky bit if we don't want it to get
|
||||||
// auto-pruned.
|
// auto-pruned.
|
||||||
|
@@ -52,9 +52,6 @@ func shouldUseRootlessCgroupManager(context *cli.Context) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func shouldHonorXDGRuntimeDir() bool {
|
func shouldHonorXDGRuntimeDir() bool {
|
||||||
if os.Getenv("XDG_RUNTIME_DIR") == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if os.Geteuid() != 0 {
|
if os.Geteuid() != 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user