Skip to content
Snippets Groups Projects
Commit 12495b52 authored by David Heidelberg's avatar David Heidelberg Committed by Luca Weiss
Browse files

hostnamed: add ACPI and Device Tree chassis detection mechanisms


Heavily "inspired" by systemd.

Signed-off-by: default avatarDavid Heidelberg <david@ixit.cz>
parent 065dcb30
Branches main
No related tags found
No related merge requests found
......@@ -81,6 +81,9 @@ hostname_is_valid (const gchar *name)
name, G_REGEX_MULTILINE, 0);
}
/*
Taken with a few minor changes from systemd's hostnamed.c,
*/
static gchar *
guess_chassis ()
{
......@@ -97,9 +100,6 @@ guess_chassis ()
#if defined(__i386__) || defined(__x86_64__)
/*
Taken with a few minor changes from systemd's hostnamed.c,
copyright 2011 Lennart Poettering.
See the SMBIOS Specification 3.5.0 section 7.4.1 for details about the values listed here:
https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.5.0.pdf
......@@ -144,6 +144,48 @@ guess_chassis ()
}
}
#endif
/* We only list the really obvious cases here as the ACPI data is not really super reliable.
*
* See the ACPI 5.0 Spec Section 5.2.9.1 for details:
*
* http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
*/
if (g_file_get_contents ("/sys/firmware/acpi/pm_profile", &filebuf, NULL, NULL)) {
switch (g_ascii_strtoull (filebuf, NULL, 10)) {
case 1: /* Desktop */
case 3: /* Workstation */
case 6: /* Appliance PC */
ret = g_strdup ("desktop");
goto out;
case 2: /* Mobile */
ret = g_strdup ("laptop");
goto out;
case 4: /* Enterprise Server */
case 5: /* SOHO Server */
case 7: /* Performance Server */
ret = g_strdup ("server");
goto out;
case 8: /* Tablet */
ret = g_strdup ("tablet");
goto out;
}
}
/* Query Device Tree for chassis type
*
* Note that the Devicetree specification uses the very same vocabulary
* of chassis types as we do, hence we do not need to translate these types:
*
* https://github.com/devicetree-org/devicetree-specification/blob/master/source/chapter3-devicenodes.rst */
if (g_file_get_contents ("/proc/device-tree/chassis-type", &filebuf, NULL, NULL)) {
ret = g_strdup (filebuf);
goto out;
}
out:
g_free (filebuf);
return ret;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment