From f8a79409c4762d736664ebf8b8e320b6ef238962 Mon Sep 17 00:00:00 2001 From: Doug Rabson Date: Sun, 9 Oct 2022 08:13:30 +0100 Subject: [PATCH] libpod: Factor out jail name construction from stats_freebsd.go [NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson --- libpod/container_internal_freebsd.go | 8 ++++++++ libpod/stats_freebsd.go | 8 ++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libpod/container_internal_freebsd.go b/libpod/container_internal_freebsd.go index 468f5725c7..cae11cd2ba 100644 --- a/libpod/container_internal_freebsd.go +++ b/libpod/container_internal_freebsd.go @@ -279,3 +279,11 @@ func (c *Container) getConmonPidFd() int { // keeping things simple for now. return -1 } + +func (c *Container) jailName() string { + if c.state.NetNS != nil { + return c.state.NetNS.Name + "." + c.ID() + } else { + return c.ID() + } +} diff --git a/libpod/stats_freebsd.go b/libpod/stats_freebsd.go index 53bc3f19a8..6c036c78e0 100644 --- a/libpod/stats_freebsd.go +++ b/libpod/stats_freebsd.go @@ -20,13 +20,9 @@ import ( func (c *Container) getPlatformContainerStats(stats *define.ContainerStats, previousStats *define.ContainerStats) error { now := uint64(time.Now().UnixNano()) - jailName := c.ID() - if c.state.NetNS != nil { - jailName = c.state.NetNS.Name + "." + jailName - } - entries, err := rctl.GetRacct("jail:" + jailName) + entries, err := rctl.GetRacct("jail:" + c.jailName()) if err != nil { - return fmt.Errorf("unable to read accounting for %s: %w", jailName, err) + return fmt.Errorf("unable to read accounting for %s: %w", c.jailName(), err) } // If the current total usage is less than what was previously