diff options
author | Doug Rabson <dfr@rabson.org> | 2022-08-17 08:14:51 +0100 |
---|---|---|
committer | Doug Rabson <dfr@rabson.org> | 2022-08-24 10:55:52 +0100 |
commit | 694cbaca3745ca8fab8665d8ba88af6056dc16f8 (patch) | |
tree | 0066809fa165dba2f571fa120e7dc0ab494a4029 | |
parent | 877e673992845afa798582c970dfbdb26efa9d46 (diff) | |
download | podman-694cbaca3745ca8fab8665d8ba88af6056dc16f8.tar.gz podman-694cbaca3745ca8fab8665d8ba88af6056dc16f8.tar.bz2 podman-694cbaca3745ca8fab8665d8ba88af6056dc16f8.zip |
libpod: Read kernel version and uptime using buildah/pkg/util
[NO NEW TESTS NEEDED]
Signed-off-by: Doug Rabson <dfr@rabson.org>
-rw-r--r-- | libpod/info.go | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/libpod/info.go b/libpod/info.go index 96fd7242e..cdf453135 100644 --- a/libpod/info.go +++ b/libpod/info.go @@ -8,7 +8,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "math" "os" "runtime" @@ -18,6 +17,7 @@ import ( "time" "github.com/containers/buildah" + "github.com/containers/buildah/pkg/util" "github.com/containers/image/v5/pkg/sysregistriesv2" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/libpod/linkmode" @@ -89,7 +89,7 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) { hostDistributionInfo := r.GetHostDistributionInfo() - kv, err := readKernelVersion() + kv, err := util.ReadKernelVersion() if err != nil { return nil, fmt.Errorf("error reading kernel version: %w", err) } @@ -133,7 +133,7 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) { info.OCIRuntime = ociruntimeInfo } - duration, err := procUptime() + duration, err := util.ReadUptime() if err != nil { return nil, fmt.Errorf("error reading up time: %w", err) } @@ -263,31 +263,6 @@ func (r *Runtime) storeInfo() (*define.StoreInfo, error) { return &info, nil } -func readKernelVersion() (string, error) { - buf, err := ioutil.ReadFile("/proc/version") - if err != nil { - return "", err - } - f := bytes.Fields(buf) - if len(f) < 3 { - return string(bytes.TrimSpace(buf)), nil - } - return string(f[2]), nil -} - -func procUptime() (time.Duration, error) { - var zero time.Duration - buf, err := ioutil.ReadFile("/proc/uptime") - if err != nil { - return zero, err - } - f := bytes.Fields(buf) - if len(f) < 1 { - return zero, errors.New("unable to parse uptime from /proc/uptime") - } - return time.ParseDuration(string(f[0]) + "s") -} - // GetHostDistributionInfo returns a map containing the host's distribution and version func (r *Runtime) GetHostDistributionInfo() define.DistributionInfo { // Populate values in case we cannot find the values |