1// +build linux 2 3package machineid 4 5const ( 6 // dbusPath is the default path for dbus machine id. 7 dbusPath = "/var/lib/dbus/machine-id" 8 // dbusPathEtc is the default path for dbus machine id located in /etc. 9 // Some systems (like Fedora 20) only know this path. 10 // Sometimes it's the other way round. 11 dbusPathEtc = "/etc/machine-id" 12) 13 14// machineID returns the uuid specified at `/var/lib/dbus/machine-id` or `/etc/machine-id`. 15// If there is an error reading the files an empty string is returned. 16// See https://unix.stackexchange.com/questions/144812/generate-consistent-machine-unique-id 17func machineID() (string, error) { 18 id, err := readFile(dbusPath) 19 if err != nil { 20 // try fallback path 21 id, err = readFile(dbusPathEtc) 22 } 23 if err != nil { 24 return "", err 25 } 26 return trim(string(id)), nil 27} 28