From d490d634ca0cff0150ce1f6d4385ce98c01881a6 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 11 Aug 2016 01:29:46 -0700 Subject: [PATCH] On Linux, attempt to read from /sys/class/dmi/id/product_uuid first before falling back to kernel.random.boot_id. `/sys/class/dmi/id/product_uuid` is still managed by permissions, so for root-run processes where `/sys/class/dmi/id/product_uuid` is available, the host's UUID will be used instead, otherwise the UUID from kernel.random.boot_id will be used instead. --- host/host_linux.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/host/host_linux.go b/host/host_linux.go index a9f3749..838609c 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -61,9 +61,20 @@ func Info() (*InfoStat, error) { ret.Procs = numProcs } - values, err := common.DoSysctrl("kernel.random.boot_id") - if err == nil && len(values) == 1 && values[0] != "" { - ret.HostID = values[0] + sysProductUUID := common.HostSys("class/dmi/id/product_uuid") + switch { + case common.PathExists(sysProductUUID): + lines, err := common.ReadLines(sysProductUUID) + if err == nil && len(lines) > 0 && lines[0] != "" { + ret.HostID = lines[0] + break + } + fallthrough + default: + values, err := common.DoSysctrl("kernel.random.boot_id") + if err == nil && len(values) == 1 && values[0] != "" { + ret.HostID = values[0] + } } return ret, nil