summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_api.go13
-rw-r--r--libpod/container_internal.go11
-rw-r--r--libpod/define/exec_codes.go18
-rw-r--r--libpod/oci_attach_linux.go7
-rw-r--r--libpod/pod_api.go12
5 files changed, 57 insertions, 4 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 9bf97c5d4..4f0d5301c 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -216,8 +216,8 @@ func (c *Container) Kill(signal uint) error {
}
// Exec starts a new process inside the container
-// Returns an exit code and an error. If Exec was not able to exec in the container before a failure, an exit code of 126 is returned.
-// If another generic error happens, an exit code of 125 is returned.
+// Returns an exit code and an error. If Exec was not able to exec in the container before a failure, an exit code of define.ExecErrorCodeCannotInvoke is returned.
+// If another generic error happens, an exit code of define.ExecErrorCodeGeneric is returned.
// Sometimes, the $RUNTIME exec call errors, and if that is the case, the exit code is the exit code of the call.
// Otherwise, the exit code will be the exit code of the executed call inside of the container.
// TODO investigate allowing exec without attaching
@@ -821,3 +821,12 @@ func (c *Container) Restore(ctx context.Context, options ContainerCheckpointOpti
defer c.newContainerEvent(events.Restore)
return c.restore(ctx, options)
}
+
+// AutoRemove indicates whether the container will be removed after it is executed
+func (c *Container) AutoRemove() bool {
+ spec := c.config.Spec
+ if spec.Annotations == nil {
+ return false
+ }
+ return c.Spec().Annotations[InspectAnnotationAutoremove] == InspectResponseTrue
+}
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 0b5a8b946..6bf8439da 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -14,6 +14,7 @@ import (
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/events"
+ "github.com/containers/libpod/pkg/cgroups"
"github.com/containers/libpod/pkg/ctime"
"github.com/containers/libpod/pkg/hooks"
"github.com/containers/libpod/pkg/hooks/exec"
@@ -1132,6 +1133,16 @@ func (c *Container) pause() error {
return errors.Wrapf(define.ErrNoCgroups, "cannot pause without using CGroups")
}
+ if rootless.IsRootless() {
+ cgroupv2, err := cgroups.IsCgroup2UnifiedMode()
+ if err != nil {
+ return errors.Wrap(err, "failed to determine cgroupversion")
+ }
+ if !cgroupv2 {
+ return errors.Wrap(define.ErrNoCgroups, "can not pause containers on rootless containers with cgroup V1")
+ }
+ }
+
if err := c.ociRuntime.pauseContainer(c); err != nil {
return err
}
diff --git a/libpod/define/exec_codes.go b/libpod/define/exec_codes.go
index 7184f1e59..33d631326 100644
--- a/libpod/define/exec_codes.go
+++ b/libpod/define/exec_codes.go
@@ -1,6 +1,8 @@
package define
import (
+ "strings"
+
"github.com/pkg/errors"
)
@@ -28,3 +30,19 @@ func TranslateExecErrorToExitCode(originalEC int, err error) int {
}
return originalEC
}
+
+// ExitCode reads the error message when failing to executing container process
+// and then returns 0 if no error, ExecErrorCodeNotFound if command does not exist, or ExecErrorCodeCannotInvoke for
+// all other errors
+func ExitCode(err error) int {
+ if err == nil {
+ return 0
+ }
+ e := strings.ToLower(err.Error())
+ if strings.Contains(e, "file not found") ||
+ strings.Contains(e, "no such file or directory") {
+ return ExecErrorCodeNotFound
+ }
+
+ return ExecErrorCodeCannotInvoke
+}
diff --git a/libpod/oci_attach_linux.go b/libpod/oci_attach_linux.go
index 22afa7416..6cada0801 100644
--- a/libpod/oci_attach_linux.go
+++ b/libpod/oci_attach_linux.go
@@ -107,8 +107,6 @@ func (c *Container) attachToExec(streams *AttachStreams, keys string, resize <-c
logrus.Debugf("Attaching to container %s exec session %s", c.ID(), sessionID)
- registerResizeFunc(resize, c.execBundlePath(sessionID))
-
// set up the socket path, such that it is the correct length and location for exec
socketPath := buildSocketPath(c.execAttachSocketPath(sessionID))
@@ -116,6 +114,7 @@ func (c *Container) attachToExec(streams *AttachStreams, keys string, resize <-c
if _, err := readConmonPipeData(attachFd, ""); err != nil {
return err
}
+
// 2: then attach
conn, err := net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: socketPath, Net: "unixpacket"})
if err != nil {
@@ -127,6 +126,10 @@ func (c *Container) attachToExec(streams *AttachStreams, keys string, resize <-c
}
}()
+ // Register the resize func after we've read the attach socket, as we know at this point the
+ // 'ctl' file has been created in conmon
+ registerResizeFunc(resize, c.execBundlePath(sessionID))
+
// start listening on stdio of the process
receiveStdoutError, stdinDone := setupStdioChannels(streams, conn, detachKeys)
diff --git a/libpod/pod_api.go b/libpod/pod_api.go
index e2448e92a..7c786b835 100644
--- a/libpod/pod_api.go
+++ b/libpod/pod_api.go
@@ -5,6 +5,8 @@ import (
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/events"
+ "github.com/containers/libpod/pkg/cgroups"
+ "github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -163,6 +165,16 @@ func (p *Pod) Pause() (map[string]error, error) {
return nil, define.ErrPodRemoved
}
+ if rootless.IsRootless() {
+ cgroupv2, err := cgroups.IsCgroup2UnifiedMode()
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to determine cgroupversion")
+ }
+ if !cgroupv2 {
+ return nil, errors.Wrap(define.ErrNoCgroups, "can not pause pods containing rootless containers with cgroup V1")
+ }
+ }
+
allCtrs, err := p.runtime.state.PodContainers(p)
if err != nil {
return nil, err