Skip to content

Commit

Permalink
fallback to device-tree when DMI informations are not available
Browse files Browse the repository at this point in the history
  • Loading branch information
EdouardVanbelle committed Nov 16, 2024
1 parent 86e1735 commit 82e0246
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions product.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ func (si *SysInfo) getProductInfo() {
if err == nil {
si.Product.UUID = uid
}

// try a fallback to device-tree (ex: dmi is not available on ARM devices)
// full details: https://www.devicetree.org/specifications/

// on linux root path is /proc/device-tree (see: https://github.com/torvalds/linux/blob/v5.9/Documentation/ABI/testing/sysfs-firmware-ofw)
if si.Product.Name == "" {
si.Product.Name = slurpFile("/proc/device-tree/model")
}

if si.Product.Serial == "" {
si.Product.Serial = slurpFile("/proc/device-tree/serial-number")
}


}
3 changes: 2 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func slurpFile(path string) string {
return ""
}

return strings.TrimSpace(string(data))
// Trim spaces & \u0000 \uffff
return strings.TrimRight( string(data), " \r\n\t\u0000\uffff")
}

// Write one-liner text files, add newline, ignore errors (best effort).
Expand Down

0 comments on commit 82e0246

Please sign in to comment.