Browse code

daemon: make daemon.getEntrypointAndArgs a regular function

It was not using the daemon, so can be a regular function. While at it,
also changed the parameter type to accept a regular string-slice, as
we don't need strslice.StrSlice's json.Unmarshaler implementation, and
reversed the logic for the early return.

Finally, for uses where the entrypoint was always nil, this patch removes
the use of this utility altogether.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/01/26 22:22:06
Showing 3 changed files
... ...
@@ -11,7 +11,6 @@ import (
11 11
 	"github.com/containerd/log"
12 12
 	containertypes "github.com/docker/docker/api/types/container"
13 13
 	networktypes "github.com/docker/docker/api/types/network"
14
-	"github.com/docker/docker/api/types/strslice"
15 14
 	"github.com/docker/docker/container"
16 15
 	"github.com/docker/docker/daemon/config"
17 16
 	"github.com/docker/docker/daemon/network"
... ...
@@ -149,7 +148,7 @@ func (daemon *Daemon) newContainer(name string, platform ocispec.Platform, confi
149 149
 			config.Hostname = id[:12]
150 150
 		}
151 151
 	}
152
-	entrypoint, args := daemon.getEntrypointAndArgs(config.Entrypoint, config.Cmd)
152
+	entrypoint, args := getEntrypointAndArgs(config.Entrypoint, config.Cmd)
153 153
 
154 154
 	base := container.NewBaseContainer(id, filepath.Join(daemon.repository, id))
155 155
 	base.Created = time.Now().UTC()
... ...
@@ -167,6 +166,13 @@ func (daemon *Daemon) newContainer(name string, platform ocispec.Platform, confi
167 167
 	return base, err
168 168
 }
169 169
 
170
+func getEntrypointAndArgs(configEntrypoint, configCmd []string) (string, []string) {
171
+	if len(configEntrypoint) == 0 {
172
+		return configCmd[0], configCmd[1:]
173
+	}
174
+	return configEntrypoint[0], append(configEntrypoint[1:], configCmd...)
175
+}
176
+
170 177
 // GetByName returns a container given a name.
171 178
 func (daemon *Daemon) GetByName(name string) (*container.Container, error) {
172 179
 	if len(name) == 0 {
... ...
@@ -187,13 +193,6 @@ func (daemon *Daemon) GetByName(name string) (*container.Container, error) {
187 187
 	return e, nil
188 188
 }
189 189
 
190
-func (daemon *Daemon) getEntrypointAndArgs(configEntrypoint strslice.StrSlice, configCmd strslice.StrSlice) (string, []string) {
191
-	if len(configEntrypoint) != 0 {
192
-		return configEntrypoint[0], append(configEntrypoint[1:], configCmd...)
193
-	}
194
-	return configCmd[0], configCmd[1:]
195
-}
196
-
197 190
 func (daemon *Daemon) setSecurityOptions(cfg *config.Config, container *container.Container, hostConfig *containertypes.HostConfig) error {
198 191
 	container.Lock()
199 192
 	defer container.Unlock()
... ...
@@ -14,7 +14,6 @@ import (
14 14
 	"github.com/docker/docker/api/types/backend"
15 15
 	containertypes "github.com/docker/docker/api/types/container"
16 16
 	"github.com/docker/docker/api/types/events"
17
-	"github.com/docker/docker/api/types/strslice"
18 17
 	"github.com/docker/docker/container"
19 18
 	"github.com/docker/docker/container/stream"
20 19
 	"github.com/docker/docker/errdefs"
... ...
@@ -100,9 +99,6 @@ func (daemon *Daemon) ContainerExecCreate(name string, options *containertypes.E
100 100
 		return "", err
101 101
 	}
102 102
 
103
-	cmd := strslice.StrSlice(options.Cmd)
104
-	entrypoint, args := daemon.getEntrypointAndArgs(strslice.StrSlice{}, cmd)
105
-
106 103
 	keys := []byte{}
107 104
 	if options.DetachKeys != "" {
108 105
 		keys, err = term.ToBytes(options.DetachKeys)
... ...
@@ -117,8 +113,7 @@ func (daemon *Daemon) ContainerExecCreate(name string, options *containertypes.E
117 117
 	execConfig.OpenStdout = options.AttachStdout
118 118
 	execConfig.OpenStderr = options.AttachStderr
119 119
 	execConfig.DetachKeys = keys
120
-	execConfig.Entrypoint = entrypoint
121
-	execConfig.Args = args
120
+	execConfig.Entrypoint, execConfig.Args = options.Cmd[0], options.Cmd[1:]
122 121
 	execConfig.Tty = options.Tty
123 122
 	execConfig.ConsoleSize = options.ConsoleSize
124 123
 	execConfig.Privileged = options.Privileged
... ...
@@ -13,7 +13,6 @@ import (
13 13
 	"github.com/docker/docker/api/types/backend"
14 14
 	containertypes "github.com/docker/docker/api/types/container"
15 15
 	"github.com/docker/docker/api/types/events"
16
-	"github.com/docker/docker/api/types/strslice"
17 16
 	"github.com/docker/docker/container"
18 17
 	"github.com/docker/docker/internal/metrics"
19 18
 )
... ...
@@ -69,18 +68,16 @@ type cmdProbe struct {
69 69
 // Returns the exit code and probe output (if any)
70 70
 func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container) (*containertypes.HealthcheckResult, error) {
71 71
 	startTime := time.Now()
72
-	cmdSlice := strslice.StrSlice(cntr.Config.Healthcheck.Test)[1:]
72
+	cmd := cntr.Config.Healthcheck.Test[1:]
73 73
 	if p.shell {
74
-		cmdSlice = append(getShell(cntr), cmdSlice...)
74
+		cmd = append(getShell(cntr), cmd...)
75 75
 	}
76
-	entrypoint, args := d.getEntrypointAndArgs(strslice.StrSlice{}, cmdSlice)
77 76
 	execConfig := container.NewExecConfig(cntr)
78 77
 	execConfig.OpenStdin = false
79 78
 	execConfig.OpenStdout = true
80 79
 	execConfig.OpenStderr = true
81 80
 	execConfig.DetachKeys = []byte{}
82
-	execConfig.Entrypoint = entrypoint
83
-	execConfig.Args = args
81
+	execConfig.Entrypoint, execConfig.Args = cmd[0], cmd[1:]
84 82
 	execConfig.Tty = false
85 83
 	execConfig.Privileged = false
86 84
 	execConfig.User = cntr.Config.User