2 * Copyright (c) 2014 Ian Sutton <ian@kremlin.cc>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #include "hostnamed.h"
24 #include "hostnamed-gen.c"
26 GPtrArray
*hostnamed_freeable
;
27 GDBusNodeInfo
*spect_data
;
29 static void on_bus_acquired(GDBusConnection
*conn
,
35 g_print("got bus, name: %s\n", name
);
39 static void on_name_acquired(GDBusConnection
*conn
,
43 g_print("got name %s\n", name
);
46 static void on_name_lost(GDBusConnection
*conn
,
50 g_print("lost name %s, exiting...", name
);
52 hostnamed_mem_clean();
54 //TODO exit through g_main_loop properly...
57 /* safe call to try and start hostnamed */
58 GError
*hostnamed_init() {
62 gchar
**hostnamed_ispect_xml
;
63 gchar
*hostnamed_joined_xml
;
65 hostnamed_freeable
= g_ptr_array_new();
66 hostnamed_ispect_xml
= g_malloc(3000);
68 g_file_get_contents("conf/hostnamed-ispect.xml", hostnamed_ispect_xml
, NULL
, NULL
);
69 hostnamed_joined_xml
= g_strjoinv("\n", hostnamed_ispect_xml
);
70 spect_data
= g_dbus_node_info_new_for_xml(hostnamed_joined_xml
, NULL
);
72 g_free(hostnamed_ispect_xml
);
73 g_ptr_array_add(hostnamed_freeable
, hostnamed_joined_xml
);
75 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SYSTEM
,
76 "org.freedesktop.hostname1",
77 G_BUS_NAME_OWNER_FLAGS_NONE
,
84 //TODO: malloc and return reference as if a main() closed
89 void hostnamed_mem_clean() {
91 g_ptr_array_foreach(hostnamed_freeable
, (GFunc
) g_free
, NULL
);
94 //TODO figure out DMI variables on obsd
95 /*static gchar *guess_icon_name() {
97 gchar *filebuf = NULL;
102 #if defined(__i386__) || defined(__x86_64__)
104 Taken with a few minor changes from systemd's hostnamed.c,
105 copyright 2011 Lennart Poettering.
107 See the SMBIOS Specification 2.7.1 section 7.4.1 for
108 details about the values listed here:
110 http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
113 if (g_file_get_contents ("/sys/class/dmi/id/chassis_type", &filebuf, NULL, NULL)) {
114 switch (g_ascii_strtoull (filebuf, NULL, 10)) {
120 ret = g_strdup ("computer-desktop");
125 ret = g_strdup ("computer-laptop");
131 ret = g_strdup ("computer-server");
136 ret = g_strdup ("computer");