Skip to content

Commit

Permalink
libpod: cleanupNetwork() return error
Browse files Browse the repository at this point in the history
Return the error not just log as the caller can then decide to log this
and exit > 0. I also removed the c.valid check as I do not see what the
purpose of this would be. c.valid is only false when the ctr was removed
but then we should never get there as Cleanup() will not work on a
container in removing state.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Aug 9, 2024
1 parent 8c79fa9 commit f2a03e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 9 additions & 6 deletions libpod/container_internal_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,18 @@ func (c *Container) cleanupNetwork() error {
}

// Stop the container's network namespace (if it has one)
if err := c.runtime.teardownNetNS(c); err != nil {
logrus.Errorf("Unable to cleanup network for container %s: %q", c.ID(), err)
}
neterr := c.runtime.teardownNetNS(c)

if c.valid {
return c.save()
// always save even when there was an error
err = c.save()
if err != nil {
if neterr != nil {
logrus.Errorf("Unable to clean up network for container %s: %q", c.ID(), neterr)
}
return err
}

return nil
return neterr
}

// reloadNetwork reloads the network for the given container, recreating
Expand Down
16 changes: 9 additions & 7 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,20 @@ func (c *Container) cleanupNetwork() error {
}

// Stop the container's network namespace (if it has one)
if err := c.runtime.teardownNetNS(c); err != nil {
logrus.Errorf("Unable to clean up network for container %s: %q", c.ID(), err)
}

neterr := c.runtime.teardownNetNS(c)
c.state.NetNS = ""
c.state.NetworkStatus = nil

if c.valid {
return c.save()
// always save even when there was an error
err = c.save()
if err != nil {
if neterr != nil {
logrus.Errorf("Unable to clean up network for container %s: %q", c.ID(), neterr)
}
return err
}

return nil
return neterr
}

// reloadNetwork reloads the network for the given container, recreating
Expand Down

0 comments on commit f2a03e5

Please sign in to comment.