summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hwdb.d/20-dmi-id.hwdb6
-rw-r--r--hwdb.d/meson.build1
-rw-r--r--rules.d/50-udev-default.rules.in3
-rw-r--r--src/hostname/hostnamectl.c9
-rw-r--r--src/hostname/hostnamed.c55
5 files changed, 74 insertions, 0 deletions
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
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"
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index de6eb9ea2f..c2338a69f6 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 f0bf29028f..a2a09c28ed 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -20,6 +20,7 @@
#include "hostname-setup.h"
#include "hostname-util.h"
#include "id128-util.h"
+#include "libudev.h"
#include "main-func.h"
#include "missing_capability.h"
#include "nscd-flush.h"
@@ -27,6 +28,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"
@@ -50,6 +52,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,
@@ -426,6 +431,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,
@@ -903,6 +956,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",