moby/rootless/rootless.go
Sebastiaan van Stijn 350fadbdd4
rootless: remove redundant sync.Once
This was added in ec87479b7e, but it's unclear
why a sync.Once was used just for reading an environment-variable. The
related PR had a lot of review comments, so perhaps an earlier implementation
used something more heavy-weight, or it was just overlooked.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-25 13:53:32 +02:00

27 lines
837 B
Go

package rootless // import "github.com/docker/docker/rootless"
import (
"os"
"path/filepath"
"github.com/pkg/errors"
"github.com/rootless-containers/rootlesskit/pkg/api/client"
)
// RootlessKitDockerProxyBinary is the binary name of rootlesskit-docker-proxy
const RootlessKitDockerProxyBinary = "rootlesskit-docker-proxy"
// RunningWithRootlessKit returns true if running under RootlessKit namespaces.
func RunningWithRootlessKit() bool {
return os.Getenv("ROOTLESSKIT_STATE_DIR") != ""
}
// GetRootlessKitClient returns RootlessKit client
func GetRootlessKitClient() (client.Client, error) {
stateDir := os.Getenv("ROOTLESSKIT_STATE_DIR")
if stateDir == "" {
return nil, errors.New("environment variable `ROOTLESSKIT_STATE_DIR` is not set")
}
apiSock := filepath.Join(stateDir, "api.sock")
return client.New(apiSock)
}