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 1/2] 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 a429e16a2..8f36c701e 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 { From 97351d2736662636b481d5217a149428b9d66c5c Mon Sep 17 00:00:00 2001 From: Niv Govrin Date: Thu, 6 Jun 2024 09:36:24 +0000 Subject: [PATCH 2/2] fix: remove tab in empty line --- internal/common/common_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 89a682e8e..541de93d3 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -100,7 +100,7 @@ func BootTimeWithContext(ctx context.Context, enableCache bool) (uint64, error) return handleBootTimeFileReadErr(err) } currentTime := float64(time.Now().UnixNano()) / float64(time.Second) - + if len(lines) != 1 { return 0, fmt.Errorf("wrong uptime format") }