8 #include "hostnamed-gen.c"
10 GPtrArray
*hostnamed_freeable
;
11 GDBusNodeInfo
*spect_data
;
13 static void on_bus_acquired(GDBusConnection
*conn
,
19 g_print("got bus, name: %s\n", name
);
23 static void on_name_acquired(GDBusConnection
*conn
,
27 g_print("got name %s\n", name
);
30 static void on_name_lost(GDBusConnection
*conn
,
34 g_print("lost name %s, exiting...", name
);
36 hostnamed_mem_clean();
38 //TODO exit through g_main_loop properly...
41 /* safe call to try and start hostnamed */
42 GError
*hostnamed_init() {
46 gchar
**hostnamed_ispect_xml
;
47 gchar
*hostnamed_joined_xml
;
49 hostnamed_freeable
= g_ptr_array_new();
50 hostnamed_ispect_xml
= g_malloc(3000);
52 g_file_get_contents("conf/hostnamed-ispect.xml", hostnamed_ispect_xml
, NULL
, NULL
);
53 hostnamed_joined_xml
= g_strjoinv("\n", hostnamed_ispect_xml
);
54 spect_data
= g_dbus_node_info_new_for_xml(hostnamed_joined_xml
, NULL
);
56 g_free(hostnamed_ispect_xml
);
57 g_ptr_array_add(hostnamed_freeable
, hostnamed_joined_xml
);
59 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SYSTEM
,
60 "org.freedesktop.hostname1",
61 G_BUS_NAME_OWNER_FLAGS_NONE
,
68 //TODO: malloc and return reference as if a main() closed
73 void hostnamed_mem_clean() {
75 g_ptr_array_foreach(hostnamed_freeable
, (GFunc
) g_free
, NULL
);
78 //TODO figure out DMI variables on obsd
79 /*static gchar *guess_icon_name() {
81 gchar *filebuf = NULL;
86 #if defined(__i386__) || defined(__x86_64__)
88 Taken with a few minor changes from systemd's hostnamed.c,
89 copyright 2011 Lennart Poettering.
91 See the SMBIOS Specification 2.7.1 section 7.4.1 for
92 details about the values listed here:
94 http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
97 if (g_file_get_contents ("/sys/class/dmi/id/chassis_type", &filebuf, NULL, NULL)) {
98 switch (g_ascii_strtoull (filebuf, NULL, 10)) {
104 ret = g_strdup ("computer-desktop");
109 ret = g_strdup ("computer-laptop");
115 ret = g_strdup ("computer-server");
120 ret = g_strdup ("computer");