libpod: cleanupNetwork() return error

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 <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-08-08 16:37:35 +02:00
parent 8c79fa99f0
commit f2a03e5753
2 changed files with 19 additions and 14 deletions

View File

@ -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)
// 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
}
if c.valid {
return c.save()
}
return nil
return neterr
}
// reloadNetwork reloads the network for the given container, recreating

View File

@ -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