From 8723ddc7e586f953f234379578c0cc416ab7cd0d Mon Sep 17 00:00:00 2001 From: Felipe Borges Date: Wed, 2 Dec 2020 14:55:21 +0100 Subject: [PATCH 1/3] hwdb: Add dmi-id database See #15493 --- hwdb.d/20-dmi-id.hwdb | 6 ++++++ hwdb.d/meson.build | 1 + 2 files changed, 7 insertions(+) create mode 100644 hwdb.d/20-dmi-id.hwdb diff --git a/hwdb.d/20-dmi-id.hwdb b/hwdb.d/20-dmi-id.hwdb new file mode 100644 index 0000000000..a614473bd9 --- /dev/null +++ b/hwdb.d/20-dmi-id.hwdb @@ -0,0 +1,6 @@ +# This file is part of systemd + +# Fix "Lenovo" capitalization in /sys/class/dmi/id/sys_vendor +dmi:bvnLENOVO* + ID_SYSFS_ATTRIBUTE_MODEL=product_version + ID_VENDOR_FROM_DATABASE=Lenovo diff --git a/hwdb.d/meson.build b/hwdb.d/meson.build index 6fcb364acd..f26e1f8576 100644 --- a/hwdb.d/meson.build +++ b/hwdb.d/meson.build @@ -4,6 +4,7 @@ # they are very long but quite repetitive and the parser is not very fast. # So we don't "test" them. hwdb_files_notest = files(''' + 20-dmi-id.hwdb 20-pci-vendor-model.hwdb 20-pci-classes.hwdb 20-usb-vendor-model.hwdb From 7341f6b58de6a11adacad0a39c2c243a7cd3349e Mon Sep 17 00:00:00 2001 From: Felipe Borges Date: Wed, 2 Dec 2020 13:45:35 +0100 Subject: [PATCH 2/3] rules.d: Add rule for the /sys/class/dmi/id device See #15493 --- rules.d/50-udev-default.rules.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rules.d/50-udev-default.rules.in b/rules.d/50-udev-default.rules.in index cef78f9d68..e1146fa88f 100644 --- a/rules.d/50-udev-default.rules.in +++ b/rules.d/50-udev-default.rules.in @@ -89,4 +89,7 @@ KERNEL=="udmabuf", GROUP="kvm" SUBSYSTEM=="ptp", ATTR{clock_name}=="KVM virtual PTP", SYMLINK += "ptp_kvm" +SUBSYSTEM=="dmi", ENV{ID_SYSFS_ATTRIBUTE_MODEL}=="", ENV{ID_VENDOR}="$attr{sys_vendor}", ENV{ID_MODEL}="$attr{product_name}" +SUBSYSTEM=="dmi", ENV{ID_SYSFS_ATTRIBUTE_MODEL}=="product_version", ENV{ID_VENDOR}="$attr{sys_vendor}", ENV{ID_MODEL}="$attr{product_version}" + LABEL="default_end" From b9d8069832425b34211a6812e06537e0c50d46b6 Mon Sep 17 00:00:00 2001 From: Felipe Borges Date: Fri, 27 Nov 2020 15:49:34 +0100 Subject: [PATCH 3/3] hostnamed: Expose dmi "Vendor" and "Model" fields See #15493 --- src/hostname/hostnamectl.c | 9 +++++++ src/hostname/hostnamed.c | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 0d39e9176f..6532a5ed8c 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -43,6 +43,8 @@ typedef struct StatusInfo { const char *virtualization; const char *architecture; const char *home_url; + const char *hardware_vendor; + const char *hardware_model; } StatusInfo; static void print_status_info(StatusInfo *i) { @@ -107,6 +109,11 @@ static void print_status_info(StatusInfo *i) { if (!isempty(i->architecture)) printf(" Architecture: %s\n", i->architecture); + if (!isempty(i->hardware_vendor)) + printf(" Hardware Vendor: %s\n", i->hardware_vendor); + + if (!isempty(i->hardware_model)) + printf(" Hardware Model: %s\n", i->hardware_model); } static int show_one_name(sd_bus *bus, const char* attr) { @@ -150,6 +157,8 @@ static int show_all_names(sd_bus *bus, sd_bus_error *error) { { "OperatingSystemPrettyName", "s", NULL, offsetof(StatusInfo, os_pretty_name) }, { "OperatingSystemCPEName", "s", NULL, offsetof(StatusInfo, os_cpe_name) }, { "HomeURL", "s", NULL, offsetof(StatusInfo, home_url) }, + { "HardwareVendor", "s", NULL, offsetof(StatusInfo, hardware_vendor) }, + { "HardwareModel", "s", NULL, offsetof(StatusInfo, hardware_model) }, {} }; diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index a1794bdab1..cb885313ea 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -18,6 +18,7 @@ #include "fileio.h" #include "hostname-util.h" #include "id128-util.h" +#include "libudev.h" #include "main-func.h" #include "missing_capability.h" #include "nscd-flush.h" @@ -25,6 +26,7 @@ #include "os-util.h" #include "parse-util.h" #include "path-util.h" +#include "sd-device.h" #include "selinux-util.h" #include "service-util.h" #include "signal-util.h" @@ -47,6 +49,9 @@ enum { PROP_DEPLOYMENT, PROP_LOCATION, + PROP_HARDWARE_VENDOR, + PROP_HARDWARE_MODEL, + /* Read from /etc/os-release (or /usr/lib/os-release) */ PROP_OS_PRETTY_NAME, PROP_OS_CPE_NAME, @@ -423,6 +428,54 @@ static int context_write_data_machine_info(Context *c) { return write_env_file_label("/etc/machine-info", l); } +static int property_get_hardware_vendor( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + _cleanup_(sd_device_unrefp) sd_device *device = NULL; + const char *hardware_vendor = NULL; + int r; + + r = sd_device_new_from_syspath(&device, "/sys/class/dmi/id"); + if (r < 0) { + log_warning_errno(r, "Failed to open /sys/class/dmi/id device, ignoring: %m"); + return sd_bus_message_append(reply, "s", NULL); + } + + if (sd_device_get_property_value(device, "ID_VENDOR_FROM_DATABASE", &hardware_vendor) < 0) + (void) sd_device_get_property_value(device, "ID_VENDOR", &hardware_vendor); + + return sd_bus_message_append(reply, "s", hardware_vendor); +} + +static int property_get_hardware_model( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + _cleanup_(sd_device_unrefp) sd_device *device = NULL; + const char *hardware_model = NULL; + int r; + + r = sd_device_new_from_syspath(&device, "/sys/class/dmi/id"); + if (r < 0) { + log_warning_errno(r, "Failed to open /sys/class/dmi/id device, ignoring: %m"); + return sd_bus_message_append(reply, "s", NULL); + } + + if (sd_device_get_property_value(device, "ID_MODEL_FROM_DATABASE", &hardware_model) < 0) + (void) sd_device_get_property_value(device, "ID_MODEL", &hardware_model); + + return sd_bus_message_append(reply, "s", hardware_model); +} + static int property_get_hostname( sd_bus *bus, const char *path, @@ -860,6 +913,8 @@ static const sd_bus_vtable hostname_vtable[] = { SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("OperatingSystemCPEName", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("HomeURL", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_HOME_URL, SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("HardwareVendor", "s", property_get_hardware_vendor, 0, SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("HardwareModel", "s", property_get_hardware_model, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_METHOD_WITH_NAMES("SetHostname", "sb",