Skip to content

Commit

Permalink
Merge pull request #1655 from govrin/patch-1
Browse files Browse the repository at this point in the history
Fix boot time not returning stat file value
  • Loading branch information
shirou authored Jun 6, 2024
2 parents ac15d68 + 97351d2 commit bf0a7e9
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 bf0a7e9

Please sign in to comment.