#include <signal.h>
#include <sys/param.h>
+#include <sys/sysctl.h>
#include <string.h>
#include <glib/gprintf.h>
#include <glib-unix.h>
+/* #include <gtk/gtk.h> */
#include "hostnamed-gen.h"
#include "hostnamed.h"
+/* add any sysctl strings that suggest virtualization here */
+/* format: {
+ * (1) string to be matched against runtime machine's sysctl output.
+ * can be either the exact string or a substring contained
+ * within sysctl strings. no "guesses" here, a match should
+ * reliably indicate the chassis/icon.
+ *
+ * (2) string describing chassis type divulged by (1).
+ * must be one of "desktop", "laptop", "server",
+ * "tablet", "handset", "vm", "container" or NULL
+ * if only icon string can be ascertained. "vm" refers
+ * to operating systems running on baremetal hypervisors
+ * (hardware virtualization, like XEN) while "container"
+ * refers to OSs running on shared hypervisors like
+ * virtualbox or VMware. consider the distinction carefully
+ * as common virtualization software like KVM may share
+ * characteristics of both "vm" and "container" types.
+ *
+ * (3) string specifying icon to use. follows XDG icon spec.
+ * see http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
+ * for allowed strings.
+ *
+ * (4) chassis precedence bit. TRUE if (2) is defined and
+ * we're certain it is the proper string. FALSE in the
+ * circumstance (2) may be the correct string, unless
+ * a match with this bit set to TRUE overrides it.
+ * if (2) is NULL, this bit is inconsequential.
+ *
+ * (5) icon precedence bit. see previous definition.
+ * } */
+struct SYSCTL_LOOKUP_TABLE {
+ gchar *match_string;
+ gchar *chassis;
+ gchar *icon;
+ gboolean chassis_precedence;
+ gboolean icon_precedence;
+};
+
GPtrArray *hostnamed_freeable;
Hostname1 *hostnamed_interf;
guint bus_descriptor;
gboolean dbus_interface_exported; /* reliable because of gdbus operational guarantees */
+gchar *CHASSIS, *ICON;
+
+/* TODO no specific vm or laptop icon in gnome
+ * NOTE paravirtualization on xen is only available for linuxes right now
+ * dmesg on linux systems reveals xen and virtualization method (HVM or PVM)
+ * but we will worry about those later */
+const struct SYSCTL_LOOKUP_TABLE chassis_indicator_table[] =
+{
+ { "QEMU Virtual CPU", "container", "drive-optical", FALSE, FALSE }, /* could be QEMU running in userspace or as part of KVM */
+ { "SmartDC HVM", "vm", "drive-multidisk", TRUE, TRUE }, /* oracle solaris kvm */
+ { "VirtualBox", "container", "drive-optical", TRUE, TRUE },
+ { "VMware, Inc.", "container", "drive-optical", TRUE, TRUE },
+ { "VMware Virtual Platform", "container", "drive-optical", TRUE, TRUE },
+ { "Parallels", "container", "drive-optical", TRUE, TRUE } /* need verification */
+};
+
+/*const gchar* vmstring_list[] = {
+ "QEMU Virtual CPU",
+ "SmartDC HVM",
+ "KVM",
+ "VirtualBox"
+};*/
+
/* --- begin method/property/dbus signal code --- */
static gboolean
const gchar *
our_get_static_hostname() {
- gchar *pretty_hostname;
- gchar *ret;
+ const gchar *pretty_hostname;
+ const gchar *ret;
pretty_hostname = our_get_pretty_hostname();
if(g_strcmp0(pretty_hostname, "") == 0)
ret = our_get_hostname();
- else if(ret = g_hostname_to_ascii(pretty_hostname)) {
+ else if((ret = g_hostname_to_ascii(pretty_hostname))) {
- g_ptr_array_add(hostnamed_freeable, ret);
+ g_ptr_array_add(hostnamed_freeable, (gpointer)ret);
return ret;
}
GKeyFile *config;
gchar *ret;
+ config = g_key_file_new();
+
if(g_key_file_load_from_file(config, "/etc/systemd_compat.conf", G_KEY_FILE_NONE, NULL)
- && ret = g_key_file_get_value(config, "hostnamed", "PrettyHostname", NULL)) { /* ret might need to be freed, docs dont specify but i am suspicious */
+ && (ret = g_key_file_get_value(config, "hostnamed", "PrettyHostname", NULL))) { /* ret might need to be freed, docs dont specify but i am suspicious */
- g_free(config);
+ g_key_file_unref(config);
return ret;
}
const gchar *
our_get_chassis() {
- return "TODO";
+ return "asdf";
+
}
const gchar *
set_signal_handlers();
- hostnamed_loop = g_main_loop_new(NULL, TRUE);
+ if(!build_chassis_table() || !determine_chassis_and_icon())
+ return 1;
+
+ hostnamed_loop = g_main_loop_new(NULL, TRUE);
hostnamed_freeable = g_ptr_array_new();
bus_descriptor = g_bus_own_name(G_BUS_TYPE_SYSTEM,
return 0;
}
+static gboolean build_chassis_table() {
+ return TRUE;
+}
+
+gboolean determine_chassis_and_icon() {
+
+ char *hwproduct, *hwmodel, *hwvendor;
+ size_t hwproduct_size, hwmodel_size, hwvendor_size;
+ int hwproduct_name[2], hwmodel_name[2], hwvendor_name[2];
+ unsigned int i;
+
+ hwproduct_name[0] = CTL_HW;
+ hwproduct_name[1] = HW_PRODUCT;
+
+ hwmodel_name[0] = CTL_HW;
+ hwmodel_name[1] = HW_MODEL;
+
+ hwvendor_name[0] = CTL_HW;
+ hwvendor_name[1] = HW_VENDOR;
+
+ /* pass NULL buffer to check size first, then pass hw to be filled according to freshly-set hw_size */
+ if(-1 == sysctl(hwproduct_name, 2, NULL, &hwproduct_size, NULL, 0) || -1 == sysctl(hwproduct_name, 2, hwproduct, &hwproduct_size, NULL, 0))
+ return FALSE;
+
+ if(-1 == sysctl(hwmodel_name, 2, NULL, &hwmodel_size, NULL, 0) || -1 == sysctl(hwmodel_name, 2, hwmodel, &hwmodel_size, NULL, 0))
+ return FALSE;
+
+ if(-1 == sysctl(hwvendor_name, 2, NULL, &hwvendor_size, NULL, 0) || -1 == sysctl(hwvendor_name, 2, hwvendor, &hwvendor_size, NULL, 0))
+ return FALSE;
+
+ /* TODO: test for laptop, if not, dmidecode for desktop vs. server
+ * probably move this code to vm test func and set a global after running it early, once */
+
+ for(; i < G_N_ELEMENTS(chassis_indicator_table); i++)
+
+ /* if(strcasestr(sysctl_string, vmstring_list[i]))
+ return (CHASSIS = ) ? TRUE : FALSE; */
+
+ return FALSE;
+
+ return TRUE; /* temp */
+}
+
/* TODO figure out DMI variables on obsd */
/*static gchar *guess_icon_name() {