[host] linux: change file if in a lxc container.

pull/441/head
shirou 8 years ago
parent 48fc561289
commit dc3a09c1d0

@ -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

@ -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) {

Loading…
Cancel
Save