8000 Lookup docker-proxy in libexec paths · moby/moby@f8c088b · GitHub
[go: up one dir, main page]

Skip to content

Commit f8c088b

Browse files
committed
Lookup docker-proxy in libexec paths
This allows distros to put docker-proxy under libexec paths as is done for docker-init. Also expands the lookup to to not require a `docker/` subdir in libexec subdir. Since it is a generic helper that may be used for something else in the future, this is only done for binaries with a `docker-`. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
1 parent 018d93d commit f8c088b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

daemon/config/config_linux.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"os/exec"
88
"path/filepath"
9+
"strings"
910

1011
"github.com/containerd/cgroups/v3"
1112
"github.com/containerd/log"
@@ -107,14 +108,13 @@ func (conf *Config) GetInitPath() string {
107108
return DefaultInitBinary
108109
}
109110

110-
// LookupInitPath returns an absolute path to the "docker-init" binary by searching relevant "libexec" directories (per FHS 3.0 & 2.3) followed by PATH
111-
func (conf *Config) LookupInitPath() (string, error) {
112-
binary := conf.GetInitPath()
111+
// lookupBinPath returns an absolute path to the provided binary by searching relevant "libexec" locations (per FHS 3.0 & 2.3) followed by PATH
112+
func lookupBinPath(binary string) (string, error) {
113113
if filepath.IsAbs(binary) {
114114
return binary, nil
115115
}
116116

117-
for _, dir := range []string{
117+
lookupPaths := []string{
118118
// FHS 3.0: "/usr/libexec includes internal binaries that are not intended to be executed directly by users or shell scripts. Applications may use a single subdirectory under /usr/libexec."
119119
// https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s07.html
120120
"/usr/local/libexec/docker",
@@ -124,7 +124,16 @@ func (conf *Config) LookupInitPath() (string, error) {
124124
// https://refsp 8000 ecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html#USRLIBLIBRARIESFORPROGRAMMINGANDPA
125125
"/usr/local/lib/docker",
126126
"/usr/lib/docker",
127-
} {
127+
}
128+
129+
// According to FHS 3.0, it is not necessary to have a subdir here (see note and reference above).
130+
// If the binary has a `docker-` prefix, let's look it up without the dir prefix.
131+
if strings.HasPrefix(binary, "docker-") {
132+
lookupPaths = append(lookupPaths, "/usr/local/libexec")
133+
lookupPaths = append(lookupPaths, "/usr/libexec")
134+
}
135+
136+
for _, dir := range lookupPaths {
128137
// exec.LookPath has a fast-path short-circuit for paths that contain "/" (skipping the PATH lookup) that then verifies whether the given path is likely to be an actual executable binary (so we invoke that instead of reimplementing the same checks)
129138
if file, err := exec.LookPath(filepath.Join(dir, binary)); err == nil {
130139
return file, nil
@@ -135,6 +144,11 @@ func (conf *Config) LookupInitPath() (string, error) {
135144
return exec.LookPath(binary)
136145
}
137146

147+
// LookupInitPath returns an absolute path to the "docker-init" binary by searching relevant "libexec" directories (per FHS 3.0 & 2.3) followed by PATH
148+
func (conf *Config) LookupInitPath() (string, error) {
149+
return lookupBinPath(conf.GetInitPath())
150+
}
151+
138152
// GetResolvConf returns the appropriate resolv.conf
139153
// Check setupResolvConf on how this is selected
140154
func (conf *Config) GetResolvConf() string {
@@ -225,7 +239,7 @@ func setPlatformDefaults(cfg *Config) error {
225239

226240
var err error
227241
// use rootlesskit-docker-proxy for exposing the ports in RootlessKit netns to the initial namespace.
228-
cfg.BridgeConfig.UserlandProxyPath, err = exec.LookPath(rootless.RootlessKitDockerProxyBinary)
242+
cfg.BridgeConfig.UserlandProxyPath, err = lookupBinPath(rootless.RootlessKitDockerProxyBinary)
229243
if err != nil {
230244
return errors.Wrapf(err, "running with RootlessKit, but %s not installed", rootless.RootlessKitDockerProxyBinary)
231245
}
@@ -244,7 +258,7 @@ func setPlatformDefaults(cfg *Config) error {
244258
cfg.Pidfile = filepath.Join(runtimeDir, "docker.pid")
245259
} else {
246260
var err error
247-
cfg.BridgeConfig.UserlandProxyPath, err = exec.LookPath(userlandProxyBinary)
261+
cfg.BridgeConfig.UserlandProxyPath, err = lookupBinPath(userlandProxyBinary)
248262
if err != nil {
249263
// Log, but don't error here. This allows running a daemon with
250264
// userland-proxy disabled (which does not require the binary

0 commit comments

Comments
 (0)
0