From 890eb805010a6bee6e060ee3f9415189940fb2af Mon Sep 17 00:00:00 2001
From: Pierre Souchay
Date: Wed, 7 Nov 2018 00:08:23 +0100
Subject: [PATCH] Better comments for fallback on /etc/machine-id
---
host/host_linux.go | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/host/host_linux.go b/host/host_linux.go
index 2981675..2c1ac6b 100644
--- a/host/host_linux.go
+++ b/host/host_linux.go
@@ -75,7 +75,8 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
sysProductUUID := common.HostSys("class/dmi/id/product_uuid")
machineID := common.HostEtc("machine-id")
switch {
- // When not running as root, lib cannot read the value
+ // In order to read this file, needs to be supported by kernel/arch and run as root
+ // so having fallback is important
case common.PathExists(sysProductUUID):
lines, err := common.ReadLines(sysProductUUID)
if err == nil && len(lines) > 0 && lines[0] != "" {
@@ -83,6 +84,7 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
break
}
fallthrough
+ // Fallback on GNU Linux systems with systemd, readable by everyone
case common.PathExists(machineID):
lines, err := common.ReadLines(machineID)
if err == nil && len(lines) > 0 && len(lines[0]) == 32 {
@@ -91,6 +93,7 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
break
}
fallthrough
+ // Not stable between reboot, but better than nothing
default:
values, err := common.DoSysctrl("kernel.random.boot_id")
if err == nil && len(values) == 1 && values[0] != "" {