src/remote/remote_daemon: convert to use GLib DBus

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Pavel Hrdina 2020-09-09 16:44:03 +02:00
parent f0505401c4
commit 5b9ad2a377

View File

@ -63,7 +63,7 @@
#include "configmake.h" #include "configmake.h"
#include "virdbus.h" #include "virgdbus.h"
VIR_LOG_INIT("daemon." DAEMON_NAME); VIR_LOG_INIT("daemon." DAEMON_NAME);
@ -508,9 +508,8 @@ static void daemonInhibitCallback(bool inhibit, void *opaque)
} }
#ifdef WITH_DBUS static GDBusConnection *sessionBus;
static DBusConnection *sessionBus; static GDBusConnection *systemBus;
static DBusConnection *systemBus;
static void daemonStopWorker(void *opaque) static void daemonStopWorker(void *opaque)
{ {
@ -538,41 +537,40 @@ static void daemonStop(virNetDaemonPtr dmn)
} }
static DBusHandlerResult static GDBusMessage *
handleSessionMessageFunc(DBusConnection *connection G_GNUC_UNUSED, handleSessionMessageFunc(GDBusConnection *connection G_GNUC_UNUSED,
DBusMessage *message, GDBusMessage *message,
void *opaque) gboolean incoming G_GNUC_UNUSED,
gpointer opaque)
{ {
virNetDaemonPtr dmn = opaque; virNetDaemonPtr dmn = opaque;
VIR_DEBUG("dmn=%p", dmn); VIR_DEBUG("dmn=%p", dmn);
if (dbus_message_is_signal(message, if (virGDBusMessageIsSignal(message,
DBUS_INTERFACE_LOCAL, "org.freedesktop.DBus.Local",
"Disconnected")) "Disconnected"))
daemonStop(dmn); daemonStop(dmn);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; return message;
} }
static DBusHandlerResult static void
handleSystemMessageFunc(DBusConnection *connection G_GNUC_UNUSED, handleSystemMessageFunc(GDBusConnection *connection G_GNUC_UNUSED,
DBusMessage *message, const char *senderName G_GNUC_UNUSED,
void *opaque) const char *objectPath G_GNUC_UNUSED,
const char *interfaceName G_GNUC_UNUSED,
const char *signalName G_GNUC_UNUSED,
GVariant *parameters G_GNUC_UNUSED,
gpointer opaque)
{ {
virNetDaemonPtr dmn = opaque; virNetDaemonPtr dmn = opaque;
VIR_DEBUG("dmn=%p", dmn); VIR_DEBUG("dmn=%p", dmn);
if (dbus_message_is_signal(message,
"org.freedesktop.login1.Manager",
"PrepareForShutdown"))
daemonStop(dmn); daemonStop(dmn);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} }
#endif
static void daemonRunStateInit(void *opaque) static void daemonRunStateInit(void *opaque)
@ -608,25 +606,28 @@ static void daemonRunStateInit(void *opaque)
driversInitialized = true; driversInitialized = true;
#ifdef WITH_DBUS
/* Tie the non-privileged daemons to the session/shutdown lifecycle */ /* Tie the non-privileged daemons to the session/shutdown lifecycle */
if (!virNetDaemonIsPrivileged(dmn)) { if (!virNetDaemonIsPrivileged(dmn)) {
sessionBus = virDBusGetSessionBus(); sessionBus = virGDBusGetSessionBus();
if (sessionBus != NULL) if (sessionBus != NULL)
dbus_connection_add_filter(sessionBus, g_dbus_connection_add_filter(sessionBus,
handleSessionMessageFunc, dmn, NULL); handleSessionMessageFunc, dmn, NULL);
systemBus = virDBusGetSystemBus(); systemBus = virGDBusGetSystemBus();
if (systemBus != NULL) { if (systemBus != NULL)
dbus_connection_add_filter(systemBus, g_dbus_connection_signal_subscribe(systemBus,
handleSystemMessageFunc, dmn, NULL); "org.freedesktop.login1",
dbus_bus_add_match(systemBus, "org.freedesktop.login1.Manager",
"type='signal',sender='org.freedesktop.login1', interface='org.freedesktop.login1.Manager'", "PrepareForShutdown",
NULL,
NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
handleSystemMessageFunc,
dmn,
NULL); NULL);
} }
}
#endif
/* Only now accept clients from network */ /* Only now accept clients from network */
virNetDaemonUpdateServices(dmn, true); virNetDaemonUpdateServices(dmn, true);
cleanup: cleanup: