Skip to content

Commit

Permalink
ds-identify: fake dmidecode support on OpenBSD
Browse files Browse the repository at this point in the history
use sysctl's hw hierarchy, because it contains pretty much all we use
from dmidecode. Unlike dmidecode, we don't need to set
`kern.allowkmem=1` for this to work.
  • Loading branch information
igalic committed Dec 4, 2023
1 parent e76743e commit 2927d2a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tools/ds-identify
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,27 @@ get_kenv_field() {
_RET="$val"
}

get_sysctl_field() {
local sys_field="$1" sysctl_field="" val=""
command -v sysctl >/dev/null 2>&1 || {
warn "No sysctl program. Cannot read $sys_field."
return 1
}
case "$sys_field" in
chassis_vendor) kenv_field='hw.vendor';;
chassis_serial) kenv_field='hw.type';;
chassis_version) kenv_field='hw.uuid';;
sys_vendor) kenv_field='hw.vendor';;
product_name) kenv_field='hw.product';;
product_serial) kenv_field='hw.uuid';;
product_uuid) kenv_field='hw.uuid';;
*) error "Unknown field $sys_field. Cannot call sysctl."
return 1;;
esac
val=$(sysctl -nq "$kenv_field" 2>/dev/null) || return 1
_RET="$val"
}

dmi_decode() {
local sys_field="$1" dmi_field="" val=""
command -v dmidecode >/dev/null 2>&1 || {
Expand Down Expand Up @@ -237,6 +258,11 @@ get_dmi_field() {
return $?
fi

if [ "$DI_UNAME_KERNEL_NAME" = "OpenBSD" ]; then
get_sysctl_field "$1" || _RET="$ERROR"
return $?
fi

local path="${PATH_SYS_CLASS_DMI_ID}/$1"
if [ -d "${PATH_SYS_CLASS_DMI_ID}" ]; then
if [ -f "$path" ] && [ -r "$path" ]; then
Expand Down

0 comments on commit 2927d2a

Please sign in to comment.