Skip to content

Commit

Permalink
Change Inherit to use a pointer to a container
Browse files Browse the repository at this point in the history
This fixes a lint issue, but I'm keeping it in its own commit so
it can be reverted independently if necessary; I don't know what
side effects this may have. I don't *think* there are any
issues, but I'm not sure why it wasn't a pointer in the first
place, so there may have been a reason.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
  • Loading branch information
mheon committed May 22, 2023
1 parent 3a3d952 commit 7091bdd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cmd/podman/pods/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b
return nil
}
setExitCode(err)
return append(errs, err)
errs = append(errs, err)
if !strings.Contains(err.Error(), define.ErrRemovingCtrs.Error()) {
return errs
}
}

// in the cli, first we print out all the successful attempts
Expand Down
2 changes: 2 additions & 0 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ type Container struct {
// threads of the same Podman process from removing the same container
// at the same time (when using recursive removal of dependencies).
// This probably should not be used outside of `removeContainer`.
// This lock should only every be taken *AFTER* and released *BEFORE*
// the main container lock, to prevent ABBA deadlocks.
perProcessLock sync.Mutex

rootlessSlirpSyncR *os.File
Expand Down
4 changes: 2 additions & 2 deletions libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,8 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, opts ctrRmO
c.perProcessLock.Lock()
defer func() {
if locked {
c.lock.Unlock()
c.perProcessLock.Unlock()
c.lock.Unlock()
}
}()
locked = true
Expand Down Expand Up @@ -811,8 +811,8 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, opts ctrRmO
// immediately after.
if locked {
locked = false
c.lock.Unlock()
c.perProcessLock.Unlock()
c.lock.Unlock()
}

logrus.Infof("Removing pod %s (dependency of container %s)", pod.ID(), c.ID())
Expand Down
2 changes: 1 addition & 1 deletion libpod/runtime_pod_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool,
}

if len(ctrErrors) > 0 {
return removedCtrs, fmt.Errorf("not all containers could be removed from pod %s: %w", p.ID(), define.ErrCtrExists)
return removedCtrs, fmt.Errorf("not all containers could be removed from pod %s: %w", p.ID(), define.ErrRemovingCtrs)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/specgen/generate/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
compatibleOptions := &libpod.InfraInherit{}
var infraSpec *specs.Spec
if infra != nil {
options, infraSpec, compatibleOptions, err = Inherit(*infra, s, rt)
options, infraSpec, compatibleOptions, err = Inherit(infra, s, rt)
if err != nil {
return nil, nil, nil, err
}
Expand Down Expand Up @@ -636,7 +636,7 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l
return options, nil
}

func Inherit(infra libpod.Container, s *specgen.SpecGenerator, rt *libpod.Runtime) (opts []libpod.CtrCreateOption, infraS *specs.Spec, compat *libpod.InfraInherit, err error) {
func Inherit(infra *libpod.Container, s *specgen.SpecGenerator, rt *libpod.Runtime) (opts []libpod.CtrCreateOption, infraS *specs.Spec, compat *libpod.InfraInherit, err error) {
inheritSpec := &specgen.SpecGenerator{}
_, compatibleOptions, err := ConfigToSpec(rt, inheritSpec, infra.ID())
if err != nil {
Expand Down

0 comments on commit 7091bdd

Please sign in to comment.