From 3e1801ab06d7dec11c8a038d1e46cf260bf8c0c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Sat, 2 Jun 2018 19:44:24 +0200
Subject: [PATCH 10/15] libgdm: Don't save manager address
There's no need to keep the manager connection address around, and
use autofree to clean it up
---
libgdm/gdm-client.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/libgdm/gdm-client.c b/libgdm/gdm-client.c
index acf016a48..0e8bf4399 100644
--- a/libgdm/gdm-client.c
+++ b/libgdm/gdm-client.c
@@ -19,61 +19,60 @@
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include "gdm-client.h"
#include "gdm-client-glue.h"
#include "gdm-manager-glue.h"
#define GDM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_CLIENT, GdmClientPrivate))
#define SESSION_DBUS_PATH "/org/gnome/DisplayManager/Session"
struct GdmClientPrivate
{
GdmUserVerifier *user_verifier;
GHashTable *user_verifier_extensions;
GdmGreeter *greeter;
GdmRemoteGreeter *remote_greeter;
GdmChooser *chooser;
- char *address;
char **enabled_extensions;
};
static void gdm_client_class_init (GdmClientClass *klass);
static void gdm_client_init (GdmClient *client);
static void gdm_client_finalize (GObject *object);
G_DEFINE_TYPE (GdmClient, gdm_client, G_TYPE_OBJECT);
static gpointer client_object = NULL;
GQuark
gdm_client_error_quark (void)
{
static GQuark error_quark = 0;
if (error_quark == 0)
error_quark = g_quark_from_static_string ("gdm-client");
return error_quark;
}
static GDBusConnection *
gdm_client_get_open_connection (GdmClient *client)
{
GDBusProxy *proxy = NULL;
if (client->priv->user_verifier != NULL) {
proxy = G_DBUS_PROXY (client->priv->user_verifier);
@@ -393,155 +392,151 @@ on_got_manager_for_reauthentication (GdmClient *client,
GCancellable *cancellable;
GdmManager *manager;
char *username;
GError *error;
error = NULL;
manager = g_task_propagate_pointer (G_TASK (result), &error);
if (manager == NULL) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
cancellable = g_task_get_cancellable (task);
username = g_object_get_data (G_OBJECT (task), "username");
gdm_manager_call_open_reauthentication_channel (manager,
username,
cancellable,
(GAsyncReadyCallback)
on_reauthentication_channel_opened,
task);
g_object_unref (manager);
}
static GDBusConnection *
gdm_client_get_connection_sync (GdmClient *client,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GdmManager) manager = NULL;
+ g_autofree char *address = NULL;
GDBusConnection *connection;
gboolean ret;
g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE);
connection = gdm_client_get_open_connection (client);
if (connection != NULL) {
return g_object_ref (connection);
}
manager = gdm_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
"org.gnome.DisplayManager",
"/org/gnome/DisplayManager/Manager",
cancellable,
error);
if (manager == NULL) {
- goto out;
+ return NULL;
}
ret = gdm_manager_call_open_session_sync (manager,
- &client->priv->address,
+ &address,
cancellable,
error);
if (!ret) {
- goto out;
+ return NULL;
}
- g_debug ("GdmClient: connecting to address: %s", client->priv->address);
+ g_debug ("GdmClient: connecting to address: %s", address);
- connection = g_dbus_connection_new_for_address_sync (client->priv->address,
+ connection = g_dbus_connection_new_for_address_sync (address,
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
NULL,
cancellable,
error);
- if (connection == NULL) {
- g_clear_pointer (&client->priv->address, g_free);
- goto out;
- }
-
- out:
return connection;
}
static void
on_connected (GObject *source_object,
GAsyncResult *result,
GTask *task)
{
GDBusConnection *connection;
GError *error;
error = NULL;
connection = g_dbus_connection_new_for_address_finish (result, &error);
if (!connection) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
g_task_return_pointer (task,
g_object_ref (connection),
(GDestroyNotify) g_object_unref);
g_object_unref (task);
g_object_unref (connection);
}
static void
on_session_opened (GdmManager *manager,
GAsyncResult *result,
GTask *task)
{
GdmClient *client;
+ g_autofree char *address = NULL;
GCancellable *cancellable;
GError *error;
client = GDM_CLIENT (g_async_result_get_source_object (G_ASYNC_RESULT (task)));
error = NULL;
if (!gdm_manager_call_open_session_finish (manager,
- &client->priv->address,
+ &address,
result,
&error)) {
g_task_return_error (task, error);
g_object_unref (task);
g_object_unref (client);
return;
}
cancellable = g_task_get_cancellable (task);
- g_dbus_connection_new_for_address (client->priv->address,
+ g_dbus_connection_new_for_address (address,
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
NULL,
cancellable,
(GAsyncReadyCallback)
on_connected,
task);
g_object_unref (client);
}
static void
on_got_manager_for_opening_connection (GdmClient *client,
GAsyncResult *result,
GTask *task)
{
GCancellable *cancellable;
GdmManager *manager;
GError *error;
error = NULL;
manager = g_task_propagate_pointer (G_TASK (result), &error);
if (manager == NULL) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
cancellable = g_task_get_cancellable (task);
gdm_manager_call_open_session (manager,
cancellable,
(GAsyncReadyCallback)
@@ -1499,61 +1494,60 @@ gdm_client_finalize (GObject *object)
client = GDM_CLIENT (object);
g_return_if_fail (client->priv != NULL);
if (client->priv->user_verifier != NULL) {
g_object_remove_weak_pointer (G_OBJECT (client->priv->user_verifier),
(gpointer *)
&client->priv->user_verifier);
}
if (client->priv->greeter != NULL) {
g_object_remove_weak_pointer (G_OBJECT (client->priv->greeter),
(gpointer *)
&client->priv->greeter);
}
if (client->priv->remote_greeter != NULL) {
g_object_remove_weak_pointer (G_OBJECT (client->priv->remote_greeter),
(gpointer *)
&client->priv->remote_greeter);
}
if (client->priv->chooser != NULL) {
g_object_remove_weak_pointer (G_OBJECT (client->priv->chooser),
(gpointer *)
&client->priv->chooser);
}
g_strfreev (client->priv->enabled_extensions);
- g_free (client->priv->address);
G_OBJECT_CLASS (gdm_client_parent_class)->finalize (object);
}
GdmClient *
gdm_client_new (void)
{
if (client_object != NULL) {
g_object_ref (client_object);
} else {
client_object = g_object_new (GDM_TYPE_CLIENT, NULL);
g_object_add_weak_pointer (client_object,
(gpointer *) &client_object);
}
return GDM_CLIENT (client_object);
}
/**
* gdm_client_set_enabled_extensions:
* @client: a #GdmClient
* @extensions: (array zero-terminated=1) (element-type utf8): a list of extensions
*
* Enables GDM's pam extensions. Currently, only
* org.gnome.DisplayManager.UserVerifier.ChoiceList is supported.
*/
void
gdm_client_set_enabled_extensions (GdmClient *client,
const char * const *extensions)
--
2.25.1