Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android][host] fix Info() failure due to forbidden /proc/stat and /proc/uptime #1361

Merged
merged 2 commits into from Nov 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 - int64(info.Uptime)
return uint64(t), nil
} else if err != nil {
tmm1 marked this conversation as resolved.
Show resolved Hide resolved
return 0, err
}

Expand Down