//go:build freebsd || netbsd || openbsd || dragonfly || solaris
// +build freebsd netbsd openbsd dragonfly solaris

package machineid

import (
	"io/ioutil"
	"os/exec"
)

func getMachineID() (s string, err error) {
	paths := []string{
		"/etc/hostid",
		"/sys/class/dmi/id/product_uuid",
	}
	var (
		buf []byte
	)
	for _, p := range paths {
		if buf, err = ioutil.ReadFile(p); err == nil {
			s = string(buf)
			break
		}
	}
	if s == "" {
		cmd := exec.Command("kenv", "-q", "smbios.system.uuid")
		if buf, err = cmd.Output(); err == nil {
			s = string(buf)
		}
	}
	return
}
