diff --git a/host/host_linux.go b/host/host_linux.go index 14893a4..06d469b 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -95,7 +95,18 @@ func BootTime() (uint64, error) { if t != 0 { return t, nil } - filename := common.HostProc("stat") + + system, role, err := Virtualization() + if err != nil { + return 0, err + } + statFile := "stat" + if system == "lxc" && role == "guest" { + // if lxc, /proc/uptime is used. + statFile = "uptime" + } + + filename := common.HostProc(statFile) lines, err := common.ReadLines(filename) if err != nil { return 0, err diff --git a/host/host_test.go b/host/host_test.go index 65f7a75..d9e6611 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -40,11 +40,13 @@ func TestBoot_time(t *testing.T) { if v < 946652400 { t.Errorf("Invalid Boottime, older than 2000-01-01") } + t.Logf("first boot time: %d", v) v2, err := BootTime() if v != v2 { t.Errorf("cached boot time is different") } + t.Logf("second boot time: %d", v2) } func TestUsers(t *testing.T) {