Add dbus server
This commit is contained in:
@@ -3,17 +3,11 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util/u_logging.h"
|
||||
#include "wivrn_config.h"
|
||||
|
||||
#ifdef WIVRN_USE_GLIB
|
||||
#include <gio/gio.h>
|
||||
#elif defined(WIVRN_USE_SYSTEMD)
|
||||
#include <systemd/sd-bus.h>
|
||||
#endif
|
||||
|
||||
static std::string _hostname()
|
||||
{
|
||||
#ifdef WIVRN_USE_GLIB
|
||||
GError * error = NULL;
|
||||
GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
|
||||
@@ -59,38 +53,6 @@ static std::string _hostname()
|
||||
|
||||
g_object_unref(con);
|
||||
}
|
||||
#elif defined(WIVRN_USE_SYSTEMD)
|
||||
sd_bus * bus;
|
||||
if (sd_bus_default_system(&bus) < 0)
|
||||
{
|
||||
U_LOG_W("Failed to connect to system bus");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto property: {"PrettyHostname", "StaticHostname", "Hostname"})
|
||||
{
|
||||
char * hostname = nullptr;
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
if (sd_bus_get_property_string(bus, "org.freedesktop.hostname1", "/org/freedesktop/hostname1", "org.freedesktop.hostname1", property, &error, &hostname) < 0)
|
||||
{
|
||||
sd_bus_error_free(&error);
|
||||
continue;
|
||||
}
|
||||
|
||||
sd_bus_error_free(&error);
|
||||
if (hostname && strcmp(hostname, ""))
|
||||
{
|
||||
std::string s = hostname;
|
||||
free(hostname);
|
||||
sd_bus_unref(bus);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
sd_bus_unref(bus);
|
||||
}
|
||||
#endif
|
||||
|
||||
char buf[HOST_NAME_MAX];
|
||||
int code = gethostname(buf, sizeof(buf));
|
||||
|
||||
Reference in New Issue
Block a user