mirror of
https://github.com/stashapp/stash.git
synced 2025-12-10 10:22:18 +01:00
34 lines
534 B
Go
34 lines
534 B
Go
// +build linux
|
|
|
|
package sysutil
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
btimePrefix = []byte("btime ")
|
|
lineEnd = []byte("\n")
|
|
)
|
|
|
|
func init() {
|
|
buf, err := ioutil.ReadFile("/proc/stat")
|
|
if err != nil {
|
|
btime = time.Now()
|
|
return
|
|
}
|
|
for _, line := range bytes.SplitN(buf, lineEnd, -1) {
|
|
if bytes.HasPrefix(line, btimePrefix) {
|
|
t, err := strconv.ParseInt(string(line[len(btimePrefix):]), 10, 64)
|
|
if err != nil {
|
|
btime = time.Now()
|
|
return
|
|
}
|
|
btime = time.Unix(t, 0)
|
|
break
|
|
}
|
|
}
|
|
}
|