594167
From ea54689eebe58d1bbb908762731f179e50ac1c9a Mon Sep 17 00:00:00 2001
594167
From: Bastien Nocera <hadess@hadess.net>
594167
Date: Fri, 21 Jan 2022 18:56:42 +0100
594167
Subject: [PATCH] hostname: Allow overriding the chassis type from hwdb
594167
594167
Closes: #7390
594167
(cherry picked from commit 4b35eb2579b226785f0d94129a7652450f9723fd)
594167
594167
Related: #2087778
594167
---
594167
 src/hostname/hostnamed.c | 12 +++++++-----
594167
 1 file changed, 7 insertions(+), 5 deletions(-)
594167
594167
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
594167
index b20a93ad81..559326b9f5 100644
594167
--- a/src/hostname/hostnamed.c
594167
+++ b/src/hostname/hostnamed.c
594167
@@ -725,16 +725,18 @@ static int property_get_chassis(
594167
                 sd_bus_error *error) {
594167
 
594167
         Context *c = userdata;
594167
-        const char *name;
594167
+        _cleanup_free_ char *dmi_chassis = NULL;
594167
+        const char *name = NULL;
594167
 
594167
         context_read_machine_info(c);
594167
 
594167
-        if (isempty(c->data[PROP_CHASSIS]))
594167
-                name = fallback_chassis();
594167
-        else
594167
+        if (isempty(c->data[PROP_CHASSIS])) {
594167
+                if (get_dmi_data("ID_CHASSIS", NULL, &dmi_chassis) <= 0)
594167
+                        name = fallback_chassis();
594167
+        } else
594167
                 name = c->data[PROP_CHASSIS];
594167
 
594167
-        return sd_bus_message_append(reply, "s", name);
594167
+        return sd_bus_message_append(reply, "s", name ?: dmi_chassis);
594167
 }
594167
 
594167
 static int property_get_uname_field(