Decouple pk-backend from HAVE_SYSTEMD_SD_LOGIN_H
This enables the inhibiting feature with ConsoleKit too. ConsoleKit and logind and have identical interfaces in this regard.
This commit is contained in:
parent
e91426a53c
commit
f42d198f43
@ -98,10 +98,9 @@ struct PkEnginePrivate
|
||||
guint owner_id;
|
||||
GDBusNodeInfo *introspection;
|
||||
GDBusConnection *connection;
|
||||
#ifdef HAVE_SYSTEMD_SD_LOGIN_H
|
||||
GDBusProxy *logind_proxy;
|
||||
gint logind_fd;
|
||||
#endif
|
||||
gboolean logind_tried;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -256,7 +255,6 @@ pk_engine_emit_offline_property_changed (PkEngine *engine,
|
||||
static void
|
||||
pk_engine_inhibit (PkEngine *engine)
|
||||
{
|
||||
#ifdef HAVE_SYSTEMD_SD_LOGIN_H
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GUnixFDList) out_fd_list = NULL;
|
||||
g_autoptr(GVariant) res = NULL;
|
||||
@ -297,19 +295,16 @@ pk_engine_inhibit (PkEngine *engine)
|
||||
}
|
||||
engine->priv->logind_fd = g_unix_fd_list_get (out_fd_list, 0, NULL);
|
||||
g_debug ("opened logind fd %i", engine->priv->logind_fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
pk_engine_uninhibit (PkEngine *engine)
|
||||
{
|
||||
#ifdef HAVE_SYSTEMD_SD_LOGIN_H
|
||||
if (engine->priv->logind_fd == 0)
|
||||
return;
|
||||
g_debug ("closed logind fd %i", engine->priv->logind_fd);
|
||||
close (engine->priv->logind_fd);
|
||||
engine->priv->logind_fd = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1741,7 +1736,6 @@ pk_engine_offline_method_call (GDBusConnection *connection_, const gchar *sender
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYSTEMD_SD_LOGIN_H
|
||||
static void
|
||||
pk_engine_proxy_logind_cb (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
@ -1749,12 +1743,28 @@ pk_engine_proxy_logind_cb (GObject *source_object,
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
PkEngine *engine = PK_ENGINE (user_data);
|
||||
GDBusConnection* connection;
|
||||
|
||||
engine->priv->logind_proxy = g_dbus_proxy_new_finish (res, &error);
|
||||
if (g_dbus_proxy_get_name_owner (engine->priv->logind_proxy) == NULL) // https://gitlab.gnome.org/GNOME/glib/-/issues/879
|
||||
g_warning ("failed to connect to logind: %s", error->message);
|
||||
// https://gitlab.gnome.org/GNOME/glib/-/issues/879
|
||||
if (g_dbus_proxy_get_name_owner (engine->priv->logind_proxy) == NULL) {
|
||||
g_warning ("failed to connect to logind: %s", error ? error->message : "no such service");
|
||||
if (!engine->priv->logind_tried) {
|
||||
engine->priv->logind_tried = TRUE;
|
||||
connection = g_dbus_proxy_get_connection (engine->priv->logind_proxy);
|
||||
g_clear_object (&engine->priv->logind_proxy);
|
||||
g_dbus_proxy_new (connection,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
|
||||
NULL,
|
||||
"org.freedesktop.ConsoleKit",
|
||||
"/org/freedesktop/ConsoleKit",
|
||||
"org.freedesktop.ConsoleKit.Manager",
|
||||
NULL, /* GCancellable */
|
||||
pk_engine_proxy_logind_cb,
|
||||
engine);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
pk_engine_on_bus_acquired_cb (GDBusConnection *connection,
|
||||
@ -1777,7 +1787,6 @@ pk_engine_on_bus_acquired_cb (GDBusConnection *connection,
|
||||
/* save copy for emitting signals */
|
||||
engine->priv->connection = g_object_ref (connection);
|
||||
|
||||
#ifdef HAVE_SYSTEMD_SD_LOGIN_H
|
||||
/* connect to logind */
|
||||
g_dbus_proxy_new (connection,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
|
||||
@ -1788,7 +1797,6 @@ pk_engine_on_bus_acquired_cb (GDBusConnection *connection,
|
||||
NULL, /* GCancellable */
|
||||
pk_engine_proxy_logind_cb,
|
||||
engine);
|
||||
#endif
|
||||
|
||||
/* register org.freedesktop.PackageKit */
|
||||
registration_id = g_dbus_connection_register_object (connection,
|
||||
@ -1923,13 +1931,11 @@ pk_engine_finalize (GObject *object)
|
||||
if (engine->priv->connection != NULL)
|
||||
g_object_unref (engine->priv->connection);
|
||||
|
||||
#ifdef HAVE_SYSTEMD_SD_LOGIN_H
|
||||
/* uninhibit */
|
||||
if (engine->priv->logind_fd != 0)
|
||||
close (engine->priv->logind_fd);
|
||||
if (engine->priv->logind_proxy != NULL)
|
||||
g_object_unref (engine->priv->logind_proxy);
|
||||
#endif
|
||||
|
||||
/* compulsory gobjects */
|
||||
g_timer_destroy (engine->priv->timer);
|
||||
|
Loading…
Reference in New Issue
Block a user