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
pull/1655/head
Niv Govrin committed by GitHub
parent 89124453c1
commit aa0b73dc6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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 {

Loading…
Cancel
Save