Skip to content

Commit

Permalink
[android][host] fallback to sysinfo() syscall for uptime
Browse files Browse the repository at this point in the history
with Android O, /proc/{stat,uptime} both return permission denied
  • Loading branch information
tmm1 committed Oct 14, 2022
1 parent 400a453 commit 07e73f9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/common/common_linux.go
Expand Up @@ -12,6 +12,7 @@ import (
"strconv"
"strings"
"sync"
"syscall"
"time"
)

Expand Down Expand Up @@ -68,7 +69,17 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {

filename := HostProc(statFile)
lines, err := ReadLines(filename)
if err != nil {
if os.IsPermission(err) {
var info syscall.Sysinfo_t
err := syscall.Sysinfo(&info)
if err != nil {
return 0, err
}

currentTime := time.Now().UnixNano() / int64(time.Second)
t := currentTime - info.Uptime
return uint64(t), nil
} else if err != nil {
return 0, err
}

Expand Down

0 comments on commit 07e73f9

Please sign in to comment.