summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-02-03 15:20:19 -0500
committerMatthew Heon <matthew.heon@pm.me>2020-03-18 11:02:14 -0400
commitf138405b46cdeb1cd8848ffc169a355433def9e2 (patch)
treea30f58910f618d470e18a3c38384484b47c0d1f8 /libpod
parentd9eb078e2a1cff73461f285924ab1ab8699e9bca (diff)
downloadpodman-f138405b46cdeb1cd8848ffc169a355433def9e2.tar.gz
podman-f138405b46cdeb1cd8848ffc169a355433def9e2.tar.bz2
podman-f138405b46cdeb1cd8848ffc169a355433def9e2.zip
Populate ExecSession with all required fields
As part of the rework of exec sessions, we want to split Create and Start - and, as a result, we need to keep everything needed to start exec sessions in the struct, not just the bare minimum for tracking running ones. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go45
-rw-r--r--libpod/define/containerstate.go34
2 files changed, 77 insertions, 2 deletions
diff --git a/libpod/container.go b/libpod/container.go
index dbd15e55f..d3359e24d 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -216,9 +216,50 @@ type ContainerState struct {
// ExecSession contains information on an active exec session
type ExecSession struct {
- ID string `json:"id"`
+ // ID is the ID of the exec session.
+ ID string `json:"id"`
+ // Command the the command that will be invoked in the exec session.
Command []string `json:"command"`
- PID int `json:"pid"`
+ // State is the state of the exec session.
+ State define.ContainerExecStatus `json:"state"`
+ // PID is the PID of the process created by the exec session.
+ PID int `json:"pid,omitempty"`
+
+ // Terminal is whether the exec session will allocate a pseudoterminal.
+ Terminal bool `json:"terminal,omitempty"`
+ // AttachStdin is whether the STDIN stream will be forwarded to the exec
+ // session's first process when attaching. Only available if Terminal is
+ // false.
+ AttachStdin bool `json:"attachStdin,omitempty"`
+ // AttachStdout is whether the STDOUT stream will be forwarded to the
+ // exec session's first process when attaching. Only available if
+ // Terminal is false.
+ AttachStdout bool `json:"attachStdout,omitempty"`
+ // AttachStderr is whether the STDERR stream will be forwarded to the
+ // exec session's first process when attaching. Only available if
+ // Terminal is false.
+ AttachStderr bool `json:"attachStderr,omitempty"`
+ // DetachKeys are keys that will be used to detach from the exec
+ // session. Here, nil will use the default detach keys, where a pointer
+ // to the empty string ("") will disable detaching via detach keys.
+ DetachKeys *string `json:"detachKeys,omitempty"`
+ // Environment is a set of environment variables that will be set for
+ // the first process started by the exec session.
+ Environment map[string]string `json:"environment,omitempty"`
+ // Privileged is whether the exec session will be privileged - that is,
+ // will be granted additional capabilities.
+ Privileged bool `json:"privileged,omitempty"`
+ // User is the user the exec session will be run as.
+ User string `json:"user,omitempty"`
+ // WorkDir is the working directory for the first process that will be
+ // launched by the exec session.
+ WorkDir string `json:"workDir,omitempty"`
+ // PreserveFDs indicates that a number of extra FDs from the process
+ // running libpod will be passed into the container. These are assumed
+ // to begin at 3 (immediately after the standard streams). The number
+ // given is the number that will be passed into the exec session,
+ // starting at 3.
+ PreserveFDs uint `json:"preserveFds,omitempty"`
}
// ContainerConfig contains all information that was used to create the
diff --git a/libpod/define/containerstate.go b/libpod/define/containerstate.go
index e7d258e21..6da49a594 100644
--- a/libpod/define/containerstate.go
+++ b/libpod/define/containerstate.go
@@ -78,3 +78,37 @@ func StringToContainerStatus(status string) (ContainerStatus, error) {
return ContainerStateUnknown, errors.Wrapf(ErrInvalidArg, "unknown container state: %s", status)
}
}
+
+// ContainerExecStatus is the status of an exec session within a container.
+type ContainerExecStatus int
+
+const (
+ // ExecStateUnknown indicates that the state of the exec session is not
+ // known.
+ ExecStateUnknown ContainerExecStatus = iota
+ // ExecStateCreated indicates that the exec session has been created but
+ // not yet started
+ ExecStateCreated ContainerExecStatus = iota
+ // ExecStateRunning indicates that the exec session has been started but
+ // has not yet exited.
+ ExecStateRunning ContainerExecStatus = iota
+ // ExecStateStopped indicates that the exec session has stopped and is
+ // no longer running.
+ ExecStateStopped ContainerExecStatus = iota
+)
+
+// String returns a string representation of a given exec state.
+func (s ContainerExecStatus) String() string {
+ switch s {
+ case ExecStateUnknown:
+ return "unknown"
+ case ExecStateCreated:
+ return "created"
+ case ExecStateRunning:
+ return "running"
+ case ExecStateStopped:
+ return "stopped"
+ default:
+ return "bad state"
+ }
+}