core: make NMSessionMonitor non-refcounted
and ensure that main() frees the singleton before exiting
This commit is contained in:
@@ -54,6 +54,7 @@
|
|||||||
#include "nm-policy-hosts.h"
|
#include "nm-policy-hosts.h"
|
||||||
#include "nm-config.h"
|
#include "nm-config.h"
|
||||||
#include "nm-posix-signals.h"
|
#include "nm-posix-signals.h"
|
||||||
|
#include "nm-session-monitor.h"
|
||||||
|
|
||||||
#if !defined(NM_DIST_VERSION)
|
#if !defined(NM_DIST_VERSION)
|
||||||
# define NM_DIST_VERSION VERSION
|
# define NM_DIST_VERSION VERSION
|
||||||
@@ -319,6 +320,7 @@ main (int argc, char *argv[])
|
|||||||
gs_unref_object NMFirewallManager *fw_mgr = NULL;
|
gs_unref_object NMFirewallManager *fw_mgr = NULL;
|
||||||
gs_unref_object NMSettings *settings = NULL;
|
gs_unref_object NMSettings *settings = NULL;
|
||||||
gs_unref_object NMConfig *config = NULL;
|
gs_unref_object NMConfig *config = NULL;
|
||||||
|
gs_unref_object NMSessionMonitor *session_monitor = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean wrote_pidfile = FALSE;
|
gboolean wrote_pidfile = FALSE;
|
||||||
|
|
||||||
@@ -581,6 +583,10 @@ main (int argc, char *argv[])
|
|||||||
fw_mgr = nm_firewall_manager_get ();
|
fw_mgr = nm_firewall_manager_get ();
|
||||||
g_assert (fw_mgr != NULL);
|
g_assert (fw_mgr != NULL);
|
||||||
|
|
||||||
|
/* Initialize session monitor */
|
||||||
|
session_monitor = nm_session_monitor_get ();
|
||||||
|
g_assert (session_monitor != NULL);
|
||||||
|
|
||||||
if (!nm_dbus_manager_get_connection (dbus_mgr)) {
|
if (!nm_dbus_manager_get_connection (dbus_mgr)) {
|
||||||
#if HAVE_DBUS_GLIB_100
|
#if HAVE_DBUS_GLIB_100
|
||||||
nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available");
|
nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available");
|
||||||
|
@@ -354,10 +354,8 @@ nm_session_monitor_get (void)
|
|||||||
{
|
{
|
||||||
static NMSessionMonitor *singleton = NULL;
|
static NMSessionMonitor *singleton = NULL;
|
||||||
|
|
||||||
if (singleton)
|
if (!singleton)
|
||||||
return g_object_ref (singleton);
|
singleton = NM_SESSION_MONITOR (g_object_new (NM_TYPE_SESSION_MONITOR, NULL));
|
||||||
|
|
||||||
singleton = NM_SESSION_MONITOR (g_object_new (NM_TYPE_SESSION_MONITOR, NULL));
|
|
||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -81,11 +81,8 @@ nm_session_monitor_get (void)
|
|||||||
{
|
{
|
||||||
static NMSessionMonitor *singleton = NULL;
|
static NMSessionMonitor *singleton = NULL;
|
||||||
|
|
||||||
if (singleton)
|
if (!singleton)
|
||||||
return g_object_ref (singleton);
|
singleton = g_object_new (NM_TYPE_SESSION_MONITOR, NULL);
|
||||||
|
|
||||||
singleton = NM_SESSION_MONITOR (g_object_new (NM_TYPE_SESSION_MONITOR, NULL));
|
|
||||||
g_assert (singleton);
|
|
||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -193,11 +193,8 @@ nm_session_monitor_get (void)
|
|||||||
{
|
{
|
||||||
static NMSessionMonitor *singleton = NULL;
|
static NMSessionMonitor *singleton = NULL;
|
||||||
|
|
||||||
if (singleton)
|
if (!singleton)
|
||||||
return g_object_ref (singleton);
|
singleton = g_object_new (NM_TYPE_SESSION_MONITOR, NULL);
|
||||||
|
|
||||||
singleton = NM_SESSION_MONITOR (g_object_new (NM_TYPE_SESSION_MONITOR, NULL));
|
|
||||||
g_assert (singleton);
|
|
||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,7 +47,6 @@ typedef struct {
|
|||||||
gboolean disposed;
|
gboolean disposed;
|
||||||
|
|
||||||
NMDBusManager *dbus_mgr;
|
NMDBusManager *dbus_mgr;
|
||||||
NMSessionMonitor *session_monitor;
|
|
||||||
|
|
||||||
/* Auth chains for checking agent permissions */
|
/* Auth chains for checking agent permissions */
|
||||||
GSList *chains;
|
GSList *chains;
|
||||||
@@ -70,9 +69,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
|||||||
|
|
||||||
typedef struct _Request Request;
|
typedef struct _Request Request;
|
||||||
|
|
||||||
static void request_add_agent (Request *req,
|
static void request_add_agent (Request *req, NMSecretAgent *agent);
|
||||||
NMSecretAgent *agent,
|
|
||||||
NMSessionMonitor *session_monitor);
|
|
||||||
|
|
||||||
static void request_remove_agent (Request *req, NMSecretAgent *agent, GSList **pending_reqs);
|
static void request_remove_agent (Request *req, NMSecretAgent *agent, GSList **pending_reqs);
|
||||||
|
|
||||||
@@ -251,7 +248,7 @@ agent_register_permissions_done (NMAuthChain *chain,
|
|||||||
/* Add this agent to any in-progress secrets requests */
|
/* Add this agent to any in-progress secrets requests */
|
||||||
g_hash_table_iter_init (&iter, priv->requests);
|
g_hash_table_iter_init (&iter, priv->requests);
|
||||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &req))
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &req))
|
||||||
request_add_agent (req, agent, priv->session_monitor);
|
request_add_agent (req, agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_auth_chain_unref (chain);
|
nm_auth_chain_unref (chain);
|
||||||
@@ -298,7 +295,7 @@ impl_agent_manager_register_with_capabilities (NMAgentManager *self,
|
|||||||
sender_uid = nm_auth_subject_get_uid (subject);
|
sender_uid = nm_auth_subject_get_uid (subject);
|
||||||
|
|
||||||
if ( 0 != sender_uid
|
if ( 0 != sender_uid
|
||||||
&& !nm_session_monitor_uid_has_session (priv->session_monitor,
|
&& !nm_session_monitor_uid_has_session (nm_session_monitor_get (),
|
||||||
sender_uid,
|
sender_uid,
|
||||||
NULL,
|
NULL,
|
||||||
&local)) {
|
&local)) {
|
||||||
@@ -406,9 +403,7 @@ typedef void (*RequestCompleteFunc) (Request *req,
|
|||||||
const char *agent_username,
|
const char *agent_username,
|
||||||
GError *error,
|
GError *error,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
typedef gboolean (*RequestAddAgentFunc) (Request *req,
|
typedef gboolean (*RequestAddAgentFunc) (Request *req, NMSecretAgent *agent);
|
||||||
NMSecretAgent *agent,
|
|
||||||
NMSessionMonitor *session_monitor);
|
|
||||||
typedef void (*RequestNextFunc) (Request *req);
|
typedef void (*RequestNextFunc) (Request *req);
|
||||||
typedef void (*RequestCancelFunc) (Request *req);
|
typedef void (*RequestCancelFunc) (Request *req);
|
||||||
|
|
||||||
@@ -523,7 +518,6 @@ req_complete_error (Request *req, GError *error)
|
|||||||
static gint
|
static gint
|
||||||
agent_compare_func (NMSecretAgent *a, NMSecretAgent *b, gpointer user_data)
|
agent_compare_func (NMSecretAgent *a, NMSecretAgent *b, gpointer user_data)
|
||||||
{
|
{
|
||||||
NMSessionMonitor *session_monitor = NM_SESSION_MONITOR (user_data);
|
|
||||||
gboolean a_active, b_active;
|
gboolean a_active, b_active;
|
||||||
|
|
||||||
if (a && !b)
|
if (a && !b)
|
||||||
@@ -534,10 +528,10 @@ agent_compare_func (NMSecretAgent *a, NMSecretAgent *b, gpointer user_data)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Prefer agents in active sessions */
|
/* Prefer agents in active sessions */
|
||||||
a_active = nm_session_monitor_uid_active (session_monitor,
|
a_active = nm_session_monitor_uid_active (nm_session_monitor_get (),
|
||||||
nm_secret_agent_get_owner_uid (a),
|
nm_secret_agent_get_owner_uid (a),
|
||||||
NULL);
|
NULL);
|
||||||
b_active = nm_session_monitor_uid_active (session_monitor,
|
b_active = nm_session_monitor_uid_active (nm_session_monitor_get (),
|
||||||
nm_secret_agent_get_owner_uid (b),
|
nm_secret_agent_get_owner_uid (b),
|
||||||
NULL);
|
NULL);
|
||||||
if (a_active && !b_active)
|
if (a_active && !b_active)
|
||||||
@@ -551,9 +545,7 @@ agent_compare_func (NMSecretAgent *a, NMSecretAgent *b, gpointer user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
request_add_agent (Request *req,
|
request_add_agent (Request *req, NMSecretAgent *agent)
|
||||||
NMSecretAgent *agent,
|
|
||||||
NMSessionMonitor *session_monitor)
|
|
||||||
{
|
{
|
||||||
uid_t agent_uid;
|
uid_t agent_uid;
|
||||||
|
|
||||||
@@ -563,7 +555,7 @@ request_add_agent (Request *req,
|
|||||||
if (g_slist_find (req->asked, GUINT_TO_POINTER (nm_secret_agent_get_hash (agent))))
|
if (g_slist_find (req->asked, GUINT_TO_POINTER (nm_secret_agent_get_hash (agent))))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (req->add_agent_callback && !req->add_agent_callback (req, agent, session_monitor))
|
if (req->add_agent_callback && !req->add_agent_callback (req, agent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* If the request should filter agents by UID, do that now */
|
/* If the request should filter agents by UID, do that now */
|
||||||
@@ -584,7 +576,7 @@ request_add_agent (Request *req,
|
|||||||
req->pending = g_slist_insert_sorted_with_data (req->pending,
|
req->pending = g_slist_insert_sorted_with_data (req->pending,
|
||||||
g_object_ref (agent),
|
g_object_ref (agent),
|
||||||
(GCompareDataFunc) agent_compare_func,
|
(GCompareDataFunc) agent_compare_func,
|
||||||
session_monitor);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -596,7 +588,7 @@ request_add_agents (NMAgentManager *self, Request *req)
|
|||||||
|
|
||||||
g_hash_table_iter_init (&iter, priv->agents);
|
g_hash_table_iter_init (&iter, priv->agents);
|
||||||
while (g_hash_table_iter_next (&iter, NULL, &data))
|
while (g_hash_table_iter_next (&iter, NULL, &data))
|
||||||
request_add_agent (req, NM_SECRET_AGENT (data), priv->session_monitor);
|
request_add_agent (req, NM_SECRET_AGENT (data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -699,9 +691,7 @@ connection_request_free (gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
connection_request_add_agent (Request *parent,
|
connection_request_add_agent (Request *parent, NMSecretAgent *agent)
|
||||||
NMSecretAgent *agent,
|
|
||||||
NMSessionMonitor *session_monitor)
|
|
||||||
{
|
{
|
||||||
ConnectionRequest *req = (ConnectionRequest *) parent;
|
ConnectionRequest *req = (ConnectionRequest *) parent;
|
||||||
uid_t agent_uid = nm_secret_agent_get_owner_uid (agent);
|
uid_t agent_uid = nm_secret_agent_get_owner_uid (agent);
|
||||||
@@ -709,7 +699,7 @@ connection_request_add_agent (Request *parent,
|
|||||||
/* Ensure the caller's username exists in the connection's permissions,
|
/* Ensure the caller's username exists in the connection's permissions,
|
||||||
* or that the permissions is empty (ie, visible by everyone).
|
* or that the permissions is empty (ie, visible by everyone).
|
||||||
*/
|
*/
|
||||||
if (!nm_auth_uid_in_acl (req->connection, session_monitor, agent_uid, NULL)) {
|
if (!nm_auth_uid_in_acl (req->connection, nm_session_monitor_get (), agent_uid, NULL)) {
|
||||||
nm_log_dbg (LOGD_AGENTS, "(%s) agent ignored for secrets request %p/%s (not in ACL)",
|
nm_log_dbg (LOGD_AGENTS, "(%s) agent ignored for secrets request %p/%s (not in ACL)",
|
||||||
nm_secret_agent_get_description (agent),
|
nm_secret_agent_get_description (agent),
|
||||||
parent, parent->detail);
|
parent, parent->detail);
|
||||||
@@ -1546,7 +1536,6 @@ nm_agent_manager_get (void)
|
|||||||
g_assert (singleton);
|
g_assert (singleton);
|
||||||
|
|
||||||
priv = NM_AGENT_MANAGER_GET_PRIVATE (singleton);
|
priv = NM_AGENT_MANAGER_GET_PRIVATE (singleton);
|
||||||
priv->session_monitor = nm_session_monitor_get ();
|
|
||||||
priv->dbus_mgr = nm_dbus_manager_get ();
|
priv->dbus_mgr = nm_dbus_manager_get ();
|
||||||
|
|
||||||
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_AGENT_MANAGER, singleton);
|
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_AGENT_MANAGER, singleton);
|
||||||
@@ -1588,7 +1577,6 @@ dispose (GObject *object)
|
|||||||
g_hash_table_destroy (priv->agents);
|
g_hash_table_destroy (priv->agents);
|
||||||
g_hash_table_destroy (priv->requests);
|
g_hash_table_destroy (priv->requests);
|
||||||
|
|
||||||
g_object_unref (priv->session_monitor);
|
|
||||||
priv->dbus_mgr = NULL;
|
priv->dbus_mgr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1969,7 +1969,6 @@ dispose (GObject *object)
|
|||||||
|
|
||||||
if (priv->session_changed_id)
|
if (priv->session_changed_id)
|
||||||
g_signal_handler_disconnect (priv->session_monitor, priv->session_changed_id);
|
g_signal_handler_disconnect (priv->session_monitor, priv->session_changed_id);
|
||||||
g_object_unref (priv->session_monitor);
|
|
||||||
g_object_unref (priv->agent_mgr);
|
g_object_unref (priv->agent_mgr);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@@ -133,7 +133,6 @@ typedef struct {
|
|||||||
|
|
||||||
NMConfig *config;
|
NMConfig *config;
|
||||||
|
|
||||||
NMSessionMonitor *session_monitor;
|
|
||||||
GSList *auths;
|
GSList *auths;
|
||||||
|
|
||||||
GSList *plugins;
|
GSList *plugins;
|
||||||
@@ -1128,7 +1127,7 @@ nm_settings_add_connection_dbus (NMSettings *self,
|
|||||||
* or that the permissions is empty (ie, visible by everyone).
|
* or that the permissions is empty (ie, visible by everyone).
|
||||||
*/
|
*/
|
||||||
if (!nm_auth_uid_in_acl (connection,
|
if (!nm_auth_uid_in_acl (connection,
|
||||||
priv->session_monitor,
|
nm_session_monitor_get (),
|
||||||
nm_auth_subject_get_uid (subject),
|
nm_auth_subject_get_uid (subject),
|
||||||
&error_desc)) {
|
&error_desc)) {
|
||||||
error = g_error_new_literal (NM_SETTINGS_ERROR,
|
error = g_error_new_literal (NM_SETTINGS_ERROR,
|
||||||
@@ -1817,8 +1816,6 @@ nm_settings_init (NMSettings *self)
|
|||||||
|
|
||||||
priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
|
priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
|
||||||
|
|
||||||
priv->session_monitor = nm_session_monitor_get ();
|
|
||||||
|
|
||||||
/* Hold a reference to the agent manager so it stays alive; the only
|
/* Hold a reference to the agent manager so it stays alive; the only
|
||||||
* other holders are NMSettingsConnection objects which are often
|
* other holders are NMSettingsConnection objects which are often
|
||||||
* transient, and we don't want the agent manager to get destroyed and
|
* transient, and we don't want the agent manager to get destroyed and
|
||||||
@@ -1840,7 +1837,6 @@ dispose (GObject *object)
|
|||||||
|
|
||||||
priv->dbus_mgr = NULL;
|
priv->dbus_mgr = NULL;
|
||||||
|
|
||||||
g_object_unref (priv->session_monitor);
|
|
||||||
g_object_unref (priv->agent_mgr);
|
g_object_unref (priv->agent_mgr);
|
||||||
|
|
||||||
G_OBJECT_CLASS (nm_settings_parent_class)->dispose (object);
|
G_OBJECT_CLASS (nm_settings_parent_class)->dispose (object);
|
||||||
|
Reference in New Issue
Block a user