From f2a03e575322f60384480a12ff137ebc2776b90b Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 8 Aug 2024 16:37:35 +0200 Subject: [PATCH] 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 --- libpod/container_internal_freebsd.go | 17 ++++++++++------- libpod/container_internal_linux.go | 16 +++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/libpod/container_internal_freebsd.go b/libpod/container_internal_freebsd.go index ac9892ef2a..4635da064b 100644 --- a/libpod/container_internal_freebsd.go +++ b/libpod/container_internal_freebsd.go @@ -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 diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index c479a0255d..5ea2448e20 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -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