aboutsummaryrefslogtreecommitdiff
path: root/libpod/oci_conmon_common.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/oci_conmon_common.go')
-rw-r--r--libpod/oci_conmon_common.go73
1 files changed, 59 insertions, 14 deletions
diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go
index 2c7c39726..8ef8ae721 100644
--- a/libpod/oci_conmon_common.go
+++ b/libpod/oci_conmon_common.go
@@ -277,15 +277,6 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error {
ctr.ID(), state.Status, define.ErrInternal)
}
- // Only grab exit status if we were not already stopped
- // If we were, it should already be in the database
- if ctr.state.State == define.ContainerStateStopped && oldState != define.ContainerStateStopped {
- if _, err := ctr.Wait(context.Background()); err != nil {
- logrus.Errorf("Waiting for container %s to exit: %v", ctr.ID(), err)
- }
- return nil
- }
-
// Handle ContainerStateStopping - keep it unless the container
// transitioned to no longer running.
if oldState == define.ContainerStateStopping && (ctr.state.State == define.ContainerStatePaused || ctr.state.State == define.ContainerStateRunning) {
@@ -316,6 +307,52 @@ func (r *ConmonOCIRuntime) StartContainer(ctr *Container) error {
return nil
}
+// UpdateContainer updates the given container's cgroup configuration
+func (r *ConmonOCIRuntime) UpdateContainer(ctr *Container, resources *spec.LinuxResources) error {
+ runtimeDir, err := util.GetRuntimeDir()
+ if err != nil {
+ return err
+ }
+ env := []string{fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir)}
+ if path, ok := os.LookupEnv("PATH"); ok {
+ env = append(env, fmt.Sprintf("PATH=%s", path))
+ }
+ args := r.runtimeFlags
+ args = append(args, "update")
+ tempFile, additionalArgs, err := generateResourceFile(resources)
+ if err != nil {
+ return err
+ }
+ defer os.Remove(tempFile)
+
+ args = append(args, additionalArgs...)
+ return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, env, r.path, append(args, ctr.ID())...)
+}
+
+func generateResourceFile(res *spec.LinuxResources) (string, []string, error) {
+ flags := []string{}
+ if res == nil {
+ return "", flags, nil
+ }
+
+ f, err := ioutil.TempFile("", "podman")
+ if err != nil {
+ return "", nil, err
+ }
+
+ j, err := json.Marshal(res)
+ if err != nil {
+ return "", nil, err
+ }
+ _, err = f.WriteString(string(j))
+ if err != nil {
+ return "", nil, err
+ }
+
+ flags = append(flags, "--resources="+f.Name())
+ return f.Name(), flags, nil
+}
+
// KillContainer sends the given signal to the given container.
// If all is set, send to all PIDs in the container.
// All is only supported if the container created cgroups.
@@ -392,13 +429,11 @@ func (r *ConmonOCIRuntime) StopContainer(ctr *Container, timeout uint, all bool)
}
}
- if err := r.KillContainer(ctr, 9, all); err != nil {
+ if err := r.KillContainer(ctr, uint(unix.SIGKILL), all); err != nil {
// Again, check if the container is gone. If it is, exit cleanly.
- err := unix.Kill(ctr.state.PID, 0)
- if err == unix.ESRCH {
+ if aliveErr := unix.Kill(ctr.state.PID, 0); errors.Is(aliveErr, unix.ESRCH) {
return nil
}
-
return fmt.Errorf("error sending SIGKILL to container %s: %w", ctr.ID(), err)
}
@@ -440,6 +475,16 @@ func (r *ConmonOCIRuntime) UnpauseContainer(ctr *Container) error {
return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, env, r.path, append(r.runtimeFlags, "resume", ctr.ID())...)
}
+// This filters out ENOTCONN errors which can happen on FreeBSD if the
+// other side of the connection is already closed.
+func socketCloseWrite(conn *net.UnixConn) error {
+ err := conn.CloseWrite()
+ if err != nil && errors.Is(err, syscall.ENOTCONN) {
+ return nil
+ }
+ return err
+}
+
// HTTPAttach performs an attach for the HTTP API.
// The caller must handle closing the HTTP connection after this returns.
// The cancel channel is not closed; it is up to the caller to do so after
@@ -652,7 +697,7 @@ func (r *ConmonOCIRuntime) HTTPAttach(ctr *Container, req *http.Request, w http.
return err
}
// copy stdin is done, close it
- if connErr := conn.CloseWrite(); connErr != nil {
+ if connErr := socketCloseWrite(conn); connErr != nil {
logrus.Errorf("Unable to close conn: %v", connErr)
}
case <-cancel: