|
|
|
@ -109,6 +109,7 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statFile := "stat"
|
|
|
|
|
if system == "lxc" && role == "guest" {
|
|
|
|
|
// if lxc, /proc/uptime is used.
|
|
|
|
@ -123,6 +124,8 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if statFile == "stat" {
|
|
|
|
|
for _, line := range lines {
|
|
|
|
|
if strings.HasPrefix(line, "btime") {
|
|
|
|
|
f := strings.Fields(line)
|
|
|
|
@ -138,6 +141,19 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|
|
|
|
return t, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if statFile == "uptime" {
|
|
|
|
|
if len(lines) != 1 {
|
|
|
|
|
return 0, fmt.Errorf("wrong uptime format")
|
|
|
|
|
}
|
|
|
|
|
f := strings.Fields(lines[0])
|
|
|
|
|
b, err := strconv.ParseInt(f[0], 10, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
t = uint64(time.Now().Unix()) - uint64(b)
|
|
|
|
|
atomic.StoreUint64(&cachedBootTime, t)
|
|
|
|
|
return t, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0, fmt.Errorf("could not find btime")
|
|
|
|
|
}
|
|
|
|
|