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
);
21 /*g_dbus_connection_register_object(conn,
22 "/org/freedesktop/hostname1",
23 spect_data->interfaces[0],
28 static void on_name_acquired(GDBusConnection
*conn
,
32 g_print("got name %s\n", name
);
35 static void on_name_lost(GDBusConnection
*conn
,
39 g_print("lost name %s, exiting...", name
);
41 hostnamed_mem_clean();
43 //TODO exit through g_main_loop properly...
46 /* safe call to try and start hostnamed */
47 GError
* hostnamed_init() {
51 gchar
**hostnamed_ispect_xml
;
52 gchar
*hostnamed_joined_xml
;
54 hostnamed_freeable
= g_ptr_array_new();
56 g_file_get_contents("conf/hostnamed-ispect.xml", hostnamed_ispect_xml
, GUINT_TO_POINTER(3000), &err
);
57 hostnamed_joined_xml
= g_strjoinv("\n", hostnamed_ispect_xml
);
58 spect_data
= g_dbus_node_info_new_for_xml(hostnamed_joined_xml
, NULL
);
60 g_free(hostnamed_ispect_xml
);
61 g_ptr_array_add(hostnamed_freeable
, hostnamed_joined_xml
);
63 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SYSTEM
,
64 "org.freedesktop.hostname1",
65 G_BUS_NAME_OWNER_FLAGS_NONE
,
72 //TODO: malloc and return reference as if a main() closed
76 //POSIX, for future ports try_hostname should be checked for null-termination
78 gboolean init_hostname() {
80 gchar try_hostname[HOST_NAME_MAX];
82 if(!gethostname(try_hostname, HOST_NAME_MAX)) {
83 hostname = try_hostname;
91 void hostnamed_mem_clean() {
93 g_ptr_array_foreach(hostnamed_freeable
, (GFunc
) g_free
, NULL
);
96 //TODO figure out DMI variables on obsd
97 /*static gchar *guess_icon_name() {
99 gchar *filebuf = NULL;
104 #if defined(__i386__) || defined(__x86_64__)
106 Taken with a few minor changes from systemd's hostnamed.c,
107 copyright 2011 Lennart Poettering.
109 See the SMBIOS Specification 2.7.1 section 7.4.1 for
110 details about the values listed here:
112 http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
115 if (g_file_get_contents ("/sys/class/dmi/id/chassis_type", &filebuf, NULL, NULL)) {
116 switch (g_ascii_strtoull (filebuf, NULL, 10)) {
122 ret = g_strdup ("computer-desktop");
127 ret = g_strdup ("computer-laptop");
133 ret = g_strdup ("computer-server");
138 ret = g_strdup ("computer");