core: use singleton nm_firewall_manager_get() throughout without taking additional ref

No need to keep references of the singleton and take an additional ref
when accessing nm_firewall_manager_get().
Especially, since the firewall manager instance was nowhere passed in from
externally, it doesn't even sense for some vague testing purporse. Not to
mention, that there are no tests that actually inject a firewall manager stub.

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-07-02 15:19:58 +02:00
parent e343c45ebb
commit 62dd70e1d1
3 changed files with 22 additions and 35 deletions

View file

@ -251,8 +251,7 @@ typedef struct {
NMDnsMasqManager *dnsmasq_manager;
gulong dnsmasq_state_id;
/* Firewall Manager */
NMFirewallManager *fw_manager;
/* Firewall */
DBusGProxyCall *fw_call;
/* avahi-autoipd stuff */
@ -4142,7 +4141,7 @@ nm_device_activate_schedule_stage3_ip_config_start (NMDevice *self)
zone = nm_setting_connection_get_zone (s_con);
nm_log_dbg (LOGD_DEVICE, "Activation (%s) setting firewall zone '%s'",
nm_device_get_iface (self), zone ? zone : "default");
priv->fw_call = nm_firewall_manager_add_or_change_zone (priv->fw_manager,
priv->fw_call = nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (),
nm_device_get_ip_iface (self),
zone,
FALSE,
@ -6425,23 +6424,21 @@ nm_device_has_pending_action (NMDevice *device)
static void
_cleanup_generic_pre (NMDevice *self, gboolean deconfigure)
{
NMConnection *connection;
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
/* Clean up when device was deactivated during call to firewall */
if (priv->fw_manager) {
NMConnection *connection;
if (priv->fw_call) {
nm_firewall_manager_cancel_call (priv->fw_manager, priv->fw_call);
priv->fw_call = NULL;
}
if (priv->fw_call) {
nm_firewall_manager_cancel_call (nm_firewall_manager_get (), priv->fw_call);
priv->fw_call = NULL;
}
connection = nm_device_get_connection (self);
if (deconfigure && connection) {
nm_firewall_manager_remove_from_zone (priv->fw_manager,
nm_device_get_ip_iface (self),
NULL);
}
connection = nm_device_get_connection (self);
if (deconfigure && connection) {
nm_firewall_manager_remove_from_zone (nm_firewall_manager_get (),
nm_device_get_ip_iface (self),
NULL);
}
ip_check_gw_ping_cleanup (self);
@ -7234,8 +7231,6 @@ constructor (GType type,
if (NM_DEVICE_GET_CLASS (dev)->get_generic_capabilities)
priv->capabilities |= NM_DEVICE_GET_CLASS (dev)->get_generic_capabilities (dev);
priv->fw_manager = nm_firewall_manager_get ();
device_get_driver_info (priv->iface, &priv->driver_version, &priv->firmware_version);
/* Watch for external IP config changes */
@ -7356,8 +7351,6 @@ dispose (GObject *object)
g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (device_ip_changed), self);
g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (link_changed_cb), self);
g_clear_object (&priv->fw_manager);
G_OBJECT_CLASS (nm_device_parent_class)->dispose (object);
}

View file

@ -263,12 +263,11 @@ nm_firewall_manager_get (void)
{
static NMFirewallManager *singleton = NULL;
if (!singleton)
if (G_UNLIKELY (!singleton)) {
singleton = NM_FIREWALL_MANAGER (g_object_new (NM_TYPE_FIREWALL_MANAGER, NULL));
else
g_object_ref (singleton);
g_assert (singleton);
}
g_assert (singleton);
return singleton;
}

View file

@ -54,7 +54,6 @@ typedef struct {
GSList *pending_secondaries;
NMFirewallManager *fw_manager;
gulong fw_started_id;
NMSettings *settings;
@ -1883,7 +1882,7 @@ firewall_update_zone (NMPolicy *policy, NMConnection *connection)
if ( (nm_device_get_connection (dev) == connection)
&& (nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED)) {
nm_firewall_manager_add_or_change_zone (priv->fw_manager,
nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (),
nm_device_get_ip_iface (dev),
nm_setting_connection_get_zone (s_con),
FALSE, /* change zone */
@ -1913,7 +1912,7 @@ firewall_started (NMFirewallManager *manager,
s_con = nm_connection_get_setting_connection (connection);
if (nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED) {
nm_firewall_manager_add_or_change_zone (priv->fw_manager,
nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (),
nm_device_get_ip_iface (dev),
nm_setting_connection_get_zone (s_con),
FALSE, /* still change zone */
@ -2069,7 +2068,6 @@ nm_policy_new (NMManager *manager, NMSettings *settings)
NMPolicy *policy;
NMPolicyPrivate *priv;
static gboolean initialized = FALSE;
gulong id;
char hostname[HOST_NAME_MAX + 2];
g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
@ -2092,10 +2090,8 @@ nm_policy_new (NMManager *manager, NMSettings *settings)
priv->orig_hostname = g_strdup (hostname);
}
priv->fw_manager = nm_firewall_manager_get();
id = g_signal_connect (priv->fw_manager, "started",
G_CALLBACK (firewall_started), policy);
priv->fw_started_id = id;
priv->fw_started_id = g_signal_connect (nm_firewall_manager_get (), "started",
G_CALLBACK (firewall_started), policy);
priv->dns_manager = nm_dns_manager_get ();
nm_dns_manager_set_initial_hostname (priv->dns_manager, priv->orig_hostname);
@ -2201,10 +2197,9 @@ dispose (GObject *object)
g_slist_free_full (priv->pending_secondaries, (GDestroyNotify) pending_secondary_data_free);
priv->pending_secondaries = NULL;
if (priv->fw_manager) {
g_signal_handler_disconnect (priv->fw_manager, priv->fw_started_id);
g_object_unref (priv->fw_manager);
priv->fw_manager = NULL;
if (priv->fw_started_id) {
g_signal_handler_disconnect (nm_firewall_manager_get (), priv->fw_started_id);
priv->fw_started_id = 0;
}
if (priv->dns_manager) {