|
|
baf615 |
From c2b6a64834df38b493d946fab55667cebdb991b6 Mon Sep 17 00:00:00 2001
|
|
|
baf615 |
From: Ray Strode <rstrode@redhat.com>
|
|
|
baf615 |
Date: Tue, 3 Oct 2017 10:00:51 -0400
|
|
|
baf615 |
Subject: [PATCH 09/13] lib: move accounts proxy creation to helper
|
|
|
baf615 |
|
|
|
baf615 |
This commit factors out hte accounts proxy creation to a
|
|
|
baf615 |
helper function.
|
|
|
baf615 |
---
|
|
|
baf615 |
src/libaccountsservice/act-user-manager.c | 74 ++++++++++++++++++-------------
|
|
|
baf615 |
1 file changed, 43 insertions(+), 31 deletions(-)
|
|
|
baf615 |
|
|
|
baf615 |
diff --git a/src/libaccountsservice/act-user-manager.c b/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
index 556b070..5ac157d 100644
|
|
|
baf615 |
--- a/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
+++ b/src/libaccountsservice/act-user-manager.c
|
|
|
baf615 |
@@ -197,60 +197,61 @@ struct ActUserManagerPrivate
|
|
|
baf615 |
guint load_id;
|
|
|
baf615 |
|
|
|
baf615 |
gboolean is_loaded;
|
|
|
baf615 |
gboolean has_multiple_users;
|
|
|
baf615 |
gboolean getting_sessions;
|
|
|
baf615 |
gboolean listing_cached_users;
|
|
|
baf615 |
};
|
|
|
baf615 |
|
|
|
baf615 |
enum {
|
|
|
baf615 |
PROP_0,
|
|
|
baf615 |
PROP_INCLUDE_USERNAMES_LIST,
|
|
|
baf615 |
PROP_EXCLUDE_USERNAMES_LIST,
|
|
|
baf615 |
PROP_IS_LOADED,
|
|
|
baf615 |
PROP_HAS_MULTIPLE_USERS
|
|
|
baf615 |
};
|
|
|
baf615 |
|
|
|
baf615 |
enum {
|
|
|
baf615 |
USER_ADDED,
|
|
|
baf615 |
USER_REMOVED,
|
|
|
baf615 |
USER_IS_LOGGED_IN_CHANGED,
|
|
|
baf615 |
USER_CHANGED,
|
|
|
baf615 |
LAST_SIGNAL
|
|
|
baf615 |
};
|
|
|
baf615 |
|
|
|
baf615 |
static guint signals [LAST_SIGNAL] = { 0, };
|
|
|
baf615 |
|
|
|
baf615 |
static void act_user_manager_class_init (ActUserManagerClass *klass);
|
|
|
baf615 |
static void act_user_manager_init (ActUserManager *user_manager);
|
|
|
baf615 |
static void act_user_manager_finalize (GObject *object);
|
|
|
baf615 |
|
|
|
baf615 |
+static gboolean ensure_accounts_proxy (ActUserManager *manager);
|
|
|
baf615 |
static gboolean load_seat_incrementally (ActUserManager *manager);
|
|
|
baf615 |
static void unload_seat (ActUserManager *manager);
|
|
|
baf615 |
static void load_users (ActUserManager *manager);
|
|
|
baf615 |
static void act_user_manager_queue_load (ActUserManager *manager);
|
|
|
baf615 |
static void queue_load_seat_and_users (ActUserManager *manager);
|
|
|
baf615 |
|
|
|
baf615 |
static void load_new_session_incrementally (ActUserManagerNewSession *new_session);
|
|
|
baf615 |
static void set_is_loaded (ActUserManager *manager, gboolean is_loaded);
|
|
|
baf615 |
|
|
|
baf615 |
static void on_new_user_loaded (ActUser *user,
|
|
|
baf615 |
GParamSpec *pspec,
|
|
|
baf615 |
ActUserManager *manager);
|
|
|
baf615 |
static void give_up (ActUserManager *manager,
|
|
|
baf615 |
ActUserManagerFetchUserRequest *request);
|
|
|
baf615 |
static void fetch_user_incrementally (ActUserManagerFetchUserRequest *request);
|
|
|
baf615 |
|
|
|
baf615 |
static void maybe_set_is_loaded (ActUserManager *manager);
|
|
|
baf615 |
static void update_user (ActUserManager *manager,
|
|
|
baf615 |
ActUser *user);
|
|
|
baf615 |
static gpointer user_manager_object = NULL;
|
|
|
baf615 |
|
|
|
baf615 |
G_DEFINE_TYPE (ActUserManager, act_user_manager, G_TYPE_OBJECT)
|
|
|
baf615 |
|
|
|
baf615 |
static const GDBusErrorEntry error_entries[] = {
|
|
|
baf615 |
{ ACT_USER_MANAGER_ERROR_FAILED, "org.freedesktop.Accounts.Error.Failed" },
|
|
|
baf615 |
{ ACT_USER_MANAGER_ERROR_USER_EXISTS, "org.freedesktop.Accounts.Error.UserExists" },
|
|
|
baf615 |
{ ACT_USER_MANAGER_ERROR_USER_DOES_NOT_EXIST, "org.freedesktop.Accounts.Error.UserDoesNotExist" },
|
|
|
baf615 |
{ ACT_USER_MANAGER_ERROR_PERMISSION_DENIED, "org.freedesktop.Accounts.Error.PermissionDenied" },
|
|
|
baf615 |
{ ACT_USER_MANAGER_ERROR_NOT_SUPPORTED, "org.freedesktop.Accounts.Error.NotSupported" }
|
|
|
baf615 |
};
|
|
|
baf615 |
@@ -2805,132 +2806,143 @@ act_user_manager_class_init (ActUserManagerClass *klass)
|
|
|
baf615 |
signals [USER_CHANGED] =
|
|
|
baf615 |
g_signal_new ("user-changed",
|
|
|
baf615 |
G_TYPE_FROM_CLASS (klass),
|
|
|
baf615 |
G_SIGNAL_RUN_LAST,
|
|
|
baf615 |
G_STRUCT_OFFSET (ActUserManagerClass, user_changed),
|
|
|
baf615 |
NULL, NULL,
|
|
|
baf615 |
g_cclosure_marshal_VOID__OBJECT,
|
|
|
baf615 |
G_TYPE_NONE, 1, ACT_TYPE_USER);
|
|
|
baf615 |
|
|
|
baf615 |
g_type_class_add_private (klass, sizeof (ActUserManagerPrivate));
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
/**
|
|
|
baf615 |
* act_user_manager_queue_load:
|
|
|
baf615 |
* @manager: a #ActUserManager
|
|
|
baf615 |
*
|
|
|
baf615 |
* Queue loading users into user manager. This must be called, and the
|
|
|
baf615 |
* #ActUserManager:is-loaded property must be %TRUE before calling
|
|
|
baf615 |
* act_user_manager_list_users()
|
|
|
baf615 |
*/
|
|
|
baf615 |
static void
|
|
|
baf615 |
act_user_manager_queue_load (ActUserManager *manager)
|
|
|
baf615 |
{
|
|
|
baf615 |
g_return_if_fail (ACT_IS_USER_MANAGER (manager));
|
|
|
baf615 |
|
|
|
baf615 |
if (! manager->priv->is_loaded) {
|
|
|
baf615 |
queue_load_seat_and_users (manager);
|
|
|
baf615 |
}
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
+static gboolean
|
|
|
baf615 |
+ensure_accounts_proxy (ActUserManager *manager)
|
|
|
baf615 |
+{
|
|
|
baf615 |
+ GError *error = NULL;
|
|
|
baf615 |
+
|
|
|
baf615 |
+ if (manager->priv->accounts_proxy != NULL) {
|
|
|
baf615 |
+ return TRUE;
|
|
|
baf615 |
+ }
|
|
|
baf615 |
+
|
|
|
baf615 |
+ manager->priv->accounts_proxy = accounts_accounts_proxy_new_sync (manager->priv->connection,
|
|
|
baf615 |
+ G_DBUS_PROXY_FLAGS_NONE,
|
|
|
baf615 |
+ ACCOUNTS_NAME,
|
|
|
baf615 |
+ ACCOUNTS_PATH,
|
|
|
baf615 |
+ NULL,
|
|
|
baf615 |
+ &error);
|
|
|
baf615 |
+ if (error != NULL) {
|
|
|
baf615 |
+ g_debug ("ActUserManager: getting account proxy failed: %s", error->message);
|
|
|
baf615 |
+ g_clear_error (&error);
|
|
|
baf615 |
+ return FALSE;
|
|
|
baf615 |
+ }
|
|
|
baf615 |
+
|
|
|
baf615 |
+ g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (manager->priv->accounts_proxy), G_MAXINT);
|
|
|
baf615 |
+
|
|
|
baf615 |
+ g_object_bind_property (G_OBJECT (manager->priv->accounts_proxy),
|
|
|
baf615 |
+ "has-multiple-users",
|
|
|
baf615 |
+ G_OBJECT (manager),
|
|
|
baf615 |
+ "has-multiple-users",
|
|
|
baf615 |
+ G_BINDING_SYNC_CREATE);
|
|
|
baf615 |
+
|
|
|
baf615 |
+ g_signal_connect (manager->priv->accounts_proxy,
|
|
|
baf615 |
+ "user-added",
|
|
|
baf615 |
+ G_CALLBACK (on_new_user_in_accounts_service),
|
|
|
baf615 |
+ manager);
|
|
|
baf615 |
+ g_signal_connect (manager->priv->accounts_proxy,
|
|
|
baf615 |
+ "user-deleted",
|
|
|
baf615 |
+ G_CALLBACK (on_user_removed_in_accounts_service),
|
|
|
baf615 |
+ manager);
|
|
|
baf615 |
+
|
|
|
baf615 |
+ return TRUE;
|
|
|
baf615 |
+}
|
|
|
baf615 |
+
|
|
|
baf615 |
static void
|
|
|
baf615 |
act_user_manager_init (ActUserManager *manager)
|
|
|
baf615 |
{
|
|
|
baf615 |
GError *error;
|
|
|
baf615 |
|
|
|
baf615 |
manager->priv = ACT_USER_MANAGER_GET_PRIVATE (manager);
|
|
|
baf615 |
|
|
|
baf615 |
act_user_manager_error_quark (); /* register dbus errors */
|
|
|
baf615 |
|
|
|
baf615 |
/* sessions */
|
|
|
baf615 |
manager->priv->sessions = g_hash_table_new_full (g_str_hash,
|
|
|
baf615 |
g_str_equal,
|
|
|
baf615 |
g_free,
|
|
|
baf615 |
g_object_unref);
|
|
|
baf615 |
|
|
|
baf615 |
/* users */
|
|
|
baf615 |
manager->priv->normal_users_by_name = g_hash_table_new_full (g_str_hash,
|
|
|
baf615 |
g_str_equal,
|
|
|
baf615 |
g_free,
|
|
|
baf615 |
g_object_unref);
|
|
|
baf615 |
manager->priv->system_users_by_name = g_hash_table_new_full (g_str_hash,
|
|
|
baf615 |
g_str_equal,
|
|
|
baf615 |
g_free,
|
|
|
baf615 |
g_object_unref);
|
|
|
baf615 |
manager->priv->users_by_object_path = g_hash_table_new_full (g_str_hash,
|
|
|
baf615 |
g_str_equal,
|
|
|
baf615 |
NULL,
|
|
|
baf615 |
g_object_unref);
|
|
|
baf615 |
|
|
|
baf615 |
error = NULL;
|
|
|
baf615 |
manager->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
|
|
baf615 |
if (manager->priv->connection == NULL) {
|
|
|
baf615 |
if (error != NULL) {
|
|
|
baf615 |
g_warning ("Failed to connect to the D-Bus daemon: %s", error->message);
|
|
|
baf615 |
g_error_free (error);
|
|
|
baf615 |
} else {
|
|
|
baf615 |
g_warning ("Failed to connect to the D-Bus daemon");
|
|
|
baf615 |
}
|
|
|
baf615 |
return;
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
- manager->priv->accounts_proxy = accounts_accounts_proxy_new_sync (manager->priv->connection,
|
|
|
baf615 |
- G_DBUS_PROXY_FLAGS_NONE,
|
|
|
baf615 |
- ACCOUNTS_NAME,
|
|
|
baf615 |
- ACCOUNTS_PATH,
|
|
|
baf615 |
- NULL,
|
|
|
baf615 |
- &error);
|
|
|
baf615 |
- if (manager->priv->accounts_proxy == NULL) {
|
|
|
baf615 |
- if (error != NULL) {
|
|
|
baf615 |
- g_warning ("Failed to create accounts proxy: %s", error->message);
|
|
|
baf615 |
- g_error_free (error);
|
|
|
baf615 |
- } else {
|
|
|
baf615 |
- g_warning ("Failed to create_accounts_proxy");
|
|
|
baf615 |
- }
|
|
|
baf615 |
- return;
|
|
|
baf615 |
- }
|
|
|
baf615 |
- g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (manager->priv->accounts_proxy), G_MAXINT);
|
|
|
baf615 |
-
|
|
|
baf615 |
- g_object_bind_property (G_OBJECT (manager->priv->accounts_proxy),
|
|
|
baf615 |
- "has-multiple-users",
|
|
|
baf615 |
- G_OBJECT (manager),
|
|
|
baf615 |
- "has-multiple-users",
|
|
|
baf615 |
- G_BINDING_SYNC_CREATE);
|
|
|
baf615 |
-
|
|
|
baf615 |
- g_signal_connect (manager->priv->accounts_proxy,
|
|
|
baf615 |
- "user-added",
|
|
|
baf615 |
- G_CALLBACK (on_new_user_in_accounts_service),
|
|
|
baf615 |
- manager);
|
|
|
baf615 |
- g_signal_connect (manager->priv->accounts_proxy,
|
|
|
baf615 |
- "user-deleted",
|
|
|
baf615 |
- G_CALLBACK (on_user_removed_in_accounts_service),
|
|
|
baf615 |
- manager);
|
|
|
baf615 |
+ ensure_accounts_proxy (manager);
|
|
|
baf615 |
|
|
|
baf615 |
manager->priv->seat.state = ACT_USER_MANAGER_SEAT_STATE_UNLOADED;
|
|
|
baf615 |
}
|
|
|
baf615 |
|
|
|
baf615 |
static void
|
|
|
baf615 |
act_user_manager_finalize (GObject *object)
|
|
|
baf615 |
{
|
|
|
baf615 |
ActUserManager *manager;
|
|
|
baf615 |
GSList *node;
|
|
|
baf615 |
|
|
|
baf615 |
g_debug ("ActUserManager: finalizing user manager");
|
|
|
baf615 |
|
|
|
baf615 |
g_return_if_fail (object != NULL);
|
|
|
baf615 |
g_return_if_fail (ACT_IS_USER_MANAGER (object));
|
|
|
baf615 |
|
|
|
baf615 |
manager = ACT_USER_MANAGER (object);
|
|
|
baf615 |
|
|
|
baf615 |
g_return_if_fail (manager->priv != NULL);
|
|
|
baf615 |
|
|
|
baf615 |
g_slist_foreach (manager->priv->new_sessions,
|
|
|
baf615 |
(GFunc) unload_new_session, NULL);
|
|
|
baf615 |
g_slist_free (manager->priv->new_sessions);
|
|
|
baf615 |
|
|
|
baf615 |
g_slist_foreach (manager->priv->fetch_user_requests,
|
|
|
baf615 |
(GFunc) free_fetch_user_request, NULL);
|
|
|
baf615 |
g_slist_free (manager->priv->fetch_user_requests);
|
|
|
baf615 |
|
|
|
baf615 |
g_slist_free (manager->priv->new_users_inhibiting_load);
|
|
|
baf615 |
|
|
|
baf615 |
node = manager->priv->new_users;
|
|
|
baf615 |
--
|
|
|
baf615 |
2.14.1
|
|
|
baf615 |
|