Skip to content
Snippets Groups Projects
Unverified Commit 1a6e7e0e authored by Luca Weiss's avatar Luca Weiss
Browse files

hostnamed: guess chassis property

Convert the existing guess_icon_name method to guess the chassis value
and build the icon name based on that.
parent 13f8d940
Branches main
No related tags found
No related merge requests found
......@@ -77,7 +77,7 @@ hostname_is_valid (const gchar *name)
}
static gchar *
guess_icon_name ()
guess_chassis ()
{
gchar *filebuf = NULL;
gchar *ret = NULL;
......@@ -85,7 +85,7 @@ guess_icon_name ()
#if HAVE_OPENRC
/* Note that rc_sys() leaks memory :( */
if (rc_sys() != NULL) {
ret = g_strdup ("computer-vm");
ret = g_strdup ("vm");
goto out;
}
#endif
......@@ -109,39 +109,60 @@ guess_icon_name ()
case 0x6: /* Mini Tower */
case 0x7: /* Tower */
case 0xD: /* All in One */
ret = g_strdup ("computer-desktop");
ret = g_strdup ("desktop");
goto out;
case 0x8: /* Portable */
case 0x9: /* Laptop */
case 0xA: /* Notebook */
case 0xE: /* Sub Notebook */
ret = g_strdup ("computer-laptop");
ret = g_strdup ("laptop");
goto out;
case 0xB: /* Hand Held */
ret = g_strdup ("computer-handset");
ret = g_strdup ("handset");
goto out;
case 0x11: /* Main Server Chassis */
case 0x17: /* Rack Mount Chassis */
case 0x1C: /* Blade */
case 0x1D: /* Blade Enclosure */
ret = g_strdup ("computer-server");
ret = g_strdup ("server");
goto out;
case 0x1E: /* Tablet */
ret = g_strdup ("computer-tablet");
ret = g_strdup ("tablet");
goto out;
case 0x1F: /* Convertible */
case 0x20: /* Detachable */
ret = g_strdup ("computer-convertible");
ret = g_strdup ("convertible");
goto out;
}
}
#endif
ret = g_strdup ("computer");
out:
g_free (filebuf);
return ret;
}
static gchar *
guess_icon_name ()
{
gchar *guessed_chassis;
gchar *ret;
/* Take configured chassis if not empty string */
if (chassis && *chassis)
return g_strconcat ("computer-", chassis, NULL);
guessed_chassis = guess_chassis();
if (guessed_chassis) {
ret = g_strconcat ("computer-", guessed_chassis, NULL);
goto out;
}
ret = g_strdup ("computer");
out:
g_free (guessed_chassis);
return ret;
}
static void
on_handle_set_hostname_authorized_cb (GObject *source_object,
GAsyncResult *res,
......@@ -680,6 +701,10 @@ hostnamed_init (gboolean _read_only)
g_error_free (err);
err = NULL;
}
if (chassis == NULL || *chassis == 0) {
g_free (chassis);
chassis = guess_chassis ();
}
deployment = shell_source_var (machine_info_file, "${DEPLOYMENT}", &err);
if (deployment == NULL)
......
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