From badb7a1c12a5a7ed3954ba79012176adc030f7ff Mon Sep 17 00:00:00 2001 From: Aman Karmani Date: Tue, 11 Oct 2022 13:16:00 -0700 Subject: [PATCH 1/2] [android][host] fallback to sysinfo() syscall for uptime with Android O, /proc/{stat,uptime} both return permission denied --- internal/common/common_linux.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 41916de3b..032522d6f 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -12,6 +12,7 @@ import ( "strconv" "strings" "sync" + "syscall" "time" ) @@ -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 { return 0, err } From 05a8e9c33f4caeca0f30ecac3d47472132515a99 Mon Sep 17 00:00:00 2001 From: Aman Gupta Karmani Date: Tue, 25 Oct 2022 16:45:56 -0700 Subject: [PATCH 2/2] Remove useless else if --- internal/common/common_linux.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 032522d6f..3b4de8e53 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -79,7 +79,8 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { currentTime := time.Now().UnixNano() / int64(time.Second) t := currentTime - int64(info.Uptime) return uint64(t), nil - } else if err != nil { + } + if err != nil { return 0, err }