Skip to content

Commit

Permalink
fix: return boot time from stat file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
govrin authored May 26, 2024
1 parent 8912445 commit aa0b73d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/common/common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ func BootTimeWithContext(ctx context.Context, enableCache bool) (uint64, error)
if enableCache {
atomic.StoreUint64(&cachedBootTime, t)
}

return t, nil
}

filename := HostProcWithContext(ctx, "uptime")
lines, err := ReadLines(filename)
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")
}
Expand All @@ -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 {
Expand Down

0 comments on commit aa0b73d

Please sign in to comment.