summaryrefslogtreecommitdiffstats
path: root/src/hostname
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostname')
-rw-r--r--src/hostname/hostnamectl.c9
-rw-r--r--src/hostname/hostnamed.c55
2 files changed, 64 insertions, 0 deletions
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",