|
20 | 20 | #include "hostname-setup.h" |
21 | 21 | #include "hostname-util.h" |
22 | 22 | #include "id128-util.h" |
| 23 | +#include "libudev.h" |
23 | 24 | #include "main-func.h" |
24 | 25 | #include "missing_capability.h" |
25 | 26 | #include "nscd-flush.h" |
26 | 27 | #include "nulstr-util.h" |
27 | 28 | #include "os-util.h" |
28 | 29 | #include "parse-util.h" |
29 | 30 | #include "path-util.h" |
| 31 | +#include "sd-device.h" |
30 | 32 | #include "selinux-util.h" |
31 | 33 | #include "service-util.h" |
32 | 34 | #include "signal-util.h" |
|
50 | 52 | PROP_DEPLOYMENT, |
51 | 53 | PROP_LOCATION, |
52 | 54 |
|
| 55 | + PROP_HARDWARE_VENDOR, |
| 56 | + PROP_HARDWARE_MODEL, |
| 57 | + |
53 | 58 | /* Read from /etc/os-release (or /usr/lib/os-release) */ |
54 | 59 | PROP_OS_PRETTY_NAME, |
55 | 60 | PROP_OS_CPE_NAME, |
@@ -426,6 +431,54 @@ static int context_write_data_machine_info(Context *c) { |
426 | 431 | return write_env_file_label("/etc/machine-info", l); |
427 | 432 | } |
428 | 433 |
|
| 434 | +static int property_get_hardware_vendor( |
| 435 | + sd_bus *bus, |
| 436 | + const char *path, |
| 437 | + const char *interface, |
| 438 | + const char *property, |
| 439 | + sd_bus_message *reply, |
| 440 | + void *userdata, |
| 441 | + sd_bus_error *error) { |
| 442 | + _cleanup_(sd_device_unrefp) sd_device *device = NULL; |
| 443 | + const char *hardware_vendor = NULL; |
| 444 | + int r; |
| 445 | + |
| 446 | + r = sd_device_new_from_syspath(&device, "/sys/class/dmi/id"); |
| 447 | + if (r < 0) { |
| 448 | + log_warning_errno(r, "Failed to open /sys/class/dmi/id device, ignoring: %m"); |
| 449 | + return sd_bus_message_append(reply, "s", NULL); |
| 450 | + } |
| 451 | + |
| 452 | + if (sd_device_get_property_value(device, "ID_VENDOR_FROM_DATABASE", &hardware_vendor) < 0) |
| 453 | + (void) sd_device_get_property_value(device, "ID_VENDOR", &hardware_vendor); |
| 454 | + |
| 455 | + return sd_bus_message_append(reply, "s", hardware_vendor); |
| 456 | +} |
| 457 | + |
| 458 | +static int property_get_hardware_model( |
| 459 | + sd_bus *bus, |
| 460 | + const char *path, |
| 461 | + const char *interface, |
| 462 | + const char *property, |
| 463 | + sd_bus_message *reply, |
| 464 | + void *userdata, |
| 465 | + sd_bus_error *error) { |
| 466 | + _cleanup_(sd_device_unrefp) sd_device *device = NULL; |
| 467 | + const char *hardware_model = NULL; |
| 468 | + int r; |
| 469 | + |
| 470 | + r = sd_device_new_from_syspath(&device, "/sys/class/dmi/id"); |
| 471 | + if (r < 0) { |
| 472 | + log_warning_errno(r, "Failed to open /sys/class/dmi/id device, ignoring: %m"); |
| 473 | + return sd_bus_message_append(reply, "s", NULL); |
| 474 | + } |
| 475 | + |
| 476 | + if (sd_device_get_property_value(device, "ID_MODEL_FROM_DATABASE", &hardware_model) < 0) |
| 477 | + (void) sd_device_get_property_value(device, "ID_MODEL", &hardware_model); |
| 478 | + |
| 479 | + return sd_bus_message_append(reply, "s", hardware_model); |
| 480 | +} |
| 481 | + |
429 | 482 | static int property_get_hostname( |
430 | 483 | sd_bus *bus, |
431 | 484 | const char *path, |
@@ -903,6 +956,8 @@ static const sd_bus_vtable hostname_vtable[] = { |
903 | 956 | SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_CONST), |
904 | 957 | SD_BUS_PROPERTY("OperatingSystemCPEName", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST), |
905 | 958 | SD_BUS_PROPERTY("HomeURL", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_HOME_URL, SD_BUS_VTABLE_PROPERTY_CONST), |
| 959 | + SD_BUS_PROPERTY("HardwareVendor", "s", property_get_hardware_vendor, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
| 960 | + SD_BUS_PROPERTY("HardwareModel", "s", property_get_hardware_model, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
906 | 961 |
|
907 | 962 | SD_BUS_METHOD_WITH_NAMES("SetHostname", |
908 | 963 | "sb", |
|
0 commit comments