Merge pull request #50384 from thaJeztah/daemon_inspect_unify

daemon: consolidate platform-specific inspectExecProcessConfig
This commit is contained in:
Sebastiaan van Stijn
2025-08-01 20:25:02 +02:00
committed by GitHub
3 changed files with 26 additions and 32 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"runtime"
"time"
containertypes "github.com/moby/moby/api/types/container"
@@ -204,24 +205,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
}

View File

@@ -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,
}
}

View File

@@ -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,
}
}