From aa0b73dc6d5669de5bc9483c0655b1f9446317a9 Mon Sep 17 00:00:00 2001 From: Niv Govrin <138374496+govrin@users.noreply.github.com> Date: Sun, 26 May 2024 11:48:29 +0300 Subject: [PATCH] fix: return boot time from stat file add missing return statement for boot time value retrieved from stat file. Also move current time fetch to be closer to where the "time since boot file" is read --- internal/common/common_linux.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index a429e16..8f36c70 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -90,6 +90,8 @@ func BootTimeWithContext(ctx context.Context, enableCache bool) (uint64, error) if enableCache { atomic.StoreUint64(&cachedBootTime, t) } + + return t, nil } filename := HostProcWithContext(ctx, "uptime") @@ -97,6 +99,8 @@ func BootTimeWithContext(ctx context.Context, enableCache bool) (uint64, error) if err != nil { return handleBootTimeFileReadErr(err) } + currentTime := float64(time.Now().UnixNano()) / float64(time.Second) + if len(lines) != 1 { return 0, fmt.Errorf("wrong uptime format") } @@ -105,7 +109,6 @@ func BootTimeWithContext(ctx context.Context, enableCache bool) (uint64, error) if err != nil { return 0, err } - currentTime := float64(time.Now().UnixNano()) / float64(time.Second) t := currentTime - b if enableCache {