From 1e499bae79c992f185601cf336f725c83880cef2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 11 Jul 2025 14:05:57 +0200 Subject: [PATCH] daemon: consolidate platform-specific inspectExecProcessConfig 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 --- daemon/inspect.go | 38 ++++++++++++++++++++++++++------------ daemon/inspect_linux.go | 11 ----------- daemon/inspect_windows.go | 9 --------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/daemon/inspect.go b/daemon/inspect.go index 658305aca7..bcf63f1e59 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "runtime" "time" containertypes "github.com/moby/moby/api/types/container" @@ -207,24 +208,37 @@ func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, err e.Lock() defer e.Unlock() - pc := inspectExecProcessConfig(e) var pid int if e.Process != nil { pid = int(e.Process.Pid()) } + var privileged *bool + if runtime.GOOS != "windows" || e.Privileged { + // Privileged is not used on Windows, so should always be false + // (and omitted in the response), but set it if it happened to + // be true. On non-Windows, we always set it, and the field should + // not be omitted. + privileged = &e.Privileged + } return &backend.ExecInspect{ - ID: e.ID, - Running: e.Running, - ExitCode: e.ExitCode, - ProcessConfig: pc, - OpenStdin: e.OpenStdin, - OpenStdout: e.OpenStdout, - OpenStderr: e.OpenStderr, - CanRemove: e.CanRemove, - ContainerID: e.Container.ID, - DetachKeys: e.DetachKeys, - Pid: pid, + ID: e.ID, + Running: e.Running, + ExitCode: e.ExitCode, + ProcessConfig: &backend.ExecProcessConfig{ + Tty: e.Tty, + Entrypoint: e.Entrypoint, + Arguments: e.Args, + Privileged: privileged, // Privileged is not used on Windows + User: e.User, // User is not used on Windows + }, + OpenStdin: e.OpenStdin, + OpenStdout: e.OpenStdout, + OpenStderr: e.OpenStderr, + CanRemove: e.CanRemove, + ContainerID: e.Container.ID, + DetachKeys: e.DetachKeys, + Pid: pid, }, nil } diff --git a/daemon/inspect_linux.go b/daemon/inspect_linux.go index 0db579f4e0..3d79cd6af2 100644 --- a/daemon/inspect_linux.go +++ b/daemon/inspect_linux.go @@ -3,7 +3,6 @@ package daemon import ( "github.com/moby/moby/api/types/container" containerpkg "github.com/moby/moby/v2/daemon/container" - "github.com/moby/moby/v2/daemon/server/backend" ) // This sets platform-specific fields @@ -15,13 +14,3 @@ func setPlatformSpecificContainerFields(container *containerpkg.Container, contJ return contJSONBase } - -func inspectExecProcessConfig(e *containerpkg.ExecConfig) *backend.ExecProcessConfig { - return &backend.ExecProcessConfig{ - Tty: e.Tty, - Entrypoint: e.Entrypoint, - Arguments: e.Args, - Privileged: &e.Privileged, - User: e.User, - } -} diff --git a/daemon/inspect_windows.go b/daemon/inspect_windows.go index 38f3ef13cd..e98aecab27 100644 --- a/daemon/inspect_windows.go +++ b/daemon/inspect_windows.go @@ -3,18 +3,9 @@ package daemon import ( "github.com/moby/moby/api/types/container" containerpkg "github.com/moby/moby/v2/daemon/container" - "github.com/moby/moby/v2/daemon/server/backend" ) // This sets platform-specific fields func setPlatformSpecificContainerFields(container *containerpkg.Container, contJSONBase *container.ContainerJSONBase) *container.ContainerJSONBase { return contJSONBase } - -func inspectExecProcessConfig(e *containerpkg.ExecConfig) *backend.ExecProcessConfig { - return &backend.ExecProcessConfig{ - Tty: e.Tty, - Entrypoint: e.Entrypoint, - Arguments: e.Args, - } -}