This function was introduced in 1af76ef5970202bdbc7024d825c0fcfcc4ec6ede
and based on the previous code in the daemon, which had platform-specific
handling for exec inspect in [setPlatformSpecificExecProcessConfig], which
was added in 5fa2e4d4f2be7787ad29b1e6ffd9c026ea0c1925 to account for
Windows not having "Privileged" and not setting the "User".
Given that "User" would be empty and "Privileged" not set, we may as well
combine both platforms, and just return the info we have.
[setPlatformSpecificExecProcessConfig]: https://github.com/moby/moby/blob/1af76ef5970202bdbc7024d825c0fcfcc4ec6ede/daemon/exec_unix.go#L11-L21
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"context" |
| 8 | 8 |
"errors" |
| 9 | 9 |
"fmt" |
| 10 |
+ "runtime" |
|
| 10 | 11 |
"time" |
| 11 | 12 |
|
| 12 | 13 |
containertypes "github.com/moby/moby/api/types/container" |
| ... | ... |
@@ -207,24 +208,37 @@ func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, err |
| 207 | 207 |
|
| 208 | 208 |
e.Lock() |
| 209 | 209 |
defer e.Unlock() |
| 210 |
- pc := inspectExecProcessConfig(e) |
|
| 211 | 210 |
var pid int |
| 212 | 211 |
if e.Process != nil {
|
| 213 | 212 |
pid = int(e.Process.Pid()) |
| 214 | 213 |
} |
| 214 |
+ var privileged *bool |
|
| 215 |
+ if runtime.GOOS != "windows" || e.Privileged {
|
|
| 216 |
+ // Privileged is not used on Windows, so should always be false |
|
| 217 |
+ // (and omitted in the response), but set it if it happened to |
|
| 218 |
+ // be true. On non-Windows, we always set it, and the field should |
|
| 219 |
+ // not be omitted. |
|
| 220 |
+ privileged = &e.Privileged |
|
| 221 |
+ } |
|
| 215 | 222 |
|
| 216 | 223 |
return &backend.ExecInspect{
|
| 217 |
- ID: e.ID, |
|
| 218 |
- Running: e.Running, |
|
| 219 |
- ExitCode: e.ExitCode, |
|
| 220 |
- ProcessConfig: pc, |
|
| 221 |
- OpenStdin: e.OpenStdin, |
|
| 222 |
- OpenStdout: e.OpenStdout, |
|
| 223 |
- OpenStderr: e.OpenStderr, |
|
| 224 |
- CanRemove: e.CanRemove, |
|
| 225 |
- ContainerID: e.Container.ID, |
|
| 226 |
- DetachKeys: e.DetachKeys, |
|
| 227 |
- Pid: pid, |
|
| 224 |
+ ID: e.ID, |
|
| 225 |
+ Running: e.Running, |
|
| 226 |
+ ExitCode: e.ExitCode, |
|
| 227 |
+ ProcessConfig: &backend.ExecProcessConfig{
|
|
| 228 |
+ Tty: e.Tty, |
|
| 229 |
+ Entrypoint: e.Entrypoint, |
|
| 230 |
+ Arguments: e.Args, |
|
| 231 |
+ Privileged: privileged, // Privileged is not used on Windows |
|
| 232 |
+ User: e.User, // User is not used on Windows |
|
| 233 |
+ }, |
|
| 234 |
+ OpenStdin: e.OpenStdin, |
|
| 235 |
+ OpenStdout: e.OpenStdout, |
|
| 236 |
+ OpenStderr: e.OpenStderr, |
|
| 237 |
+ CanRemove: e.CanRemove, |
|
| 238 |
+ ContainerID: e.Container.ID, |
|
| 239 |
+ DetachKeys: e.DetachKeys, |
|
| 240 |
+ Pid: pid, |
|
| 228 | 241 |
}, nil |
| 229 | 242 |
} |
| 230 | 243 |
|
| ... | ... |
@@ -3,7 +3,6 @@ package daemon |
| 3 | 3 |
import ( |
| 4 | 4 |
"github.com/moby/moby/api/types/container" |
| 5 | 5 |
containerpkg "github.com/moby/moby/v2/daemon/container" |
| 6 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 7 | 6 |
) |
| 8 | 7 |
|
| 9 | 8 |
// This sets platform-specific fields |
| ... | ... |
@@ -15,13 +14,3 @@ func setPlatformSpecificContainerFields(container *containerpkg.Container, contJ |
| 15 | 15 |
|
| 16 | 16 |
return contJSONBase |
| 17 | 17 |
} |
| 18 |
- |
|
| 19 |
-func inspectExecProcessConfig(e *containerpkg.ExecConfig) *backend.ExecProcessConfig {
|
|
| 20 |
- return &backend.ExecProcessConfig{
|
|
| 21 |
- Tty: e.Tty, |
|
| 22 |
- Entrypoint: e.Entrypoint, |
|
| 23 |
- Arguments: e.Args, |
|
| 24 |
- Privileged: &e.Privileged, |
|
| 25 |
- User: e.User, |
|
| 26 |
- } |
|
| 27 |
-} |
| ... | ... |
@@ -3,18 +3,9 @@ package daemon |
| 3 | 3 |
import ( |
| 4 | 4 |
"github.com/moby/moby/api/types/container" |
| 5 | 5 |
containerpkg "github.com/moby/moby/v2/daemon/container" |
| 6 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 7 | 6 |
) |
| 8 | 7 |
|
| 9 | 8 |
// This sets platform-specific fields |
| 10 | 9 |
func setPlatformSpecificContainerFields(container *containerpkg.Container, contJSONBase *container.ContainerJSONBase) *container.ContainerJSONBase {
|
| 11 | 10 |
return contJSONBase |
| 12 | 11 |
} |
| 13 |
- |
|
| 14 |
-func inspectExecProcessConfig(e *containerpkg.ExecConfig) *backend.ExecProcessConfig {
|
|
| 15 |
- return &backend.ExecProcessConfig{
|
|
| 16 |
- Tty: e.Tty, |
|
| 17 |
- Entrypoint: e.Entrypoint, |
|
| 18 |
- Arguments: e.Args, |
|
| 19 |
- } |
|
| 20 |
-} |