2007-01-04 Dan Williams <dcbw@redhat.com>
Threading removal related cleanups: - Use the glib default main context. Remove the device main context member from NMDevice, and the main_context member from NMData. Change all the idle and timeout scheduler functions to use plain g_idle_add() and g_timeout_add(). - As a side-effect of the first change, nm_dbus_manager_get() no longer takes an argument; fix that up too. - Remove all locking, which is useless since we no longer use threads. For example, nm_get_device_by_iface_locked() has been removed. The global device list lock, the AP List lock, and all static locks in NetworkManagerPolicy.c have been removed. The locking utility functions in NetworkManagerUtils.c have also been removed. - Other cleanups in spacing and code style git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2205 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
20
ChangeLog
20
ChangeLog
@@ -1,3 +1,23 @@
|
||||
2007-01-04 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
Threading removal related cleanups:
|
||||
|
||||
- Use the glib default main context. Remove the device main context
|
||||
member from NMDevice, and the main_context member from NMData. Change
|
||||
all the idle and timeout scheduler functions to use plain
|
||||
g_idle_add() and g_timeout_add().
|
||||
|
||||
- As a side-effect of the first change, nm_dbus_manager_get() no longer
|
||||
takes an argument; fix that up too.
|
||||
|
||||
- Remove all locking, which is useless since we no longer use threads. For
|
||||
example, nm_get_device_by_iface_locked() has been removed. The global
|
||||
device list lock, the AP List lock, and all static locks in
|
||||
NetworkManagerPolicy.c have been removed. The locking utility functions
|
||||
in NetworkManagerUtils.c have also been removed.
|
||||
|
||||
- Other cleanups in spacing and code style
|
||||
|
||||
2007-01-01 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
Found by Bill Moss:
|
||||
|
@@ -137,42 +137,26 @@ NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, cons
|
||||
if ((dev = nm_get_device_by_iface (data, iface)))
|
||||
return (NULL);
|
||||
|
||||
if ((dev = nm_device_new (iface, udi, test_device, test_device_type, data)))
|
||||
{
|
||||
/* Attempt to acquire mutex for device list addition. If acquire fails,
|
||||
* just ignore the device addition entirely.
|
||||
*/
|
||||
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||
{
|
||||
if ((dev = nm_device_new (iface, udi, test_device, test_device_type, data))) {
|
||||
nm_info ("Now managing %s device '%s'.",
|
||||
nm_device_is_802_11_wireless (dev) ? "wireless (802.11)" : "wired Ethernet (802.3)", nm_device_get_iface (dev));
|
||||
nm_device_is_802_11_wireless (dev) ? "wireless (802.11)" : "wired Ethernet (802.3)",
|
||||
nm_device_get_iface (dev));
|
||||
|
||||
data->dev_list = g_slist_append (data->dev_list, dev);
|
||||
nm_device_deactivate (dev);
|
||||
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
|
||||
nm_policy_schedule_device_change_check (data);
|
||||
nm_dbus_schedule_device_status_change_signal (data, dev, NULL, DEVICE_ADDED);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If we couldn't add the device to our list, free its data. */
|
||||
nm_warning ("could not acquire device list mutex." );
|
||||
g_object_unref (G_OBJECT (dev));
|
||||
dev = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return (dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_remove_device
|
||||
*
|
||||
* Removes a particular device from the device list. Requires that
|
||||
* the device list is locked, if needed.
|
||||
* Removes a particular device from the device list.
|
||||
*/
|
||||
void nm_remove_device (NMData *data, NMDevice *dev)
|
||||
{
|
||||
@@ -198,23 +182,21 @@ void nm_remove_device (NMData *data, NMDevice *dev)
|
||||
*/
|
||||
NMDevice *nm_get_active_device (NMData *data)
|
||||
{
|
||||
NMDevice * dev = NULL;
|
||||
GSList * elt;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
|
||||
nm_lock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
if ((dev = (NMDevice *)(elt->data)) && nm_device_get_act_request (dev))
|
||||
break;
|
||||
dev = NULL;
|
||||
}
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {
|
||||
NMDevice * dev = NM_DEVICE (elt->data);
|
||||
|
||||
g_assert (dev);
|
||||
if (nm_device_get_act_request (dev))
|
||||
return dev;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_hal_device_added
|
||||
@@ -247,23 +229,18 @@ static void nm_hal_device_added (LibHalContext *ctx, const char *udi)
|
||||
*/
|
||||
static void nm_hal_device_removed (LibHalContext *ctx, const char *udi)
|
||||
{
|
||||
NMData *data = (NMData *)libhal_ctx_get_user_data (ctx);
|
||||
NMData * data;
|
||||
NMDevice * dev;
|
||||
|
||||
data = (NMData *) libhal_ctx_get_user_data (ctx);
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
nm_debug ("Device removed (hal udi is '%s').", udi );
|
||||
|
||||
if (!nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||
return;
|
||||
|
||||
if ((dev = nm_get_device_by_udi (data, udi)))
|
||||
{
|
||||
if ((dev = nm_get_device_by_udi (data, udi))) {
|
||||
nm_remove_device (data, dev);
|
||||
nm_policy_schedule_device_change_check (data);
|
||||
}
|
||||
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
}
|
||||
|
||||
|
||||
@@ -346,7 +323,7 @@ static gboolean nm_state_change_signal_broadcast (gpointer user_data)
|
||||
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (dbus_connection)
|
||||
nm_dbus_signal_state_change (dbus_connection, data);
|
||||
@@ -366,11 +343,11 @@ void nm_schedule_state_change_signal_broadcast (NMData *data)
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
id = g_idle_add (nm_state_change_signal_broadcast, data);
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
if (source) {
|
||||
g_source_set_priority (source, G_PRIORITY_HIGH);
|
||||
g_source_set_callback (source, nm_state_change_signal_broadcast, data, NULL);
|
||||
id = g_source_attach (source, data->main_context);
|
||||
g_source_unref (source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -405,7 +382,7 @@ nm_monitor_setup (NMData *data)
|
||||
G_CALLBACK (nm_error_monitoring_device_link_state),
|
||||
data);
|
||||
|
||||
nm_netlink_monitor_attach (monitor, data->main_context);
|
||||
nm_netlink_monitor_attach (monitor, NULL);
|
||||
|
||||
/* Request initial status of cards */
|
||||
nm_netlink_monitor_request_status (monitor, NULL);
|
||||
@@ -444,7 +421,7 @@ nm_hal_init (NMData *data,
|
||||
goto out;
|
||||
}
|
||||
|
||||
libhal_ctx_set_user_data (data->hal_ctx, data->main_context);
|
||||
libhal_ctx_set_user_data (data->hal_ctx, data);
|
||||
libhal_ctx_set_device_added (data->hal_ctx, nm_hal_device_added);
|
||||
libhal_ctx_set_device_removed (data->hal_ctx, nm_hal_device_removed);
|
||||
libhal_ctx_set_device_new_capability (data->hal_ctx, nm_hal_device_new_capability);
|
||||
@@ -503,39 +480,25 @@ nm_hal_deinit (NMData *data)
|
||||
static NMData *nm_data_new (gboolean enable_test_devices)
|
||||
{
|
||||
NMData * data;
|
||||
GSource * iosource;
|
||||
guint id;
|
||||
|
||||
data = g_slice_new0 (NMData);
|
||||
|
||||
data->main_context = g_main_context_new ();
|
||||
data->main_loop = g_main_loop_new (data->main_context, FALSE);
|
||||
data->main_loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
/* Allow clean shutdowns by having the thread which receives the signal
|
||||
* notify the main thread to quit, rather than having the receiving
|
||||
* thread try to quit the glib main loop.
|
||||
*/
|
||||
if (pipe (data->sigterm_pipe) < 0)
|
||||
{
|
||||
if (pipe (data->sigterm_pipe) < 0) {
|
||||
nm_error ("Couldn't create pipe: %s", g_strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
data->sigterm_iochannel = g_io_channel_unix_new (data->sigterm_pipe[0]);
|
||||
iosource = g_io_create_watch (data->sigterm_iochannel, G_IO_IN | G_IO_ERR);
|
||||
g_source_set_callback (iosource, (GSourceFunc) sigterm_pipe_handler, data, NULL);
|
||||
g_source_attach (iosource, data->main_context);
|
||||
g_source_unref (iosource);
|
||||
|
||||
/* Initialize the device list mutex to protect additions/deletions to it. */
|
||||
data->dev_list_mutex = g_mutex_new ();
|
||||
data->dialup_list_mutex = g_mutex_new ();
|
||||
if (!data->dev_list_mutex || !data->dialup_list_mutex)
|
||||
{
|
||||
nm_data_free (data);
|
||||
nm_warning ("could not initialize data structure locks.");
|
||||
return NULL;
|
||||
}
|
||||
nm_register_mutex_desc (data->dev_list_mutex, "Device List Mutex");
|
||||
nm_register_mutex_desc (data->dialup_list_mutex, "DialUp List Mutex");
|
||||
id = g_io_add_watch (data->sigterm_iochannel,
|
||||
G_IO_IN | G_IO_ERR,
|
||||
sigterm_pipe_handler,
|
||||
data);
|
||||
|
||||
/* Initialize the access point lists */
|
||||
data->allowed_ap_list = nm_ap_list_new (NETWORK_TYPE_ALLOWED);
|
||||
@@ -594,12 +557,8 @@ static void nm_data_free (NMData *data)
|
||||
}
|
||||
|
||||
/* Stop and destroy all devices */
|
||||
nm_lock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
g_slist_foreach (data->dev_list, (GFunc) device_stop_and_free, NULL);
|
||||
g_slist_free (data->dev_list);
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
|
||||
g_mutex_free (data->dev_list_mutex);
|
||||
|
||||
nm_ap_list_unref (data->allowed_ap_list);
|
||||
nm_ap_list_unref (data->invalid_ap_list);
|
||||
@@ -612,8 +571,6 @@ static void nm_data_free (NMData *data)
|
||||
g_object_unref (data->named_manager);
|
||||
|
||||
g_main_loop_unref (data->main_loop);
|
||||
g_main_context_unref (data->main_context);
|
||||
|
||||
g_io_channel_unref(data->sigterm_iochannel);
|
||||
|
||||
nm_hal_deinit (data);
|
||||
@@ -821,7 +778,7 @@ main (int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Initialize our DBus service & connection */
|
||||
dbus_mgr = nm_dbus_manager_get (nm_data->main_context);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_error ("Failed to initialize. "
|
||||
@@ -861,7 +818,7 @@ main (int argc, char *argv[])
|
||||
goto done;
|
||||
}
|
||||
|
||||
nm_data->dhcp_manager = nm_dhcp_manager_new (nm_data, nm_data->main_context);
|
||||
nm_data->dhcp_manager = nm_dhcp_manager_new (nm_data);
|
||||
if (!nm_data->dhcp_manager) {
|
||||
nm_warning ("Failed to start the DHCP manager.");
|
||||
goto done;
|
||||
|
@@ -35,7 +35,6 @@ struct NMAccessPointList
|
||||
guint refcount;
|
||||
NMNetworkType type;
|
||||
GSList * ap_list;
|
||||
GMutex *mutex;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,16 +50,7 @@ NMAccessPointList *nm_ap_list_new (NMNetworkType type)
|
||||
|
||||
nm_ap_list_ref (list);
|
||||
list->type = type;
|
||||
list->mutex = g_mutex_new ();
|
||||
if (!list->mutex)
|
||||
{
|
||||
g_slice_free (NMAccessPointList, list);
|
||||
nm_warning ("nm_ap_list_new() could not create list mutex");
|
||||
return (NULL);
|
||||
}
|
||||
nm_register_mutex_desc (list->mutex, "AP List Mutex");
|
||||
|
||||
return (list);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,17 +94,9 @@ void nm_ap_list_unref (NMAccessPointList *list)
|
||||
return;
|
||||
|
||||
list->refcount--;
|
||||
if (list->refcount <= 0)
|
||||
{
|
||||
gboolean acquired = nm_try_acquire_mutex (list->mutex, __FUNCTION__);
|
||||
|
||||
if (list->refcount <= 0) {
|
||||
g_slist_foreach (list->ap_list, nm_ap_list_element_free, NULL);
|
||||
g_slist_free (list->ap_list);
|
||||
|
||||
if (acquired)
|
||||
nm_unlock_mutex (list->mutex, __FUNCTION__);
|
||||
|
||||
g_mutex_free (list->mutex);
|
||||
g_slice_free (NMAccessPointList, list);
|
||||
}
|
||||
}
|
||||
@@ -128,20 +110,9 @@ void nm_ap_list_unref (NMAccessPointList *list)
|
||||
*/
|
||||
guint nm_ap_list_size (NMAccessPointList *list)
|
||||
{
|
||||
guint size;
|
||||
|
||||
g_return_val_if_fail (list != NULL, 0);
|
||||
|
||||
if (!nm_ap_list_lock (list))
|
||||
{
|
||||
nm_warning ("nm_ap_list_size() could not acquire AP list mutex." );
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = g_slist_length (list->ap_list);
|
||||
nm_ap_list_unlock (list);
|
||||
|
||||
return size;
|
||||
return g_slist_length (list->ap_list);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,16 +140,8 @@ void nm_ap_list_append_ap (NMAccessPointList *list, NMAccessPoint *ap)
|
||||
g_return_if_fail (list != NULL);
|
||||
g_return_if_fail (ap != NULL);
|
||||
|
||||
if (!nm_ap_list_lock (list))
|
||||
{
|
||||
nm_warning ("nm_ap_list_append_ap() could not acquire AP list mutex." );
|
||||
return;
|
||||
}
|
||||
|
||||
nm_ap_ref (ap);
|
||||
list->ap_list = g_slist_append (list->ap_list, ap);
|
||||
|
||||
nm_ap_list_unlock (list);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,25 +158,16 @@ void nm_ap_list_remove_ap (NMAccessPointList *list, NMAccessPoint *ap)
|
||||
g_return_if_fail (list != NULL);
|
||||
g_return_if_fail (ap != NULL);
|
||||
|
||||
if (!nm_ap_list_lock (list))
|
||||
{
|
||||
nm_warning ("nm_ap_list_remove_ap() could not acquire AP list mutex." );
|
||||
return;
|
||||
}
|
||||
for (elt = list->ap_list; elt; elt = g_slist_next (elt)) {
|
||||
NMAccessPoint * list_ap = (NMAccessPoint *) elt->data;
|
||||
|
||||
for (elt = list->ap_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
NMAccessPoint *list_ap = (NMAccessPoint *)(elt->data);
|
||||
|
||||
if (list_ap == ap)
|
||||
{
|
||||
if (list_ap == ap) {
|
||||
list->ap_list = g_slist_remove_link (list->ap_list, elt);
|
||||
nm_ap_unref (list_ap);
|
||||
g_slist_free (elt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
nm_ap_list_unlock (list);
|
||||
}
|
||||
|
||||
|
||||
@@ -230,25 +184,16 @@ void nm_ap_list_remove_ap_by_essid (NMAccessPointList *list, const char *network
|
||||
g_return_if_fail (list != NULL);
|
||||
g_return_if_fail (network != NULL);
|
||||
|
||||
if (!nm_ap_list_lock (list))
|
||||
{
|
||||
nm_warning ("nm_ap_list_remove_ap_by_essid() could not acquire AP list mutex." );
|
||||
return;
|
||||
}
|
||||
for (elt = list->ap_list; elt; elt = g_slist_next (elt)) {
|
||||
NMAccessPoint * list_ap = (NMAccessPoint *) elt->data;
|
||||
|
||||
for (elt = list->ap_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
NMAccessPoint *list_ap = (NMAccessPoint *)(elt->data);
|
||||
|
||||
if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap), network) == 0)
|
||||
{
|
||||
if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap), network) == 0) {
|
||||
list->ap_list = g_slist_remove_link (list->ap_list, elt);
|
||||
nm_ap_unref (list_ap);
|
||||
g_slist_free (elt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
nm_ap_list_unlock (list);
|
||||
}
|
||||
|
||||
/* nm_ap_list_remove_duplicate_essids
|
||||
@@ -268,20 +213,12 @@ void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list)
|
||||
|
||||
g_return_if_fail (list != NULL);
|
||||
|
||||
if (!nm_ap_list_lock (list))
|
||||
{
|
||||
nm_warning ("nm_ap_list_append_ap() could not acquire AP list mutex." );
|
||||
return;
|
||||
}
|
||||
|
||||
for (elt_i = list->ap_list; elt_i; elt_i = g_slist_next (elt_i))
|
||||
{
|
||||
NMAccessPoint *list_ap_i = (NMAccessPoint *)(elt_i->data);
|
||||
for (elt_i = list->ap_list; elt_i; elt_i = g_slist_next (elt_i)) {
|
||||
NMAccessPoint * list_ap_i = (NMAccessPoint *) elt_i->data;
|
||||
gboolean found = FALSE;
|
||||
|
||||
for (elt_j = list->ap_list; elt_j < elt_i; elt_j = g_slist_next (elt_j))
|
||||
{
|
||||
NMAccessPoint *list_ap_j = (NMAccessPoint *)(elt_j->data);
|
||||
for (elt_j = list->ap_list; elt_j < elt_i; elt_j = g_slist_next (elt_j)) {
|
||||
NMAccessPoint *list_ap_j = (NMAccessPoint *) elt_j->data;
|
||||
|
||||
if ((found = (nm_null_safe_strcmp (nm_ap_get_essid (list_ap_i), nm_ap_get_essid (list_ap_j)) == 0)))
|
||||
break;
|
||||
@@ -294,33 +231,27 @@ void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list)
|
||||
list_ap_max = (NMAccessPoint *)(elt_i->data);
|
||||
max_strength = nm_ap_get_strength (list_ap_i);
|
||||
|
||||
for (elt_j = g_slist_next (elt_i); elt_j; elt_j = g_slist_next (elt_j))
|
||||
{
|
||||
NMAccessPoint *list_ap_j = (NMAccessPoint *)(elt_j->data);
|
||||
for (elt_j = g_slist_next (elt_i); elt_j; elt_j = g_slist_next (elt_j)) {
|
||||
NMAccessPoint *list_ap_j = (NMAccessPoint *) elt_j->data;
|
||||
|
||||
strengthj = nm_ap_get_strength (list_ap_j);
|
||||
if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap_i), nm_ap_get_essid (list_ap_j)) == 0)
|
||||
{
|
||||
if (strengthj > max_strength)
|
||||
{
|
||||
if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap_i), nm_ap_get_essid (list_ap_j)) == 0) {
|
||||
if (strengthj > max_strength) {
|
||||
removal_list = g_slist_append (removal_list, list_ap_max);
|
||||
list_ap_max = list_ap_j;
|
||||
max_strength = strengthj;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
removal_list = g_slist_append (removal_list, list_ap_j);
|
||||
}
|
||||
}
|
||||
}
|
||||
nm_ap_list_unlock (list);
|
||||
}
|
||||
|
||||
for (elt = removal_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
for (elt = removal_list; elt; elt = g_slist_next (elt)) {
|
||||
if ((removal_ap = (NMAccessPoint *)(elt->data)))
|
||||
nm_ap_list_remove_ap (list, removal_ap);
|
||||
}
|
||||
g_slist_free (removal_list);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -648,35 +579,6 @@ NMNetworkType nm_ap_list_get_type (NMAccessPointList *list)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_ap_list_lock
|
||||
*
|
||||
* Grab exclusive access to an access point list
|
||||
*
|
||||
*/
|
||||
gboolean nm_ap_list_lock (NMAccessPointList *list)
|
||||
{
|
||||
g_return_val_if_fail (list != NULL, FALSE);
|
||||
|
||||
return (nm_try_acquire_mutex (list->mutex, __FUNCTION__));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_ap_list_unlock
|
||||
*
|
||||
* Give up access to an access point list
|
||||
*
|
||||
*/
|
||||
void nm_ap_list_unlock (NMAccessPointList *list)
|
||||
{
|
||||
g_return_if_fail (list != NULL);
|
||||
|
||||
nm_unlock_mutex (list->mutex, __FUNCTION__);
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct NMAPListIter
|
||||
{
|
||||
NMAccessPointList * list;
|
||||
@@ -693,17 +595,11 @@ NMAPListIter * nm_ap_list_iter_new (NMAccessPointList *list)
|
||||
|
||||
iter = g_slice_new (NMAPListIter);
|
||||
|
||||
if (!nm_ap_list_lock (list))
|
||||
{
|
||||
g_slice_free (NMAPListIter, iter);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
iter->list = list;
|
||||
iter->cur_pos = list->ap_list;
|
||||
iter->valid = FALSE;
|
||||
|
||||
return (iter);
|
||||
return iter;
|
||||
}
|
||||
|
||||
|
||||
@@ -723,10 +619,9 @@ NMAccessPoint * nm_ap_list_iter_next (NMAPListIter *iter)
|
||||
{
|
||||
g_return_val_if_fail (iter != NULL, NULL);
|
||||
|
||||
if (iter->valid)
|
||||
if (iter->valid) {
|
||||
iter->cur_pos = g_slist_next (iter->cur_pos);
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iter->valid = TRUE;
|
||||
iter->cur_pos = iter->list->ap_list;
|
||||
}
|
||||
@@ -738,7 +633,6 @@ void nm_ap_list_iter_free (NMAPListIter *iter)
|
||||
{
|
||||
g_return_if_fail (iter != NULL);
|
||||
|
||||
nm_ap_list_unlock (iter->list);
|
||||
memset (iter, 0, sizeof (struct NMAPListIter));
|
||||
g_slice_free (NMAPListIter, iter);
|
||||
}
|
||||
|
@@ -55,9 +55,6 @@ gboolean nm_ap_list_merge_scanned_ap (NMDevice80211Wireless *dev, NMAccessPoi
|
||||
|
||||
NMNetworkType nm_ap_list_get_type (NMAccessPointList *list);
|
||||
|
||||
gboolean nm_ap_list_lock (NMAccessPointList *list);
|
||||
void nm_ap_list_unlock (NMAccessPointList *list);
|
||||
|
||||
NMAPListIter * nm_ap_list_iter_new (NMAccessPointList *list);
|
||||
NMAccessPoint * nm_ap_list_iter_get_ap (NMAPListIter *iter);
|
||||
NMAccessPoint * nm_ap_list_iter_next (NMAPListIter *iter);
|
||||
|
@@ -150,17 +150,13 @@ NMDevice *nm_dbus_get_device_from_escaped_object_path (NMData *data, const char
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
|
||||
if (!nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||
return NULL;
|
||||
|
||||
/* Iterate over the device list looking for the device with the matching object path. */
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {
|
||||
char *compare_path;
|
||||
char *escaped_compare_path;
|
||||
int len;
|
||||
|
||||
if (!(dev = (NMDevice *)(elt->data)))
|
||||
if (!(dev = NM_DEVICE (elt->data)))
|
||||
continue;
|
||||
|
||||
compare_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
|
||||
@@ -179,7 +175,6 @@ NMDevice *nm_dbus_get_device_from_escaped_object_path (NMData *data, const char
|
||||
g_free (escaped_compare_path);
|
||||
dev = NULL;
|
||||
}
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
|
||||
return dev;
|
||||
}
|
||||
@@ -237,7 +232,7 @@ nm_dbus_signal_device_status_change (gpointer user_data)
|
||||
g_return_val_if_fail (cb_data->data, FALSE);
|
||||
g_return_val_if_fail (cb_data->dev, FALSE);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("could not get the dbus connection.");
|
||||
@@ -286,6 +281,7 @@ void nm_dbus_schedule_device_status_change_signal (NMData *data, NMDevice *dev,
|
||||
{
|
||||
NMStatusChangeData * cb_data = NULL;
|
||||
GSource * source;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
g_return_if_fail (dev != NULL);
|
||||
@@ -294,18 +290,17 @@ void nm_dbus_schedule_device_status_change_signal (NMData *data, NMDevice *dev,
|
||||
g_object_ref (G_OBJECT (dev));
|
||||
cb_data->data = data;
|
||||
cb_data->dev = dev;
|
||||
if (ap)
|
||||
{
|
||||
if (ap) {
|
||||
nm_ap_ref (ap);
|
||||
cb_data->ap = ap;
|
||||
}
|
||||
cb_data->status = status;
|
||||
|
||||
source = g_idle_source_new ();
|
||||
id = g_idle_add (nm_dbus_signal_device_status_change, cb_data);
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
if (source) {
|
||||
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||
g_source_set_callback (source, nm_dbus_signal_device_status_change, cb_data, NULL);
|
||||
g_source_attach (source, data->main_context);
|
||||
g_source_unref (source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -386,7 +381,7 @@ nm_dbus_signal_wireless_network_change (NMDevice80211Wireless *dev,
|
||||
g_return_if_fail (dev != NULL);
|
||||
g_return_if_fail (ap != NULL);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("could not get the dbus connection.");
|
||||
@@ -455,7 +450,7 @@ nm_dbus_signal_device_strength_change (NMDevice80211Wireless *dev,
|
||||
|
||||
g_return_if_fail (dev != NULL);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("could not get the dbus connection.");
|
||||
|
@@ -72,21 +72,18 @@ typedef struct NMData
|
||||
NMDbusMethodList * device_methods;
|
||||
NMDbusMethodList * net_methods;
|
||||
|
||||
GMainContext * main_context;
|
||||
GMainLoop * main_loop;
|
||||
gboolean enable_test_devices;
|
||||
|
||||
guint dev_change_check_idle_id;
|
||||
|
||||
GSList * dev_list;
|
||||
GMutex * dev_list_mutex;
|
||||
|
||||
gboolean wireless_enabled;
|
||||
gboolean modem_active;
|
||||
gboolean asleep;
|
||||
|
||||
GSList * dialup_list;
|
||||
GMutex * dialup_list_mutex;
|
||||
|
||||
struct NMAccessPointList *allowed_ap_list;
|
||||
struct NMAccessPointList *invalid_ap_list;
|
||||
|
@@ -41,9 +41,6 @@
|
||||
#include "nm-dbus-manager.h"
|
||||
|
||||
|
||||
static GStaticMutex dev_change_mutex = G_STATIC_MUTEX_INIT;
|
||||
|
||||
|
||||
/*
|
||||
* nm_policy_activation_finish
|
||||
*
|
||||
@@ -51,8 +48,9 @@ static GStaticMutex dev_change_mutex = G_STATIC_MUTEX_INIT;
|
||||
* on the main thread.
|
||||
*
|
||||
*/
|
||||
static gboolean nm_policy_activation_finish (NMActRequest *req)
|
||||
static gboolean nm_policy_activation_finish (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMDevice * dev = NULL;
|
||||
NMData * data = NULL;
|
||||
NMAccessPoint * ap = NULL;
|
||||
@@ -85,25 +83,23 @@ static gboolean nm_policy_activation_finish (NMActRequest *req)
|
||||
void nm_policy_schedule_activation_finish (NMActRequest *req)
|
||||
{
|
||||
GSource * source;
|
||||
NMData * data;
|
||||
NMDevice * dev;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
data = nm_act_request_get_data (req);
|
||||
g_assert (data);
|
||||
|
||||
dev = nm_act_request_get_dev (req);
|
||||
g_assert (dev);
|
||||
|
||||
nm_act_request_set_stage (req, NM_ACT_STAGE_ACTIVATED);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
id = g_idle_add (nm_policy_activation_finish, req);
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
if (source) {
|
||||
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||
g_source_set_callback (source, (GSourceFunc) nm_policy_activation_finish, req, NULL);
|
||||
g_source_attach (source, data->main_context);
|
||||
g_source_unref (source);
|
||||
nm_info ("Activation (%s) Finish handler scheduled.", nm_device_get_iface (dev));
|
||||
}
|
||||
|
||||
nm_info ("Activation (%s) Finish handler scheduled.",
|
||||
nm_device_get_iface (dev));
|
||||
}
|
||||
|
||||
|
||||
@@ -113,8 +109,9 @@ void nm_policy_schedule_activation_finish (NMActRequest *req)
|
||||
* Clean up a failed activation.
|
||||
*
|
||||
*/
|
||||
static gboolean nm_policy_activation_failed (NMActRequest *req)
|
||||
static gboolean nm_policy_activation_failed (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMDevice * dev = NULL;
|
||||
NMData * data = NULL;
|
||||
NMAccessPoint * ap = NULL;
|
||||
@@ -150,24 +147,21 @@ static gboolean nm_policy_activation_failed (NMActRequest *req)
|
||||
void nm_policy_schedule_activation_failed (NMActRequest *req)
|
||||
{
|
||||
GSource * source;
|
||||
NMData * data;
|
||||
NMDevice * dev;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
data = nm_act_request_get_data (req);
|
||||
g_assert (data);
|
||||
|
||||
dev = nm_act_request_get_dev (req);
|
||||
g_assert (dev);
|
||||
|
||||
nm_act_request_set_stage (req, NM_ACT_STAGE_FAILED);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
id = g_idle_add (nm_policy_activation_failed, req);
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
if (source) {
|
||||
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||
g_source_set_callback (source, (GSourceFunc) nm_policy_activation_failed, req, NULL);
|
||||
g_source_attach (source, data->main_context);
|
||||
g_source_unref (source);
|
||||
}
|
||||
|
||||
nm_info ("Activation (%s) failure scheduled...", nm_device_get_iface (dev));
|
||||
}
|
||||
|
||||
@@ -288,8 +282,9 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_policy_device_change_check (NMData *data)
|
||||
nm_policy_device_change_check (gpointer user_data)
|
||||
{
|
||||
NMData * data = (NMData *) user_data;
|
||||
NMAccessPoint * ap = NULL;
|
||||
NMDevice * new_dev = NULL;
|
||||
NMDevice * old_dev = NULL;
|
||||
@@ -297,23 +292,16 @@ nm_policy_device_change_check (NMData *data)
|
||||
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
|
||||
g_static_mutex_lock (&dev_change_mutex);
|
||||
data->dev_change_check_idle_id = 0;
|
||||
g_static_mutex_unlock (&dev_change_mutex);
|
||||
|
||||
old_dev = nm_get_active_device (data);
|
||||
|
||||
if (!nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||
return FALSE;
|
||||
|
||||
if (old_dev)
|
||||
{
|
||||
if (old_dev) {
|
||||
guint32 caps = nm_device_get_capabilities (old_dev);
|
||||
|
||||
/* Don't interrupt a currently activating device. */
|
||||
if ( nm_device_is_activating (old_dev)
|
||||
&& !nm_device_can_interrupt_activation (old_dev))
|
||||
{
|
||||
&& !nm_device_can_interrupt_activation (old_dev)) {
|
||||
nm_info ("Old device '%s' activating, won't change.", nm_device_get_iface (old_dev));
|
||||
goto out;
|
||||
}
|
||||
@@ -322,8 +310,7 @@ nm_policy_device_change_check (NMData *data)
|
||||
* explicitly choose to move to another device, we're not going to move for them.
|
||||
*/
|
||||
if ((nm_device_is_802_3_ethernet (old_dev) && !(caps & NM_DEVICE_CAP_CARRIER_DETECT))
|
||||
|| (nm_device_is_802_11_wireless (old_dev) && !(caps & NM_DEVICE_CAP_WIRELESS_SCAN)))
|
||||
{
|
||||
|| (nm_device_is_802_11_wireless (old_dev) && !(caps & NM_DEVICE_CAP_WIRELESS_SCAN))) {
|
||||
nm_info ("Old device '%s' was semi-supported and user chosen, won't change unless told to.",
|
||||
nm_device_get_iface (old_dev));
|
||||
goto out;
|
||||
@@ -350,46 +337,37 @@ nm_policy_device_change_check (NMData *data)
|
||||
* c) same device, same access point? do nothing
|
||||
*/
|
||||
|
||||
if (!old_dev && !new_dev)
|
||||
{
|
||||
if (!old_dev && !new_dev) {
|
||||
; /* Do nothing, wait for something like link-state to change, or an access point to be found */
|
||||
}
|
||||
else if (!old_dev && new_dev)
|
||||
{
|
||||
} else if (!old_dev && new_dev) {
|
||||
/* Activate new device */
|
||||
nm_info ("SWITCH: no current connection, found better connection '%s'.", nm_device_get_iface (new_dev));
|
||||
do_switch = TRUE;
|
||||
}
|
||||
else if (old_dev && !new_dev)
|
||||
{
|
||||
} else if (old_dev && !new_dev) {
|
||||
/* Terminate current connection */
|
||||
nm_info ("SWITCH: terminating current connection '%s' because it's no longer valid.", nm_device_get_iface (old_dev));
|
||||
nm_device_deactivate (old_dev);
|
||||
do_switch = TRUE;
|
||||
}
|
||||
else if (old_dev && new_dev)
|
||||
{
|
||||
} else if (old_dev && new_dev) {
|
||||
NMActRequest * old_act_req = nm_device_get_act_request (old_dev);
|
||||
gboolean old_user_requested = nm_act_request_get_user_requested (old_act_req);
|
||||
gboolean old_has_link = nm_device_has_active_link (old_dev);
|
||||
|
||||
if (nm_device_is_802_3_ethernet (old_dev))
|
||||
{
|
||||
if (nm_device_is_802_3_ethernet (old_dev)) {
|
||||
/* Only switch if the old device was not user requested, and we are switching to
|
||||
* a new device. Note that new_dev will never be wireless since automatic device picking
|
||||
* above will prefer a wired device to a wireless device.
|
||||
*/
|
||||
if ((!old_user_requested || !old_has_link) && (new_dev != old_dev))
|
||||
{
|
||||
nm_info ("SWITCH: found better connection '%s' than current connection '%s'.", nm_device_get_iface (new_dev), nm_device_get_iface (old_dev));
|
||||
if ((!old_user_requested || !old_has_link) && (new_dev != old_dev)) {
|
||||
nm_info ("SWITCH: found better connection '%s' than current "
|
||||
"connection '%s'.",
|
||||
nm_device_get_iface (new_dev),
|
||||
nm_device_get_iface (old_dev));
|
||||
do_switch = TRUE;
|
||||
}
|
||||
}
|
||||
else if (nm_device_is_802_11_wireless (old_dev))
|
||||
{
|
||||
} else if (nm_device_is_802_11_wireless (old_dev)) {
|
||||
/* Only switch if the old device's wireless config is invalid */
|
||||
if (nm_device_is_802_11_wireless (new_dev))
|
||||
{
|
||||
if (nm_device_is_802_11_wireless (new_dev)) {
|
||||
NMAccessPoint *old_ap = nm_act_request_get_ap (old_act_req);
|
||||
const char * old_essid = nm_ap_get_essid (old_ap);
|
||||
int old_mode = nm_ap_get_mode (old_ap);
|
||||
@@ -411,8 +389,7 @@ nm_policy_device_change_check (NMData *data)
|
||||
if ((old_dev == new_dev) && nm_device_is_activating (new_dev) && same_essid)
|
||||
same_request = TRUE;
|
||||
|
||||
if (!same_request && (!same_essid || !old_has_link) && (old_mode != IW_MODE_ADHOC))
|
||||
{
|
||||
if (!same_request && (!same_essid || !old_has_link) && (old_mode != IW_MODE_ADHOC)) {
|
||||
nm_info ("SWITCH: found better connection '%s/%s'"
|
||||
" than current connection '%s/%s'. "
|
||||
"same_ssid=%d, have_link=%d",
|
||||
@@ -421,21 +398,18 @@ nm_policy_device_change_check (NMData *data)
|
||||
same_essid, old_has_link);
|
||||
do_switch = TRUE;
|
||||
}
|
||||
} /* Always prefer Ethernet over wireless, unless the user explicitly switched away. */
|
||||
else if (nm_device_is_802_3_ethernet (new_dev))
|
||||
{
|
||||
} else if (nm_device_is_802_3_ethernet (new_dev)) {
|
||||
/* Always prefer Ethernet over wireless, unless the user explicitly switched away. */
|
||||
if (!old_user_requested)
|
||||
do_switch = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (do_switch && (nm_device_is_802_3_ethernet (new_dev) || (nm_device_is_802_11_wireless (new_dev) && ap)))
|
||||
{
|
||||
if (do_switch && (nm_device_is_802_3_ethernet (new_dev) || (nm_device_is_802_11_wireless (new_dev) && ap))) {
|
||||
NMActRequest * act_req = NULL;
|
||||
|
||||
if ((act_req = nm_act_request_new (data, new_dev, ap, FALSE)))
|
||||
{
|
||||
if ((act_req = nm_act_request_new (data, new_dev, ap, FALSE))) {
|
||||
nm_info ("Will activate connection '%s%s%s'.", nm_device_get_iface (new_dev), ap ? "/" : "", ap ? nm_ap_get_essid (ap) : "");
|
||||
nm_policy_schedule_device_activation (act_req);
|
||||
}
|
||||
@@ -445,7 +419,6 @@ nm_policy_device_change_check (NMData *data)
|
||||
nm_ap_unref (ap);
|
||||
|
||||
out:
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -459,19 +432,15 @@ out:
|
||||
*/
|
||||
void nm_policy_schedule_device_change_check (NMData *data)
|
||||
{
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
g_static_mutex_lock (&dev_change_mutex);
|
||||
if (data->dev_change_check_idle_id > 0)
|
||||
return;
|
||||
|
||||
if (data->dev_change_check_idle_id == 0) {
|
||||
GSource * source = g_idle_source_new ();
|
||||
|
||||
g_source_set_callback (source, (GSourceFunc) nm_policy_device_change_check, data, NULL);
|
||||
data->dev_change_check_idle_id = g_source_attach (source, data->main_context);
|
||||
g_source_unref (source);
|
||||
}
|
||||
|
||||
g_static_mutex_unlock (&dev_change_mutex);
|
||||
id = g_idle_add (nm_policy_device_change_check, data);
|
||||
data->dev_change_check_idle_id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -482,8 +451,10 @@ void nm_policy_schedule_device_change_check (NMData *data)
|
||||
* activation on the requested device.
|
||||
*
|
||||
*/
|
||||
static gboolean nm_policy_device_activation (NMActRequest *req)
|
||||
static gboolean
|
||||
nm_policy_device_activation (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMData * data;
|
||||
NMDevice * new_dev = NULL;
|
||||
NMDevice * old_dev = NULL;
|
||||
@@ -512,30 +483,29 @@ static gboolean nm_policy_device_activation (NMActRequest *req)
|
||||
* Activate a particular device (and possibly access point)
|
||||
*
|
||||
*/
|
||||
void nm_policy_schedule_device_activation (NMActRequest *req)
|
||||
void
|
||||
nm_policy_schedule_device_activation (NMActRequest * req)
|
||||
{
|
||||
GSource * source;
|
||||
NMData * data;
|
||||
NMDevice * dev;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
data = nm_act_request_get_data (req);
|
||||
g_assert (data);
|
||||
|
||||
dev = nm_act_request_get_dev (req);
|
||||
g_assert (dev);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
id = g_idle_add (nm_policy_device_activation, req);
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
if (source) {
|
||||
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||
g_source_set_callback (source, (GSourceFunc) nm_policy_device_activation, req, NULL);
|
||||
g_source_attach (source, data->main_context);
|
||||
g_source_unref (source);
|
||||
}
|
||||
|
||||
nm_info ("Device %s activation scheduled...", nm_device_get_iface (dev));
|
||||
}
|
||||
|
||||
|
||||
static gboolean allowed_list_update_pending = FALSE;
|
||||
static guint allowed_list_update_id = 0;
|
||||
|
||||
/*
|
||||
* nm_policy_allowed_ap_list_update
|
||||
@@ -549,7 +519,7 @@ nm_policy_allowed_ap_list_update (gpointer user_data)
|
||||
{
|
||||
NMData * data = (NMData *)user_data;
|
||||
|
||||
allowed_list_update_pending = FALSE;
|
||||
allowed_list_update_id = 0;
|
||||
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
|
||||
@@ -572,30 +542,24 @@ nm_policy_allowed_ap_list_update (gpointer user_data)
|
||||
*/
|
||||
void nm_policy_schedule_allowed_ap_list_update (NMData *app_data)
|
||||
{
|
||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||
GSource * source;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (app_data != NULL);
|
||||
g_return_if_fail (app_data->main_context != NULL);
|
||||
|
||||
g_static_mutex_lock (&mutex);
|
||||
if (allowed_list_update_id > 0)
|
||||
return;
|
||||
|
||||
if (allowed_list_update_pending == FALSE)
|
||||
{
|
||||
GSource *source = g_idle_source_new ();
|
||||
/* We want this idle source to run before any other idle source */
|
||||
id = g_idle_add (nm_policy_allowed_ap_list_update, app_data);
|
||||
allowed_list_update_id = id;
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
if (source) {
|
||||
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||
g_source_set_callback (source, nm_policy_allowed_ap_list_update, app_data, NULL);
|
||||
g_source_attach (source, app_data->main_context);
|
||||
g_source_unref (source);
|
||||
|
||||
allowed_list_update_pending = TRUE;
|
||||
}
|
||||
|
||||
g_static_mutex_unlock (&mutex);
|
||||
}
|
||||
|
||||
|
||||
static gboolean device_list_update_pending = FALSE;
|
||||
static gboolean device_list_update_id = 0;
|
||||
|
||||
/*
|
||||
* nm_policy_device_list_update_from_allowed_list
|
||||
@@ -605,11 +569,12 @@ static gboolean device_list_update_pending = FALSE;
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_policy_device_list_update_from_allowed_list (NMData *data)
|
||||
nm_policy_device_list_update_from_allowed_list (gpointer user_data)
|
||||
{
|
||||
NMData * data = (NMData *) user_data;
|
||||
GSList * elt;
|
||||
|
||||
device_list_update_pending = FALSE;
|
||||
device_list_update_id = 0;
|
||||
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
|
||||
@@ -652,27 +617,21 @@ nm_policy_device_list_update_from_allowed_list (NMData *data)
|
||||
* the allowed list, in the main thread.
|
||||
*
|
||||
*/
|
||||
void nm_policy_schedule_device_ap_lists_update_from_allowed (NMData *app_data)
|
||||
void
|
||||
nm_policy_schedule_device_ap_lists_update_from_allowed (NMData *app_data)
|
||||
{
|
||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||
GSource * source;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (app_data != NULL);
|
||||
g_return_if_fail (app_data->main_context != NULL);
|
||||
|
||||
g_static_mutex_lock (&mutex);
|
||||
if (device_list_update_id > 0)
|
||||
return;
|
||||
|
||||
if (device_list_update_pending == FALSE)
|
||||
{
|
||||
GSource *source = g_idle_source_new ();
|
||||
|
||||
/* We want this idle source to run before any other idle source */
|
||||
id = g_idle_add (nm_policy_device_list_update_from_allowed_list, app_data);
|
||||
device_list_update_id = id;
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
if (source) {
|
||||
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||
g_source_set_callback (source, (GSourceFunc) nm_policy_device_list_update_from_allowed_list, app_data, NULL);
|
||||
g_source_attach (source, app_data->main_context);
|
||||
g_source_unref (source);
|
||||
|
||||
device_list_update_pending = TRUE;
|
||||
}
|
||||
|
||||
g_static_mutex_unlock (&mutex);
|
||||
}
|
||||
|
@@ -157,17 +157,14 @@ static gboolean nm_system_device_set_ip4_route (NMDevice *dev, int ip4_gateway,
|
||||
|
||||
static struct nl_cache * get_link_cache (struct nl_handle *nlh)
|
||||
{
|
||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||
static struct nl_cache * link_cache = NULL;
|
||||
|
||||
g_static_mutex_lock (&mutex);
|
||||
if (!link_cache)
|
||||
link_cache = rtnl_link_alloc_cache (nlh);
|
||||
if (!link_cache)
|
||||
nm_warning ("couldn't allocate rtnl link cache!");
|
||||
else
|
||||
nl_cache_update (nlh, link_cache);
|
||||
g_static_mutex_unlock (&mutex);
|
||||
|
||||
return link_cache;
|
||||
}
|
||||
|
@@ -53,126 +53,6 @@ struct NMSock
|
||||
};
|
||||
|
||||
static GSList * sock_list = NULL;
|
||||
static GStaticMutex sock_list_mutex = G_STATIC_MUTEX_INIT;
|
||||
|
||||
typedef struct MutexDesc
|
||||
{
|
||||
GMutex *mutex;
|
||||
char *desc;
|
||||
} MutexDesc;
|
||||
|
||||
GSList *mutex_descs = NULL;
|
||||
|
||||
/*#define LOCKING_DEBUG*/
|
||||
|
||||
|
||||
static MutexDesc *nm_find_mutex_desc (GMutex *mutex)
|
||||
{
|
||||
GSList *elt;
|
||||
|
||||
for (elt = mutex_descs; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
MutexDesc *desc = (MutexDesc *)(elt->data);
|
||||
if (desc && (desc->mutex == mutex))
|
||||
return desc;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_register_mutex_desc
|
||||
*
|
||||
* Associate a description with a particular mutex.
|
||||
*
|
||||
*/
|
||||
void nm_register_mutex_desc (GMutex *mutex, const char *string)
|
||||
{
|
||||
if (!(nm_find_mutex_desc (mutex)))
|
||||
{
|
||||
MutexDesc *desc = g_malloc0 (sizeof (MutexDesc));
|
||||
desc->mutex = mutex;
|
||||
desc->desc = g_strdup (string);
|
||||
mutex_descs = g_slist_append (mutex_descs, desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_try_acquire_mutex
|
||||
*
|
||||
* Tries to acquire a given mutex, sleeping a bit between tries.
|
||||
*
|
||||
* Returns: FALSE if mutex was not acquired
|
||||
* TRUE if mutex was successfully acquired
|
||||
*/
|
||||
gboolean nm_try_acquire_mutex (GMutex *mutex, const char *func)
|
||||
{
|
||||
g_return_val_if_fail (mutex != NULL, FALSE);
|
||||
|
||||
if (g_mutex_trylock (mutex))
|
||||
{
|
||||
#ifdef LOCKING_DEBUG
|
||||
if (func)
|
||||
{
|
||||
MutexDesc *desc = nm_find_mutex_desc (mutex);
|
||||
nm_debug ("MUTEX: <%s %p> acquired by %s", desc ? desc->desc : "(none)", mutex, func);
|
||||
}
|
||||
#endif
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
#ifdef LOCKING_DEBUG
|
||||
if (func)
|
||||
{
|
||||
MutexDesc *desc = nm_find_mutex_desc (mutex);
|
||||
nm_debug ("MUTEX: <%s %p> FAILED to be acquired by %s", desc ? desc->desc : "(none)", mutex, func);
|
||||
}
|
||||
#endif
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_lock_mutex
|
||||
*
|
||||
* Blocks until a mutex is grabbed, with debugging.
|
||||
*
|
||||
*/
|
||||
void nm_lock_mutex (GMutex *mutex, const char *func)
|
||||
{
|
||||
#ifdef LOCKING_DEBUG
|
||||
if (func)
|
||||
{
|
||||
MutexDesc *desc = nm_find_mutex_desc (mutex);
|
||||
nm_debug ("MUTEX: <%s %p> being acquired by %s", desc ? desc->desc : "(none)", mutex, func);
|
||||
}
|
||||
#endif
|
||||
g_mutex_lock (mutex);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_unlock_mutex
|
||||
*
|
||||
* Simply unlocks a mutex, balances nm_try_acquire_mutex()
|
||||
*
|
||||
*/
|
||||
void nm_unlock_mutex (GMutex *mutex, const char *func)
|
||||
{
|
||||
g_return_if_fail (mutex != NULL);
|
||||
|
||||
#ifdef LOCKING_DEBUG
|
||||
if (func)
|
||||
{
|
||||
MutexDesc *desc = nm_find_mutex_desc (mutex);
|
||||
nm_debug ("MUTEX: <%s %p> released by %s", desc ? desc->desc : "(none)", mutex, func);
|
||||
}
|
||||
#endif
|
||||
|
||||
g_mutex_unlock (mutex);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@@ -223,9 +103,7 @@ NMSock *nm_dev_sock_open (NMDevice *dev, SockType type, const char *func_name, c
|
||||
g_object_ref (G_OBJECT (sock->dev));
|
||||
|
||||
/* Add the sock to our global sock list for tracking */
|
||||
g_static_mutex_lock (&sock_list_mutex);
|
||||
sock_list = g_slist_append (sock_list, sock);
|
||||
g_static_mutex_unlock (&sock_list_mutex);
|
||||
|
||||
return sock;
|
||||
}
|
||||
@@ -251,18 +129,14 @@ void nm_dev_sock_close (NMSock *sock)
|
||||
|
||||
memset (sock, 0, sizeof (NMSock));
|
||||
|
||||
g_static_mutex_lock (&sock_list_mutex);
|
||||
for (elt = sock_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
for (elt = sock_list; elt; elt = g_slist_next (elt)) {
|
||||
NMSock *temp_sock = (NMSock *)(elt->data);
|
||||
if (temp_sock == sock)
|
||||
{
|
||||
if (temp_sock == sock) {
|
||||
sock_list = g_slist_remove_link (sock_list, elt);
|
||||
g_slist_free (elt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_static_mutex_unlock (&sock_list_mutex);
|
||||
|
||||
g_free (sock);
|
||||
}
|
||||
@@ -294,18 +168,14 @@ void nm_print_open_socks (void)
|
||||
int i = 0;
|
||||
|
||||
nm_debug ("Open Sockets List:");
|
||||
g_static_mutex_lock (&sock_list_mutex);
|
||||
for (elt = sock_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
for (elt = sock_list; elt; elt = g_slist_next (elt)) {
|
||||
NMSock *sock = (NMSock *)(elt->data);
|
||||
if (sock)
|
||||
{
|
||||
if (sock) {
|
||||
i++;
|
||||
nm_debug (" %d: %s fd:%d F:'%s' D:'%s'", i, sock->dev ? nm_device_get_iface (sock->dev) : "",
|
||||
sock->fd, sock->func, sock->desc);
|
||||
}
|
||||
}
|
||||
g_static_mutex_unlock (&sock_list_mutex);
|
||||
nm_debug ("Open Sockets List Done.");
|
||||
}
|
||||
|
||||
|
@@ -44,11 +44,6 @@ typedef enum SockType
|
||||
typedef struct NMSock NMSock;
|
||||
|
||||
|
||||
gboolean nm_try_acquire_mutex (GMutex *mutex, const char *func);
|
||||
void nm_lock_mutex (GMutex *mutex, const char *func);
|
||||
void nm_unlock_mutex (GMutex *mutex, const char *func);
|
||||
void nm_register_mutex_desc (GMutex *mutex, const char *string);
|
||||
|
||||
NMSock * nm_dev_sock_open (NMDevice *dev, SockType type, const char *func_name, const char *desc);
|
||||
void nm_dev_sock_close (NMSock *sock);
|
||||
int nm_dev_sock_get_fd (NMSock *sock);
|
||||
|
@@ -54,7 +54,6 @@ static void nm_dhcp_manager_dbus_connection_changed (NMDBusManager *dbus_mgr,
|
||||
|
||||
struct NMDHCPManager {
|
||||
NMData * data;
|
||||
GMainContext * main_ctx;
|
||||
gboolean running;
|
||||
size_t dhcp_sn_len;
|
||||
NMDBusManager * dbus_mgr;
|
||||
@@ -87,19 +86,16 @@ static gboolean state_is_down (guint8 state)
|
||||
|
||||
|
||||
NMDHCPManager *
|
||||
nm_dhcp_manager_new (NMData *data,
|
||||
GMainContext *main_ctx)
|
||||
nm_dhcp_manager_new (NMData *data)
|
||||
{
|
||||
NMDHCPManager * manager;
|
||||
guint32 id;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
g_return_val_if_fail (main_ctx != NULL, NULL);
|
||||
|
||||
manager = g_slice_new0 (NMDHCPManager);
|
||||
manager->data = data;
|
||||
manager->main_ctx = main_ctx;
|
||||
manager->dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
manager->dbus_mgr = nm_dbus_manager_get ();
|
||||
manager->running = nm_dbus_manager_name_has_owner (manager->dbus_mgr,
|
||||
DHCP_SERVICE_NAME);
|
||||
manager->dhcp_sn_len = strlen (DHCP_SERVICE_NAME);
|
||||
@@ -206,8 +202,9 @@ out:
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_dhcp_manager_handle_timeout (NMActRequest *req)
|
||||
nm_dhcp_manager_handle_timeout (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMData * data;
|
||||
NMDevice * dev;
|
||||
|
||||
@@ -245,9 +242,9 @@ nm_dhcp_manager_begin_transaction (NMDHCPManager *manager,
|
||||
char * path;
|
||||
const guint32 opt1 = 31; /* turns off ALL actions and dhclient-script just writes options to dhcdbd */
|
||||
const guint32 opt2 = 2; /* dhclient is run in ONE SHOT mode and releases existing leases when brought down */
|
||||
GSource * source;
|
||||
DBusConnection * dbus_connection;
|
||||
gboolean success = FALSE;
|
||||
guint id;
|
||||
|
||||
g_return_val_if_fail (manager != NULL, FALSE);
|
||||
g_return_val_if_fail (req != NULL, FALSE);
|
||||
@@ -304,13 +301,10 @@ nm_dhcp_manager_begin_transaction (NMDHCPManager *manager,
|
||||
}
|
||||
|
||||
/* Set up a timeout on the transaction to kill it after NM_DHCP_TIMEOUT seconds */
|
||||
source = g_timeout_source_new (NM_DHCP_TIMEOUT * 1000);
|
||||
g_source_set_callback (source,
|
||||
(GSourceFunc) nm_dhcp_manager_handle_timeout,
|
||||
req,
|
||||
NULL);
|
||||
nm_act_request_set_dhcp_timeout (req, g_source_attach (source, manager->main_ctx));
|
||||
g_source_unref (source);
|
||||
id = g_timeout_add (NM_DHCP_TIMEOUT * 1000,
|
||||
nm_dhcp_manager_handle_timeout,
|
||||
req);
|
||||
nm_act_request_set_dhcp_timeout (req, id);
|
||||
success = TRUE;
|
||||
|
||||
out:
|
||||
@@ -328,9 +322,8 @@ remove_timeout (NMDHCPManager *manager, NMActRequest *req)
|
||||
|
||||
/* Remove any pending timeouts on the request */
|
||||
if ((id = nm_act_request_get_dhcp_timeout (req)) > 0) {
|
||||
GSource * source = g_main_context_find_source_by_id (manager->main_ctx, id);
|
||||
g_source_remove (id);
|
||||
nm_act_request_set_dhcp_timeout (req, 0);
|
||||
g_source_destroy (source);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ enum dhcdbd_state
|
||||
DHCDBD_END_OPTIONS, /* last option in subscription sent */
|
||||
};
|
||||
|
||||
NMDHCPManager * nm_dhcp_manager_new (NMData *data, GMainContext *main_ctx);
|
||||
NMDHCPManager * nm_dhcp_manager_new (NMData *data);
|
||||
void nm_dhcp_manager_dispose (NMDHCPManager *manager);
|
||||
|
||||
gboolean nm_dhcp_manager_begin_transaction (NMDHCPManager *manager, NMActRequest *req);
|
||||
|
@@ -706,7 +706,7 @@ nm_named_manager_init (NMNamedManager *mgr)
|
||||
{
|
||||
mgr->priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
|
||||
mgr->priv->use_named = FALSE;
|
||||
mgr->priv->dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
mgr->priv->dbus_mgr = nm_dbus_manager_get ();
|
||||
g_signal_connect (G_OBJECT (mgr->priv->dbus_mgr),
|
||||
"name-owner-changed",
|
||||
G_CALLBACK (nm_named_manager_name_owner_changed),
|
||||
|
@@ -89,17 +89,13 @@ void nm_act_request_unref (NMActRequest *req)
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
req->refcount--;
|
||||
if (req->refcount <= 0)
|
||||
{
|
||||
if (req->refcount <= 0) {
|
||||
g_object_unref (G_OBJECT (req->dev));
|
||||
if (req->ap)
|
||||
nm_ap_unref (req->ap);
|
||||
|
||||
if (req->dhcp_timeout > 0)
|
||||
{
|
||||
GSource * source = g_main_context_find_source_by_id (req->data->main_context, req->dhcp_timeout);
|
||||
g_source_destroy (source);
|
||||
}
|
||||
g_source_remove (req->dhcp_timeout);
|
||||
|
||||
memset (req, 0, sizeof (NMActRequest));
|
||||
g_free (req);
|
||||
@@ -182,7 +178,7 @@ void nm_act_request_set_stage (NMActRequest *req, NMActStage stage)
|
||||
g_return_if_fail (req->data);
|
||||
g_return_if_fail (req->dev);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("couldn't get the dbus connection.");
|
||||
|
@@ -32,7 +32,6 @@
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_MAIN_CONTEXT,
|
||||
PROP_DBUS_CONNECTION
|
||||
};
|
||||
|
||||
@@ -74,7 +73,6 @@ typedef struct MethodHandlerData {
|
||||
|
||||
struct _NMDBusManagerPrivate {
|
||||
DBusConnection * connection;
|
||||
GMainContext * main_ctx;
|
||||
gboolean started;
|
||||
|
||||
GSList * msg_handlers;
|
||||
@@ -96,25 +94,17 @@ static void signal_match_disable (SignalMatch * match);
|
||||
|
||||
|
||||
NMDBusManager *
|
||||
nm_dbus_manager_get (GMainContext *ctx)
|
||||
nm_dbus_manager_get (void)
|
||||
{
|
||||
static NMDBusManager *singleton = NULL;
|
||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||
|
||||
/* Ensure that if singleton is NULL, that ctx is non-NULL */
|
||||
g_return_val_if_fail (singleton ? TRUE : (ctx ? TRUE : FALSE), NULL);
|
||||
|
||||
g_static_mutex_lock (&mutex);
|
||||
if (!singleton) {
|
||||
singleton = NM_DBUS_MANAGER (g_object_new (NM_TYPE_DBUS_MANAGER,
|
||||
"main-context", ctx,
|
||||
NULL));
|
||||
singleton = NM_DBUS_MANAGER (g_object_new (NM_TYPE_DBUS_MANAGER, NULL));
|
||||
if (!nm_dbus_manager_init_bus (singleton))
|
||||
start_reconnection_timeout (singleton);
|
||||
} else {
|
||||
g_object_ref (singleton);
|
||||
}
|
||||
g_static_mutex_unlock (&mutex);
|
||||
|
||||
g_assert (singleton);
|
||||
return singleton;
|
||||
@@ -135,14 +125,6 @@ nm_dbus_manager_set_property (GObject *object,
|
||||
NMDBusManager *self = NM_DBUS_MANAGER (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_MAIN_CONTEXT:
|
||||
if (!self->priv->main_ctx) {
|
||||
self->priv->main_ctx = g_value_get_pointer (value);
|
||||
g_main_context_ref (self->priv->main_ctx);
|
||||
} else {
|
||||
nm_warning ("already have a valid main context.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -224,7 +206,6 @@ nm_dbus_manager_finalize (GObject *object)
|
||||
self->priv->matches = NULL;
|
||||
|
||||
nm_dbus_manager_cleanup (self);
|
||||
g_main_context_unref (self->priv->main_ctx);
|
||||
|
||||
g_slist_foreach (self->priv->msg_handlers, cleanup_handler_data, NULL);
|
||||
g_slist_free (self->priv->msg_handlers);
|
||||
@@ -243,14 +224,6 @@ nm_dbus_manager_class_init (NMDBusManagerClass *klass)
|
||||
object_class->get_property = nm_dbus_manager_get_property;
|
||||
object_class->set_property = nm_dbus_manager_set_property;
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_MAIN_CONTEXT,
|
||||
g_param_spec_pointer ("main-context",
|
||||
"GMainContext",
|
||||
"The mainloop context.",
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)
|
||||
);
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_DBUS_CONNECTION,
|
||||
g_param_spec_pointer ("dbus-connection",
|
||||
@@ -499,16 +472,8 @@ signal_match_disable (SignalMatch * match)
|
||||
static void
|
||||
start_reconnection_timeout (NMDBusManager *self)
|
||||
{
|
||||
GSource * source;
|
||||
|
||||
/* Schedule timeout for reconnection attempts */
|
||||
source = g_timeout_source_new (3000);
|
||||
g_source_set_callback (source,
|
||||
(GSourceFunc) nm_dbus_manager_reconnect,
|
||||
self,
|
||||
NULL);
|
||||
g_source_attach (source, self->priv->main_ctx);
|
||||
g_source_unref (source);
|
||||
g_timeout_add (3000, nm_dbus_manager_reconnect, self);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -751,8 +716,6 @@ nm_dbus_manager_init_bus (NMDBusManager *self)
|
||||
DBusError error;
|
||||
gboolean success = FALSE;
|
||||
|
||||
g_return_val_if_fail (self->priv->main_ctx, FALSE);
|
||||
|
||||
if (self->priv->connection) {
|
||||
nm_warning ("DBus Manager already has a valid connection.");
|
||||
return FALSE;
|
||||
@@ -772,7 +735,7 @@ nm_dbus_manager_init_bus (NMDBusManager *self)
|
||||
|
||||
dbus_connection_set_exit_on_disconnect (self->priv->connection, FALSE);
|
||||
dbus_connection_setup_with_g_main (self->priv->connection,
|
||||
self->priv->main_ctx);
|
||||
g_main_context_default ());
|
||||
|
||||
if (!dbus_connection_add_filter (self->priv->connection,
|
||||
nm_dbus_manager_signal_handler,
|
||||
@@ -966,7 +929,6 @@ nm_dbus_manager_register_signal_handler (NMDBusManager *self,
|
||||
NMDBusSignalHandlerFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||
SignalHandlerData * sig_handler;
|
||||
SignalMatch * match = NULL;
|
||||
|
||||
@@ -1001,10 +963,8 @@ nm_dbus_manager_register_signal_handler (NMDBusManager *self,
|
||||
|
||||
signal_match_enable (self, sig_handler->match, NULL);
|
||||
|
||||
g_static_mutex_lock (&mutex);
|
||||
self->priv->sig_handler_id_counter++;
|
||||
sig_handler->id = self->priv->sig_handler_id_counter;
|
||||
g_static_mutex_unlock (&mutex);
|
||||
|
||||
self->priv->signal_handlers = g_slist_append (self->priv->signal_handlers,
|
||||
sig_handler);
|
||||
|
@@ -67,7 +67,7 @@ struct _NMDBusManagerClass {
|
||||
|
||||
GType nm_dbus_manager_get_type (void);
|
||||
|
||||
NMDBusManager * nm_dbus_manager_get (GMainContext *ctx);
|
||||
NMDBusManager * nm_dbus_manager_get (void);
|
||||
|
||||
char * nm_dbus_manager_get_name_owner (NMDBusManager *self,
|
||||
const char *name);
|
||||
|
@@ -55,6 +55,7 @@ nm_dbus_nm_get_devices (DBusConnection *connection,
|
||||
DBusMessage * reply = NULL;
|
||||
DBusMessageIter iter;
|
||||
DBusMessageIter iter_array;
|
||||
GSList * elt;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
@@ -74,16 +75,13 @@ nm_dbus_nm_get_devices (DBusConnection *connection,
|
||||
}
|
||||
|
||||
dbus_message_iter_init_append (reply, &iter);
|
||||
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__)) {
|
||||
GSList *elt;
|
||||
|
||||
dbus_message_iter_open_container (&iter,
|
||||
DBUS_TYPE_ARRAY,
|
||||
DBUS_TYPE_OBJECT_PATH_AS_STRING,
|
||||
&iter_array);
|
||||
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {
|
||||
NMDevice * dev = (NMDevice *) elt->data;
|
||||
NMDevice * dev = NM_DEVICE (elt->data);
|
||||
char * op = nm_dbus_get_object_path_for_device (dev);
|
||||
|
||||
dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH, &op);
|
||||
@@ -92,16 +90,6 @@ nm_dbus_nm_get_devices (DBusConnection *connection,
|
||||
|
||||
dbus_message_iter_close_container (&iter, &iter_array);
|
||||
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
} else {
|
||||
dbus_message_unref (reply);
|
||||
reply = nm_dbus_create_error_message (message,
|
||||
NM_DBUS_INTERFACE,
|
||||
"Retry",
|
||||
"NetworkManager could not lock "
|
||||
" device list, try again.");
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
@@ -114,6 +102,8 @@ nm_dbus_nm_get_dialup (DBusConnection *connection,
|
||||
NMData * data = (NMData *) user_data;
|
||||
DBusMessage * reply = NULL;
|
||||
DBusMessageIter iter;
|
||||
DBusMessageIter iter_array;
|
||||
GSList * elt;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
@@ -133,10 +123,6 @@ nm_dbus_nm_get_dialup (DBusConnection *connection,
|
||||
}
|
||||
|
||||
dbus_message_iter_init_append (reply, &iter);
|
||||
if (nm_try_acquire_mutex (data->dialup_list_mutex, __FUNCTION__)) {
|
||||
DBusMessageIter iter_array;
|
||||
GSList *elt;
|
||||
|
||||
dbus_message_iter_open_container (&iter,
|
||||
DBUS_TYPE_ARRAY,
|
||||
DBUS_TYPE_STRING_AS_STRING,
|
||||
@@ -149,15 +135,6 @@ nm_dbus_nm_get_dialup (DBusConnection *connection,
|
||||
}
|
||||
|
||||
dbus_message_iter_close_container (&iter, &iter_array);
|
||||
nm_unlock_mutex (data->dialup_list_mutex, __FUNCTION__);
|
||||
} else {
|
||||
dbus_message_unref (reply);
|
||||
reply = nm_dbus_create_error_message (message,
|
||||
NM_DBUS_INTERFACE,
|
||||
"Retry",
|
||||
"NetworkManager could not lock "
|
||||
" dialup list, try again.");
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -187,7 +164,6 @@ nm_dbus_nm_activate_dialup (DBusConnection *connection,
|
||||
goto out;
|
||||
}
|
||||
|
||||
nm_lock_mutex (data->dialup_list_mutex, __FUNCTION__);
|
||||
if (!nm_system_activate_dialup (data->dialup_list, dialup)) {
|
||||
reply = nm_dbus_create_error_message (message,
|
||||
NM_DBUS_INTERFACE,
|
||||
@@ -197,7 +173,6 @@ nm_dbus_nm_activate_dialup (DBusConnection *connection,
|
||||
} else {
|
||||
data->modem_active = TRUE;
|
||||
}
|
||||
nm_unlock_mutex (data->dialup_list_mutex, __FUNCTION__);
|
||||
|
||||
out:
|
||||
return reply;
|
||||
@@ -230,7 +205,6 @@ nm_dbus_nm_deactivate_dialup (DBusConnection *connection,
|
||||
goto out;
|
||||
}
|
||||
|
||||
nm_lock_mutex (data->dialup_list_mutex, __FUNCTION__);
|
||||
if (!nm_system_deactivate_dialup (data->dialup_list, dialup)) {
|
||||
reply = nm_dbus_create_error_message (message,
|
||||
NM_DBUS_INTERFACE,
|
||||
@@ -240,7 +214,6 @@ nm_dbus_nm_deactivate_dialup (DBusConnection *connection,
|
||||
} else {
|
||||
data->modem_active = FALSE;
|
||||
}
|
||||
nm_unlock_mutex (data->dialup_list_mutex, __FUNCTION__);
|
||||
|
||||
out:
|
||||
return reply;
|
||||
@@ -557,6 +530,7 @@ nm_dbus_nm_set_wireless_enabled (DBusConnection *connection,
|
||||
NMData * data = (NMData *) user_data;
|
||||
gboolean enabled = FALSE;
|
||||
DBusMessage * reply = NULL;
|
||||
GSList * elt;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
g_return_val_if_fail (message != NULL, NULL);
|
||||
@@ -573,19 +547,15 @@ nm_dbus_nm_set_wireless_enabled (DBusConnection *connection,
|
||||
data->wireless_enabled = enabled;
|
||||
|
||||
if (!enabled) {
|
||||
GSList * elt;
|
||||
|
||||
/* Down all wireless devices */
|
||||
nm_lock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {
|
||||
NMDevice * dev = (NMDevice *)(elt->data);
|
||||
NMDevice * dev = NM_DEVICE (elt->data);
|
||||
|
||||
if (nm_device_is_802_11_wireless (dev)) {
|
||||
nm_device_deactivate (dev);
|
||||
nm_device_bring_down (dev);
|
||||
}
|
||||
}
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
}
|
||||
|
||||
nm_policy_schedule_device_change_check (data);
|
||||
@@ -641,19 +611,15 @@ nm_dbus_nm_sleep (DBusConnection *connection,
|
||||
/* Just deactivate and down all devices from the device list,
|
||||
* we'll remove them in 'wake' for speed's sake.
|
||||
*/
|
||||
nm_lock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {
|
||||
NMDevice *dev = (NMDevice *)(elt->data);
|
||||
NMDevice *dev = NM_DEVICE (elt->data);
|
||||
nm_device_set_removed (dev, TRUE);
|
||||
nm_device_deactivate_quickly (dev);
|
||||
nm_system_device_set_up_down (dev, FALSE);
|
||||
}
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
|
||||
nm_lock_mutex (data->dialup_list_mutex, __FUNCTION__);
|
||||
nm_system_deactivate_all_dialup (data->dialup_list);
|
||||
data->modem_active = FALSE;
|
||||
nm_unlock_mutex (data->dialup_list_mutex, __FUNCTION__);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -676,12 +642,10 @@ nm_dbus_nm_wake (DBusConnection *connection,
|
||||
data->asleep = FALSE;
|
||||
|
||||
/* Remove all devices from the device list */
|
||||
nm_lock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
while (g_slist_length (data->dev_list))
|
||||
nm_remove_device (data, (NMDevice *)(data->dev_list->data));
|
||||
nm_remove_device (data, NM_DEVICE (data->dev_list->data));
|
||||
g_slist_free (data->dev_list);
|
||||
data->dev_list = NULL;
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
|
||||
nm_add_initial_devices (data);
|
||||
|
||||
|
@@ -141,7 +141,7 @@ nm_dbus_get_user_key_for_network (NMActRequest *req,
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("could not get the dbus connection.");
|
||||
@@ -222,7 +222,7 @@ nm_dbus_cancel_get_user_key_for_network (NMActRequest *req)
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("could not get the dbus connection.");
|
||||
@@ -271,7 +271,7 @@ nm_dbus_update_network_info (NMAccessPoint *ap,
|
||||
|
||||
g_return_if_fail (ap != NULL);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("could not get the dbus connection.");
|
||||
@@ -559,7 +559,7 @@ nm_dbus_get_networks_cb (DBusPendingCall *pcall,
|
||||
goto out;
|
||||
}
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("couldn't get dbus connection.");
|
||||
@@ -630,7 +630,7 @@ nm_dbus_update_allowed_networks (NMAccessPointList *list,
|
||||
g_return_if_fail (list != NULL);
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("could not get the dbus connection.");
|
||||
@@ -686,7 +686,7 @@ nm_dbus_update_one_allowed_network (const char *network,
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("could not get the dbus connection.");
|
||||
|
@@ -62,7 +62,7 @@ typedef struct Supplicant {
|
||||
guint iface_scan_result_id;
|
||||
guint iface_con_state_id;
|
||||
|
||||
GSource * con_timeout;
|
||||
guint con_timeout_id;
|
||||
} Supplicant;
|
||||
|
||||
struct _NMDevice80211WirelessPrivate
|
||||
@@ -85,12 +85,13 @@ struct _NMDevice80211WirelessPrivate
|
||||
NMAccessPointList * ap_list;
|
||||
guint8 scan_interval; /* seconds */
|
||||
guint32 last_scan;
|
||||
GSource * pending_scan;
|
||||
guint pending_scan_id;
|
||||
|
||||
Supplicant supplicant;
|
||||
|
||||
guint32 failed_link_count;
|
||||
GSource * link_timeout;
|
||||
guint periodic_source_id;
|
||||
guint link_timeout_id;
|
||||
|
||||
/* Static options from driver */
|
||||
guint8 we_version;
|
||||
@@ -557,14 +558,11 @@ static void
|
||||
real_start (NMDevice *dev)
|
||||
{
|
||||
NMDevice80211Wireless * self = NM_DEVICE_802_11_WIRELESS (dev);
|
||||
GSource * source;
|
||||
guint source_id;
|
||||
guint id;
|
||||
|
||||
/* Peridoically update link status and signal strength */
|
||||
source = g_timeout_source_new (2000);
|
||||
g_source_set_callback (source, nm_device_802_11_periodic_update, self, NULL);
|
||||
source_id = g_source_attach (source, nm_device_get_main_context (dev));
|
||||
g_source_unref (source);
|
||||
id = g_timeout_add (2000, nm_device_802_11_periodic_update, self);
|
||||
self->priv->periodic_source_id = id;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1143,24 +1141,23 @@ nm_device_802_11_wireless_set_scan_interval (NMData *data,
|
||||
NMWirelessScanInterval interval)
|
||||
{
|
||||
static guint source_id = 0;
|
||||
GSource * source = NULL;
|
||||
GSList * elt;
|
||||
gboolean found = FALSE;
|
||||
guint8 seconds = nm_wireless_scan_interval_to_seconds (interval);
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
if (source_id != 0)
|
||||
if (source_id != 0) {
|
||||
g_source_remove (source_id);
|
||||
source_id = 0;
|
||||
}
|
||||
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {
|
||||
NMDevice *d = (NMDevice *)(elt->data);
|
||||
if (self && (NM_DEVICE (self) != d))
|
||||
continue;
|
||||
|
||||
if (d && nm_device_is_802_11_wireless (d))
|
||||
{
|
||||
if (d && nm_device_is_802_11_wireless (d)) {
|
||||
NM_DEVICE_802_11_WIRELESS (d)->priv->scan_interval = seconds;
|
||||
if (self && (NM_DEVICE (self) == d))
|
||||
found = TRUE;
|
||||
@@ -1174,12 +1171,8 @@ nm_device_802_11_wireless_set_scan_interval (NMData *data,
|
||||
if (self && !found)
|
||||
self->priv->scan_interval = seconds;
|
||||
|
||||
if (interval != NM_WIRELESS_SCAN_INTERVAL_INACTIVE)
|
||||
{
|
||||
source = g_timeout_source_new (120000);
|
||||
g_source_set_callback (source, set_scan_interval_cb, (gpointer) data, NULL);
|
||||
source_id = g_source_attach (source, data->main_context);
|
||||
g_source_unref (source);
|
||||
if (interval != NM_WIRELESS_SCAN_INTERVAL_INACTIVE) {
|
||||
source_id = g_timeout_add (120000, set_scan_interval_cb, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1801,10 +1794,9 @@ request_wireless_scan (gpointer user_data)
|
||||
if (!(caps & NM_DEVICE_CAP_NM_SUPPORTED) || !(caps & NM_DEVICE_CAP_WIRELESS_SCAN))
|
||||
goto out;
|
||||
|
||||
if (self->priv->pending_scan) {
|
||||
g_source_destroy (self->priv->pending_scan);
|
||||
g_source_unref (self->priv->pending_scan); /* Balance g_timeout_source_new() */
|
||||
self->priv->pending_scan = NULL;
|
||||
if (self->priv->pending_scan_id) {
|
||||
g_source_remove (self->priv->pending_scan_id);
|
||||
self->priv->pending_scan_id = 0;
|
||||
}
|
||||
|
||||
/* Reschedule ourselves if all wireless is disabled, we're asleep,
|
||||
@@ -1857,15 +1849,16 @@ out:
|
||||
static void
|
||||
schedule_scan (NMDevice80211Wireless *self)
|
||||
{
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
cancel_pending_scan (self);
|
||||
|
||||
self->priv->pending_scan = g_timeout_source_new (self->priv->scan_interval * 1000);
|
||||
g_source_set_callback (self->priv->pending_scan,
|
||||
request_wireless_scan, self, NULL);
|
||||
g_source_attach (self->priv->pending_scan,
|
||||
nm_device_get_main_context (NM_DEVICE (self)));
|
||||
id = g_timeout_add (self->priv->scan_interval * 1000,
|
||||
request_wireless_scan,
|
||||
self);
|
||||
self->priv->pending_scan_id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -1874,10 +1867,9 @@ cancel_pending_scan (NMDevice80211Wireless *self)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
if (self->priv->pending_scan) {
|
||||
g_source_destroy (self->priv->pending_scan); /* Balance g_source_attach() */
|
||||
g_source_unref (self->priv->pending_scan); /* Balance g_timeout_source_new() */
|
||||
self->priv->pending_scan = NULL;
|
||||
if (self->priv->pending_scan_id) {
|
||||
g_source_remove (self->priv->pending_scan_id);
|
||||
self->priv->pending_scan_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2116,9 +2108,7 @@ cull_scan_list (NMDevice80211Wireless * self)
|
||||
}
|
||||
nm_ap_list_iter_free (iter);
|
||||
|
||||
/* Ok, now remove outdated ones. We have to do it after the lock
|
||||
* because nm_ap_list_remove_ap() locks the list too.
|
||||
*/
|
||||
/* Remove outdated APs */
|
||||
for (elt = outdated_list; elt; elt = g_slist_next (elt)) {
|
||||
if (!(outdated_ap = (NMAccessPoint *)(elt->data)))
|
||||
continue;
|
||||
@@ -2363,9 +2353,9 @@ remove_link_timeout (NMDevice80211Wireless *self)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
if (self->priv->link_timeout != NULL) {
|
||||
g_source_destroy (self->priv->link_timeout);
|
||||
self->priv->link_timeout = NULL;
|
||||
if (self->priv->link_timeout_id) {
|
||||
g_source_remove (self->priv->link_timeout_id);
|
||||
self->priv->link_timeout_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2387,6 +2377,10 @@ link_timeout_cb (gpointer user_data)
|
||||
|
||||
g_assert (dev);
|
||||
|
||||
if (self->priv->link_timeout_id) {
|
||||
self->priv->link_timeout_id = 0;
|
||||
}
|
||||
|
||||
req = nm_device_get_act_request (dev);
|
||||
if (req)
|
||||
ap = nm_act_request_get_ap (req);
|
||||
@@ -2433,7 +2427,6 @@ schedule_state_handler (NMDevice80211Wireless * self,
|
||||
guint32 old_state)
|
||||
{
|
||||
struct state_cb_data * cb_data;
|
||||
GSource * source;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (handler != NULL, FALSE);
|
||||
@@ -2452,10 +2445,7 @@ schedule_state_handler (NMDevice80211Wireless * self,
|
||||
cb_data->new_state = new_state;
|
||||
cb_data->old_state = old_state;
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_callback (source, handler, cb_data, NULL);
|
||||
g_source_attach (source, nm_device_get_main_context (NM_DEVICE (self)));
|
||||
g_source_unref (source);
|
||||
g_idle_add (handler, cb_data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -2483,13 +2473,7 @@ supplicant_iface_state_cb_handler (gpointer user_data)
|
||||
|
||||
/* Start the scanning timeout for devices that can do scanning */
|
||||
if (nm_device_get_capabilities (NM_DEVICE (self)) & NM_DEVICE_CAP_WIRELESS_SCAN) {
|
||||
guint source_id;
|
||||
|
||||
self->priv->pending_scan = g_idle_source_new ();
|
||||
g_source_set_callback (self->priv->pending_scan,
|
||||
request_wireless_scan, self, NULL);
|
||||
source_id = g_source_attach (self->priv->pending_scan,
|
||||
nm_device_get_main_context (NM_DEVICE (self)));
|
||||
self->priv->pending_scan_id = g_idle_add (request_wireless_scan, self);
|
||||
}
|
||||
|
||||
/* Device may be able to be activated now */
|
||||
@@ -2568,11 +2552,8 @@ supplicant_iface_connection_state_cb_handler (gpointer user_data)
|
||||
gboolean has_link = nm_device_has_active_link (NM_DEVICE (self));
|
||||
|
||||
/* Start the link timeout so we allow some time for reauthentication */
|
||||
if (!has_link && (self->priv->link_timeout == NULL) && !self->priv->scanning) {
|
||||
GMainContext * context = nm_device_get_main_context (dev);
|
||||
self->priv->link_timeout = g_timeout_source_new (12000);
|
||||
g_source_set_callback (self->priv->link_timeout, link_timeout_cb, self, NULL);
|
||||
g_source_attach (self->priv->link_timeout, context);
|
||||
if (!has_link && (self->priv->link_timeout_id == 0) && !self->priv->scanning) {
|
||||
self->priv->link_timeout_id = g_timeout_add (12000, link_timeout_cb, self);
|
||||
}
|
||||
} else {
|
||||
nm_device_set_active_link (dev, FALSE);
|
||||
@@ -2754,7 +2735,7 @@ supplicant_iface_connection_error_cb (NMSupplicantInterface * iface,
|
||||
NMDevice80211Wireless * self)
|
||||
{
|
||||
struct iface_con_error_cb_data * cb_data;
|
||||
GSource * source;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
@@ -2768,13 +2749,7 @@ supplicant_iface_connection_error_cb (NMSupplicantInterface * iface,
|
||||
cb_data->name = g_strdup (name);
|
||||
cb_data->message = g_strdup (message);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_callback (source,
|
||||
supplicant_iface_connection_error_cb_handler,
|
||||
cb_data,
|
||||
NULL);
|
||||
g_source_attach (source, nm_device_get_main_context (NM_DEVICE (self)));
|
||||
g_source_unref (source);
|
||||
id = g_idle_add (supplicant_iface_connection_error_cb_handler, cb_data);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2783,10 +2758,9 @@ remove_supplicant_connection_timeout (NMDevice80211Wireless *self)
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
/* Remove any pending timeouts on the request */
|
||||
if (self->priv->supplicant.con_timeout != NULL) {
|
||||
g_source_destroy (self->priv->supplicant.con_timeout);
|
||||
g_source_unref (self->priv->supplicant.con_timeout);
|
||||
self->priv->supplicant.con_timeout = NULL;
|
||||
if (self->priv->supplicant.con_timeout_id) {
|
||||
g_source_remove (self->priv->supplicant.con_timeout_id);
|
||||
self->priv->supplicant.con_timeout_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2840,26 +2814,21 @@ start_supplicant_connection_timeout (NMDevice80211Wireless *self)
|
||||
{
|
||||
GMainContext * context;
|
||||
NMDevice * dev;
|
||||
guint id;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
|
||||
dev = NM_DEVICE (self);
|
||||
|
||||
/* Set up a timeout on the connection attempt to fail it after 25 seconds */
|
||||
self->priv->supplicant.con_timeout = g_timeout_source_new (25000);
|
||||
if (self->priv->supplicant.con_timeout == NULL) {
|
||||
id = g_timeout_add (25000, supplicant_connection_timeout_cb, self);
|
||||
if (id <= 0) {
|
||||
nm_warning ("Activation (%s/wireless): couldn't start supplicant "
|
||||
"timeout timer.",
|
||||
nm_device_get_iface (dev));
|
||||
return FALSE;
|
||||
}
|
||||
g_source_set_callback (self->priv->supplicant.con_timeout,
|
||||
supplicant_connection_timeout_cb,
|
||||
self,
|
||||
NULL);
|
||||
context = nm_device_get_main_context (dev);
|
||||
g_source_attach (self->priv->supplicant.con_timeout, context);
|
||||
|
||||
self->priv->supplicant.con_timeout_id = id;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -3269,6 +3238,11 @@ nm_device_802_11_wireless_dispose (GObject *object)
|
||||
self->priv->supplicant.mgr = NULL;
|
||||
}
|
||||
|
||||
if (self->priv->periodic_source_id) {
|
||||
g_source_remove (self->priv->periodic_source_id);
|
||||
self->priv->periodic_source_id = 0;
|
||||
}
|
||||
|
||||
out:
|
||||
/* Chain up to the parent class */
|
||||
parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass));
|
||||
|
@@ -47,6 +47,7 @@ struct _NMDevice8023EthernetPrivate
|
||||
char * carrier_file_path;
|
||||
gulong link_connected_id;
|
||||
gulong link_disconnected_id;
|
||||
guint link_source_id;
|
||||
|
||||
NMSupplicantInterface * sup_iface;
|
||||
};
|
||||
@@ -72,6 +73,7 @@ nm_device_802_3_ethernet_init (NMDevice8023Ethernet * self)
|
||||
{
|
||||
self->priv = NM_DEVICE_802_3_ETHERNET_GET_PRIVATE (self);
|
||||
self->priv->dispose_has_run = FALSE;
|
||||
self->priv->link_source_id = 0;
|
||||
|
||||
memset (&(self->priv->hw_addr), 0, sizeof (struct ether_addr));
|
||||
}
|
||||
@@ -198,17 +200,14 @@ static void
|
||||
real_start (NMDevice *dev)
|
||||
{
|
||||
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (dev);
|
||||
GSource * source;
|
||||
guint source_id;
|
||||
guint id;
|
||||
|
||||
self->priv->carrier_file_path = g_strdup_printf ("/sys/class/net/%s/carrier",
|
||||
nm_device_get_iface (NM_DEVICE (dev)));
|
||||
|
||||
/* Peridoically update link status and signal strength */
|
||||
source = g_timeout_source_new (2000);
|
||||
g_source_set_callback (source, nm_device_802_3_periodic_update, self, NULL);
|
||||
source_id = g_source_attach (source, nm_device_get_main_context (dev));
|
||||
g_source_unref (source);
|
||||
/* Peridoically update link status */
|
||||
id = g_timeout_add (2000, nm_device_802_3_periodic_update, self);
|
||||
self->priv->link_source_id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -340,6 +339,11 @@ nm_device_802_3_ethernet_dispose (GObject *object)
|
||||
g_signal_handler_disconnect (G_OBJECT (data->netlink_monitor),
|
||||
self->priv->link_disconnected_id);
|
||||
|
||||
if (self->priv->link_source_id) {
|
||||
g_source_remove (self->priv->link_source_id);
|
||||
self->priv->link_source_id = 0;
|
||||
}
|
||||
|
||||
/* Chain up to the parent class */
|
||||
parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass));
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
|
@@ -34,8 +34,6 @@ typedef struct NMDbusCBData {
|
||||
|
||||
gboolean nm_device_is_activated (NMDevice *dev);
|
||||
|
||||
GMainContext * nm_device_get_main_context (NMDevice *dev);
|
||||
|
||||
NMIP4Config * nm_device_new_ip4_autoip_config (NMDevice *self);
|
||||
|
||||
void nm_device_activate_schedule_stage3_ip_config_start (struct NMActRequest *req);
|
||||
|
209
src/nm-device.c
209
src/nm-device.c
@@ -58,14 +58,12 @@ struct _NMDevicePrivate
|
||||
NMData * app_data;
|
||||
|
||||
NMActRequest * act_request;
|
||||
GSource * act_source;
|
||||
guint act_source_id;
|
||||
|
||||
/* IP configuration info */
|
||||
void * system_config_data; /* Distro-specific config data (parsed config file, etc) */
|
||||
gboolean use_dhcp;
|
||||
NMIP4Config * ip4_config; /* Config from DHCP, PPP, or system config files */
|
||||
|
||||
GMainContext * context;
|
||||
};
|
||||
|
||||
static void nm_device_activate_schedule_stage5_ip_config_commit (NMActRequest *req);
|
||||
@@ -164,8 +162,6 @@ nm_device_new (const char *iface,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->priv->context = app_data->main_context;
|
||||
|
||||
/* Have to bring the device up before checking link status and other stuff */
|
||||
nm_device_bring_up_wait (dev, FALSE);
|
||||
|
||||
@@ -218,13 +214,11 @@ nm_device_init (NMDevice * self)
|
||||
self->priv->app_data = NULL;
|
||||
|
||||
self->priv->act_request = NULL;
|
||||
self->priv->act_source = NULL;
|
||||
self->priv->act_source_id = 0;
|
||||
|
||||
self->priv->system_config_data = NULL;
|
||||
self->priv->use_dhcp = TRUE;
|
||||
self->priv->ip4_config = NULL;
|
||||
|
||||
self->priv->context = NULL;
|
||||
}
|
||||
|
||||
static guint32
|
||||
@@ -249,23 +243,12 @@ nm_device_stop (NMDevice *self)
|
||||
nm_device_bring_down (self);
|
||||
}
|
||||
|
||||
GMainContext *
|
||||
nm_device_get_main_context (NMDevice *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
return self->priv->context;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_get_device_by_udi
|
||||
*
|
||||
* Search through the device list for a device with a given UDI.
|
||||
*
|
||||
* NOTE: the caller MUST hold the device list mutex already to make
|
||||
* this routine thread-safe.
|
||||
*
|
||||
*/
|
||||
NMDevice *
|
||||
nm_get_device_by_udi (NMData *data,
|
||||
@@ -295,9 +278,6 @@ nm_get_device_by_udi (NMData *data,
|
||||
*
|
||||
* Search through the device list for a device with a given iface.
|
||||
*
|
||||
* NOTE: the caller MUST hold the device list mutex already to make
|
||||
* this routine thread-safe.
|
||||
*
|
||||
*/
|
||||
NMDevice *
|
||||
nm_get_device_by_iface (NMData *data,
|
||||
@@ -308,57 +288,17 @@ nm_get_device_by_iface (NMData *data,
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
NMDevice *dev = NULL;
|
||||
if ((dev = NM_DEVICE (elt->data)))
|
||||
{
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt)) {
|
||||
NMDevice *dev = NM_DEVICE (elt->data);
|
||||
|
||||
g_assert (dev);
|
||||
if (nm_null_safe_strcmp (nm_device_get_iface (dev), iface) == 0)
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_get_device_by_iface_locked
|
||||
*
|
||||
* Search through the device list for a device with a given iface.
|
||||
* NOTE: refs the device, caller must unref when done.
|
||||
*
|
||||
*/
|
||||
NMDevice *
|
||||
nm_get_device_by_iface_locked (NMData *data,
|
||||
const char *iface)
|
||||
{
|
||||
GSList * elt;
|
||||
NMDevice *dev = NULL;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
|
||||
nm_lock_mutex (data->dev_list_mutex, __func__);
|
||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
NMDevice *tmp_dev = NULL;
|
||||
if ((tmp_dev = NM_DEVICE (elt->data)))
|
||||
{
|
||||
if (nm_null_safe_strcmp (nm_device_get_iface (tmp_dev), iface) == 0)
|
||||
{
|
||||
g_object_ref (G_OBJECT (tmp_dev));
|
||||
dev = tmp_dev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get/set functions for UDI
|
||||
*/
|
||||
@@ -610,8 +550,9 @@ nm_device_activation_start (NMActRequest *req)
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_device_activate_stage1_device_prepare (NMActRequest *req)
|
||||
nm_device_activate_stage1_device_prepare (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMDevice * self;
|
||||
NMData * data;
|
||||
const char * iface;
|
||||
@@ -625,13 +566,9 @@ nm_device_activate_stage1_device_prepare (NMActRequest *req)
|
||||
self = nm_act_request_get_dev (req);
|
||||
g_assert (self);
|
||||
|
||||
/* Unref and clear activation GSource to balance
|
||||
* it's creation in the function that scheduled this one.
|
||||
*/
|
||||
if (self->priv->act_source) {
|
||||
g_source_unref (self->priv->act_source);
|
||||
self->priv->act_source = NULL;
|
||||
}
|
||||
/* Clear the activation source ID now that this stage has run */
|
||||
if (self->priv->act_source_id > 0)
|
||||
self->priv->act_source_id = 0;
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
nm_info ("Activation (%s) Stage 1 of 5 (Device Prepare) started...", iface);
|
||||
@@ -663,6 +600,7 @@ void
|
||||
nm_device_activate_schedule_stage1_device_prepare (NMActRequest *req)
|
||||
{
|
||||
NMDevice * self = NULL;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
@@ -670,10 +608,8 @@ nm_device_activate_schedule_stage1_device_prepare (NMActRequest *req)
|
||||
g_assert (self);
|
||||
|
||||
nm_act_request_set_stage (req, NM_ACT_STAGE_DEVICE_PREPARE);
|
||||
|
||||
self->priv->act_source = g_idle_source_new ();
|
||||
g_source_set_callback (self->priv->act_source, (GSourceFunc) nm_device_activate_stage1_device_prepare, req, NULL);
|
||||
g_source_attach (self->priv->act_source, self->priv->context);
|
||||
id = g_idle_add (nm_device_activate_stage1_device_prepare, req);
|
||||
self->priv->act_source_id = id;
|
||||
|
||||
nm_info ("Activation (%s) Stage 1 of 5 (Device Prepare) scheduled...",
|
||||
nm_device_get_iface (self));
|
||||
@@ -701,8 +637,9 @@ real_act_stage2_config (NMDevice *dev, NMActRequest *req)
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_device_activate_stage2_device_config (NMActRequest *req)
|
||||
nm_device_activate_stage2_device_config (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMDevice * self;
|
||||
NMData * data;
|
||||
const char * iface;
|
||||
@@ -716,13 +653,9 @@ nm_device_activate_stage2_device_config (NMActRequest *req)
|
||||
self = nm_act_request_get_dev (req);
|
||||
g_assert (self);
|
||||
|
||||
/* Unref and clear activation GSource to balance
|
||||
* it's creation in the function that scheduled this one.
|
||||
*/
|
||||
if (self->priv->act_source) {
|
||||
g_source_unref (self->priv->act_source);
|
||||
self->priv->act_source = NULL;
|
||||
}
|
||||
/* Clear the activation source ID now that this stage has run */
|
||||
if (self->priv->act_source_id > 0)
|
||||
self->priv->act_source_id = 0;
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
nm_info ("Activation (%s) Stage 2 of 5 (Device Configure) starting...", iface);
|
||||
@@ -761,6 +694,7 @@ void
|
||||
nm_device_activate_schedule_stage2_device_config (NMActRequest *req)
|
||||
{
|
||||
NMDevice * self = NULL;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
@@ -768,10 +702,8 @@ nm_device_activate_schedule_stage2_device_config (NMActRequest *req)
|
||||
g_assert (self);
|
||||
|
||||
nm_act_request_set_stage (req, NM_ACT_STAGE_DEVICE_CONFIG);
|
||||
|
||||
self->priv->act_source = g_idle_source_new ();
|
||||
g_source_set_callback (self->priv->act_source, (GSourceFunc) nm_device_activate_stage2_device_config, req, NULL);
|
||||
g_source_attach (self->priv->act_source, self->priv->context);
|
||||
id = g_idle_add (nm_device_activate_stage2_device_config, req);
|
||||
self->priv->act_source_id = id;
|
||||
|
||||
nm_info ("Activation (%s) Stage 2 of 5 (Device Configure) scheduled...",
|
||||
nm_device_get_iface (self));
|
||||
@@ -816,8 +748,9 @@ out:
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_device_activate_stage3_ip_config_start (NMActRequest *req)
|
||||
nm_device_activate_stage3_ip_config_start (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMData * data = NULL;
|
||||
NMDevice * self = NULL;
|
||||
const char * iface;
|
||||
@@ -831,13 +764,9 @@ nm_device_activate_stage3_ip_config_start (NMActRequest *req)
|
||||
self = nm_act_request_get_dev (req);
|
||||
g_assert (self);
|
||||
|
||||
/* Unref and clear activation GSource to balance
|
||||
* it's creation in the function that scheduled this one.
|
||||
*/
|
||||
if (self->priv->act_source) {
|
||||
g_source_unref (self->priv->act_source);
|
||||
self->priv->act_source = NULL;
|
||||
}
|
||||
/* Clear the activation source ID now that this stage has run */
|
||||
if (self->priv->act_source_id > 0)
|
||||
self->priv->act_source_id = 0;
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
nm_info ("Activation (%s) Stage 3 of 5 (IP Configure Start) started...", iface);
|
||||
@@ -869,6 +798,7 @@ void
|
||||
nm_device_activate_schedule_stage3_ip_config_start (NMActRequest *req)
|
||||
{
|
||||
NMDevice * self = NULL;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
@@ -876,10 +806,8 @@ nm_device_activate_schedule_stage3_ip_config_start (NMActRequest *req)
|
||||
g_assert (self);
|
||||
|
||||
nm_act_request_set_stage (req, NM_ACT_STAGE_IP_CONFIG_START);
|
||||
|
||||
self->priv->act_source = g_idle_source_new ();
|
||||
g_source_set_callback (self->priv->act_source, (GSourceFunc) nm_device_activate_stage3_ip_config_start, req, NULL);
|
||||
g_source_attach (self->priv->act_source, self->priv->context);
|
||||
id = g_idle_add (nm_device_activate_stage3_ip_config_start, req);
|
||||
self->priv->act_source_id = id;
|
||||
|
||||
nm_info ("Activation (%s) Stage 3 of 5 (IP Configure Start) scheduled.",
|
||||
nm_device_get_iface (self));
|
||||
@@ -959,8 +887,9 @@ real_act_stage4_get_ip4_config (NMDevice *self,
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_device_activate_stage4_ip_config_get (NMActRequest *req)
|
||||
nm_device_activate_stage4_ip_config_get (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMData * data = NULL;
|
||||
NMDevice * self = NULL;
|
||||
NMIP4Config * ip4_config = NULL;
|
||||
@@ -975,13 +904,9 @@ nm_device_activate_stage4_ip_config_get (NMActRequest *req)
|
||||
self = nm_act_request_get_dev (req);
|
||||
g_assert (self);
|
||||
|
||||
/* Unref and clear activation GSource to balance
|
||||
* it's creation in the function that scheduled this one.
|
||||
*/
|
||||
if (self->priv->act_source) {
|
||||
g_source_unref (self->priv->act_source);
|
||||
self->priv->act_source = NULL;
|
||||
}
|
||||
/* Clear the activation source ID now that this stage has run */
|
||||
if (self->priv->act_source_id > 0)
|
||||
self->priv->act_source_id = 0;
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
nm_info ("Activation (%s) Stage 4 of 5 (IP Configure Get) started...", iface);
|
||||
@@ -1015,6 +940,7 @@ void
|
||||
nm_device_activate_schedule_stage4_ip_config_get (NMActRequest *req)
|
||||
{
|
||||
NMDevice * self = NULL;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
@@ -1022,10 +948,8 @@ nm_device_activate_schedule_stage4_ip_config_get (NMActRequest *req)
|
||||
g_assert (self);
|
||||
|
||||
nm_act_request_set_stage (req, NM_ACT_STAGE_IP_CONFIG_GET);
|
||||
|
||||
self->priv->act_source = g_idle_source_new ();
|
||||
g_source_set_callback (self->priv->act_source, (GSourceFunc) nm_device_activate_stage4_ip_config_get, req, NULL);
|
||||
g_source_attach (self->priv->act_source, self->priv->context);
|
||||
id = g_idle_add (nm_device_activate_stage4_ip_config_get, req);
|
||||
self->priv->act_source_id = id;
|
||||
|
||||
nm_info ("Activation (%s) Stage 4 of 5 (IP Configure Get) scheduled...",
|
||||
nm_device_get_iface (self));
|
||||
@@ -1057,8 +981,9 @@ real_act_stage4_ip_config_timeout (NMDevice *self,
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_device_activate_stage4_ip_config_timeout (NMActRequest *req)
|
||||
nm_device_activate_stage4_ip_config_timeout (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMData * data = NULL;
|
||||
NMDevice * self = NULL;
|
||||
NMIP4Config * ip4_config = NULL;
|
||||
@@ -1073,14 +998,17 @@ nm_device_activate_stage4_ip_config_timeout (NMActRequest *req)
|
||||
self = nm_act_request_get_dev (req);
|
||||
g_assert (self);
|
||||
|
||||
/* Clear the activation source ID now that this stage has run */
|
||||
if (self->priv->act_source_id > 0)
|
||||
self->priv->act_source_id = 0;
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
nm_info ("Activation (%s) Stage 4 of 5 (IP Configure Timeout) started...", iface);
|
||||
|
||||
ret = NM_DEVICE_GET_CLASS (self)->act_stage4_ip_config_timeout (self, req, &ip4_config);
|
||||
if (ret == NM_ACT_STAGE_RETURN_POSTPONE)
|
||||
if (ret == NM_ACT_STAGE_RETURN_POSTPONE) {
|
||||
goto out;
|
||||
else if (!ip4_config || (ret == NM_ACT_STAGE_RETURN_FAILURE))
|
||||
{
|
||||
} else if (!ip4_config || (ret == NM_ACT_STAGE_RETURN_FAILURE)) {
|
||||
nm_policy_schedule_activation_failed (req);
|
||||
goto out;
|
||||
}
|
||||
@@ -1105,8 +1033,8 @@ out:
|
||||
void
|
||||
nm_device_activate_schedule_stage4_ip_config_timeout (NMActRequest *req)
|
||||
{
|
||||
GSource * source = NULL;
|
||||
NMDevice * self = NULL;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
@@ -1114,12 +1042,11 @@ nm_device_activate_schedule_stage4_ip_config_timeout (NMActRequest *req)
|
||||
g_assert (self);
|
||||
|
||||
nm_act_request_set_stage (req, NM_ACT_STAGE_IP_CONFIG_GET);
|
||||
id = g_idle_add (nm_device_activate_stage4_ip_config_timeout, req);
|
||||
self->priv->act_source_id = id;
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_callback (source, (GSourceFunc) nm_device_activate_stage4_ip_config_timeout, req, NULL);
|
||||
g_source_attach (source, self->priv->context);
|
||||
g_source_unref (source);
|
||||
nm_info ("Activation (%s) Stage 4 of 5 (IP Configure Timeout) scheduled...", nm_device_get_iface (self));
|
||||
nm_info ("Activation (%s) Stage 4 of 5 (IP Configure Timeout) scheduled...",
|
||||
nm_device_get_iface (self));
|
||||
}
|
||||
|
||||
|
||||
@@ -1130,8 +1057,9 @@ nm_device_activate_schedule_stage4_ip_config_timeout (NMActRequest *req)
|
||||
*
|
||||
*/
|
||||
static gboolean
|
||||
nm_device_activate_stage5_ip_config_commit (NMActRequest *req)
|
||||
nm_device_activate_stage5_ip_config_commit (gpointer user_data)
|
||||
{
|
||||
NMActRequest * req = (NMActRequest *) user_data;
|
||||
NMData * data = NULL;
|
||||
NMDevice * self = NULL;
|
||||
NMIP4Config * ip4_config = NULL;
|
||||
@@ -1148,13 +1076,9 @@ nm_device_activate_stage5_ip_config_commit (NMActRequest *req)
|
||||
ip4_config = nm_act_request_get_ip4_config (req);
|
||||
g_assert (ip4_config);
|
||||
|
||||
/* Unref and clear activation GSource to balance
|
||||
* it's creation in the function that scheduled this one.
|
||||
*/
|
||||
if (self->priv->act_source) {
|
||||
g_source_unref (self->priv->act_source);
|
||||
self->priv->act_source = NULL;
|
||||
}
|
||||
/* Clear the activation source ID now that this stage has run */
|
||||
if (self->priv->act_source_id > 0)
|
||||
self->priv->act_source_id = 0;
|
||||
|
||||
iface = nm_device_get_iface (self);
|
||||
nm_info ("Activation (%s) Stage 5 of 5 (IP Configure Commit) started...",
|
||||
@@ -1190,6 +1114,7 @@ static void
|
||||
nm_device_activate_schedule_stage5_ip_config_commit (NMActRequest *req)
|
||||
{
|
||||
NMDevice * self = NULL;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
@@ -1197,10 +1122,8 @@ nm_device_activate_schedule_stage5_ip_config_commit (NMActRequest *req)
|
||||
g_assert (self);
|
||||
|
||||
nm_act_request_set_stage (req, NM_ACT_STAGE_IP_CONFIG_COMMIT);
|
||||
|
||||
self->priv->act_source = g_idle_source_new ();
|
||||
g_source_set_callback (self->priv->act_source, (GSourceFunc) nm_device_activate_stage5_ip_config_commit, req, NULL);
|
||||
g_source_attach (self->priv->act_source, self->priv->context);
|
||||
id = g_idle_add (nm_device_activate_stage5_ip_config_commit, req);
|
||||
self->priv->act_source_id = id;
|
||||
|
||||
nm_info ("Activation (%s) Stage 5 of 5 (IP Configure Commit) scheduled...",
|
||||
nm_device_get_iface (self));
|
||||
@@ -1240,10 +1163,9 @@ nm_device_activation_cancel (NMDevice *self)
|
||||
nm_info ("Activation (%s): cancelling...", nm_device_get_iface (self));
|
||||
|
||||
/* Break the activation chain */
|
||||
if (self->priv->act_source) {
|
||||
g_source_destroy (self->priv->act_source);
|
||||
g_source_unref (self->priv->act_source);
|
||||
self->priv->act_source = NULL;
|
||||
if (self->priv->act_source_id) {
|
||||
g_source_remove (self->priv->act_source_id);
|
||||
self->priv->act_source_id = 0;
|
||||
}
|
||||
|
||||
klass = NM_DEVICE_CLASS (g_type_class_peek (NM_TYPE_DEVICE));
|
||||
@@ -1725,10 +1647,9 @@ nm_device_dispose (GObject *object)
|
||||
self->priv->act_request = NULL;
|
||||
}
|
||||
|
||||
if (self->priv->act_source) {
|
||||
g_source_destroy (self->priv->act_source);
|
||||
g_source_unref (self->priv->act_source);
|
||||
self->priv->act_source = NULL;
|
||||
if (self->priv->act_source_id) {
|
||||
g_source_remove (self->priv->act_source_id);
|
||||
self->priv->act_source_id = 0;
|
||||
}
|
||||
|
||||
/* Chain up to the parent class */
|
||||
|
@@ -177,8 +177,6 @@ NMDevice * nm_get_device_by_udi (struct NMData *data,
|
||||
const char *udi);
|
||||
NMDevice * nm_get_device_by_iface (struct NMData *data,
|
||||
const char *iface);
|
||||
NMDevice * nm_get_device_by_iface_locked (struct NMData *data,
|
||||
const char *iface);
|
||||
|
||||
gboolean nm_device_is_test_device (NMDevice *dev);
|
||||
|
||||
|
@@ -720,7 +720,7 @@ nm_netlink_monitor_event_handler (GIOChannel *channel,
|
||||
gboolean is_connected = !!((gboolean) (interface_info->ifi_flags & IFF_RUNNING));
|
||||
NMDevice * dev;
|
||||
|
||||
if ((dev = nm_get_device_by_iface_locked (monitor->priv->app_data, iface)))
|
||||
if ((dev = nm_get_device_by_iface (monitor->priv->app_data, iface)))
|
||||
{
|
||||
if (is_connected) {
|
||||
g_signal_emit (G_OBJECT (monitor),
|
||||
@@ -731,7 +731,6 @@ nm_netlink_monitor_event_handler (GIOChannel *channel,
|
||||
nm_netlink_monitor_signals[INTERFACE_DISCONNECTED],
|
||||
0, dev);
|
||||
}
|
||||
g_object_unref (G_OBJECT (dev));
|
||||
}
|
||||
}
|
||||
g_free (iface);
|
||||
@@ -739,7 +738,7 @@ nm_netlink_monitor_event_handler (GIOChannel *channel,
|
||||
char * iface = nm_system_get_iface_from_rtnl_index (interface_info->ifi_index);
|
||||
if (iface != NULL) {
|
||||
NMDevice *dev;
|
||||
if ((dev = nm_get_device_by_iface_locked (monitor->priv->app_data, iface)))
|
||||
if ((dev = nm_get_device_by_iface (monitor->priv->app_data, iface)))
|
||||
{
|
||||
char * data = g_malloc0 (data_len);
|
||||
memcpy (data, RTA_DATA (attribute), data_len);
|
||||
@@ -747,7 +746,6 @@ nm_netlink_monitor_event_handler (GIOChannel *channel,
|
||||
nm_netlink_monitor_signals[WIRELESS_EVENT],
|
||||
0, dev, data, data_len);
|
||||
g_free (data);
|
||||
g_object_unref (G_OBJECT (dev));
|
||||
}
|
||||
}
|
||||
g_free (iface);
|
||||
|
@@ -204,7 +204,7 @@ nm_supplicant_interface_init (NMSupplicantInterface * self)
|
||||
self->priv->other_pcalls = NULL;
|
||||
self->priv->dispose_has_run = FALSE;
|
||||
|
||||
self->priv->dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
self->priv->dbus_mgr = nm_dbus_manager_get ();
|
||||
}
|
||||
|
||||
|
||||
@@ -745,14 +745,15 @@ wpas_iface_query_scan_results (NMSupplicantInterface * self)
|
||||
|
||||
/* Only fetch scan results every 4s max, but initially do it right away */
|
||||
if (self->priv->last_scan == 0) {
|
||||
source = g_idle_source_new ();
|
||||
id = g_idle_add (request_scan_results, self);
|
||||
} else {
|
||||
source = g_timeout_source_new (4000);
|
||||
id = g_timeout_add (4000, request_scan_results, self);
|
||||
}
|
||||
g_source_set_callback (source, request_scan_results, self, NULL);
|
||||
id = g_source_attach (source, app_data->main_context);
|
||||
if (id > 0) {
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
self->priv->scan_results_timeout = source;
|
||||
}
|
||||
}
|
||||
|
||||
static guint32
|
||||
wpas_state_string_to_enum (const char * str_state)
|
||||
|
@@ -66,15 +66,12 @@ NMSupplicantManager *
|
||||
nm_supplicant_manager_get (void)
|
||||
{
|
||||
static NMSupplicantManager * singleton = NULL;
|
||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||
|
||||
g_static_mutex_lock (&mutex);
|
||||
if (!singleton) {
|
||||
singleton = NM_SUPPLICANT_MANAGER (g_object_new (NM_TYPE_SUPPLICANT_MANAGER, NULL));
|
||||
} else {
|
||||
g_object_ref (singleton);
|
||||
}
|
||||
g_static_mutex_unlock (&mutex);
|
||||
|
||||
g_assert (singleton);
|
||||
return singleton;
|
||||
@@ -88,7 +85,7 @@ nm_supplicant_manager_init (NMSupplicantManager * self)
|
||||
|
||||
self->priv->dispose_has_run = FALSE;
|
||||
self->priv->state = NM_SUPPLICANT_MANAGER_STATE_DOWN;
|
||||
self->priv->dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
self->priv->dbus_mgr = nm_dbus_manager_get ();
|
||||
|
||||
nm_supplicant_manager_startup (self);
|
||||
|
||||
|
@@ -413,7 +413,7 @@ nm_dbus_vpn_update_one_connection_cb (DBusPendingCall *pcall,
|
||||
if (!dbus_pending_call_get_completed (pcall))
|
||||
goto out;
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("couldn't get the dbus connection.");
|
||||
@@ -511,7 +511,7 @@ nm_dbus_vpn_connections_update_cb (DBusPendingCall *pcall,
|
||||
if (!dbus_pending_call_get_completed (pcall))
|
||||
goto out;
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("couldn't get the dbus connection.");
|
||||
@@ -640,7 +640,7 @@ nm_dbus_vpn_connections_update_from_nmi (NMData *data)
|
||||
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("couldn't get the dbus connection.");
|
||||
@@ -679,16 +679,14 @@ out:
|
||||
void nm_dbus_vpn_schedule_vpn_connections_update (NMData *app_data)
|
||||
{
|
||||
GSource * source = NULL;
|
||||
guint id;
|
||||
|
||||
g_return_if_fail (app_data != NULL);
|
||||
g_return_if_fail (app_data->main_context != NULL);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
/* We want this idle source to run before any other idle source */
|
||||
id = g_idle_add ((GSourceFunc) nm_dbus_vpn_connections_update_from_nmi,
|
||||
app_data);
|
||||
source = g_main_context_find_source_by_id (NULL, id);
|
||||
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||
g_source_set_callback (source, (GSourceFunc) nm_dbus_vpn_connections_update_from_nmi, app_data, NULL);
|
||||
g_source_attach (source, app_data->main_context);
|
||||
g_source_unref (source);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -238,7 +238,7 @@ void nm_vpn_act_request_set_stage (NMVPNActRequest *req, NMVPNActStage stage)
|
||||
NMDBusManager *dbus_mgr;
|
||||
DBusConnection *dbus_connection;
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (dbus_connection) {
|
||||
req->stage = stage;
|
||||
|
@@ -134,7 +134,7 @@ nm_vpn_connection_set_config (NMVPNConnection *connection,
|
||||
g_return_val_if_fail (dev != NULL, FALSE);
|
||||
g_return_val_if_fail (ip4_config != NULL, FALSE);
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("couldn't get dbus connection.");
|
||||
|
@@ -71,7 +71,7 @@ NMVPNManager *nm_vpn_manager_new (NMData *app_data)
|
||||
load_services (manager, manager->service_table);
|
||||
|
||||
manager->dbus_methods = nm_dbus_vpn_methods_setup (manager);
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
nm_dbus_manager_register_method_list (dbus_mgr, manager->dbus_methods);
|
||||
g_object_unref (dbus_mgr);
|
||||
|
||||
@@ -191,7 +191,7 @@ nm_vpn_manager_add_connection (NMVPNManager *manager,
|
||||
if (!(service = nm_vpn_manager_find_service_by_name (manager, service_name)))
|
||||
return NULL;
|
||||
|
||||
dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
dbus_mgr = nm_dbus_manager_get ();
|
||||
dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr);
|
||||
if (!dbus_connection) {
|
||||
nm_warning ("couldn't get dbus connection.");
|
||||
@@ -400,15 +400,10 @@ static gboolean nm_vpn_manager_vpn_activation_failed (gpointer user_data)
|
||||
|
||||
void nm_vpn_manager_schedule_vpn_activation_failed (NMVPNManager *manager, NMVPNActRequest *req)
|
||||
{
|
||||
GSource * source = NULL;
|
||||
|
||||
g_return_if_fail (manager != NULL);
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_callback (source, (GSourceFunc) nm_vpn_manager_vpn_activation_failed, req, NULL);
|
||||
g_source_attach (source, manager->app_data->main_context);
|
||||
g_source_unref (source);
|
||||
g_idle_add (nm_vpn_manager_vpn_activation_failed, req);
|
||||
}
|
||||
|
||||
|
||||
@@ -431,15 +426,10 @@ static gboolean nm_vpn_manager_vpn_connection_died (gpointer user_data)
|
||||
|
||||
void nm_vpn_manager_schedule_vpn_connection_died (NMVPNManager *manager, NMVPNActRequest *req)
|
||||
{
|
||||
GSource * source = NULL;
|
||||
|
||||
g_return_if_fail (manager != NULL);
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_callback (source, (GSourceFunc) nm_vpn_manager_vpn_connection_died, req, NULL);
|
||||
g_source_attach (source, manager->app_data->main_context);
|
||||
g_source_unref (source);
|
||||
g_idle_add (nm_vpn_manager_vpn_connection_died, req);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -104,7 +104,7 @@ NMVPNService *nm_vpn_service_new (NMVPNManager *manager, NMData *app_data)
|
||||
service->state = NM_VPN_STATE_SHUTDOWN;
|
||||
service->app_data = app_data;
|
||||
service->manager = manager;
|
||||
service->dbus_mgr = nm_dbus_manager_get (NULL);
|
||||
service->dbus_mgr = nm_dbus_manager_get ();
|
||||
|
||||
return service;
|
||||
}
|
||||
@@ -390,7 +390,6 @@ out:
|
||||
|
||||
static void nm_vpn_service_schedule_stage1_daemon_exec (NMVPNService *service, NMVPNActRequest *req)
|
||||
{
|
||||
GSource * source = NULL;
|
||||
NMVPNConnection * vpn = NULL;
|
||||
guint id;
|
||||
|
||||
@@ -403,12 +402,10 @@ static void nm_vpn_service_schedule_stage1_daemon_exec (NMVPNService *service, N
|
||||
nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_PREPARE);
|
||||
nm_vpn_service_set_state (service, NM_VPN_STATE_SHUTDOWN);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_callback (source, (GSourceFunc) nm_vpn_service_stage1_daemon_exec, req, NULL);
|
||||
id = g_source_attach (source, service->app_data->main_context);
|
||||
id = g_idle_add (nm_vpn_service_stage1_daemon_exec, req);
|
||||
nm_vpn_act_request_set_callback_id (req, id);
|
||||
g_source_unref (source);
|
||||
nm_info ("VPN Activation (%s) Stage 1 of 4 (Connection Prepare) scheduled...", nm_vpn_connection_get_name (vpn));
|
||||
nm_info ("VPN Activation (%s) Stage 1 of 4 (Connection Prepare) scheduled...",
|
||||
nm_vpn_connection_get_name (vpn));
|
||||
}
|
||||
|
||||
|
||||
@@ -462,7 +459,6 @@ static gboolean nm_vpn_service_stage2_daemon_wait (gpointer user_data)
|
||||
|
||||
static void nm_vpn_service_schedule_stage2_daemon_wait (NMVPNService *service, NMVPNActRequest *req)
|
||||
{
|
||||
GSource * source = NULL;
|
||||
NMVPNConnection * vpn = NULL;
|
||||
guint id;
|
||||
|
||||
@@ -476,12 +472,11 @@ static void nm_vpn_service_schedule_stage2_daemon_wait (NMVPNService *service, N
|
||||
|
||||
nm_vpn_act_request_set_daemon_wait_count (req, nm_vpn_act_request_get_daemon_wait_count (req) + 1);
|
||||
|
||||
source = g_timeout_source_new (200);
|
||||
g_source_set_callback (source, (GSourceFunc) nm_vpn_service_stage2_daemon_wait, req, NULL);
|
||||
id = g_source_attach (source, service->app_data->main_context);
|
||||
id = g_timeout_add (200, nm_vpn_service_stage2_daemon_wait, req);
|
||||
nm_vpn_act_request_set_callback_id (req, id);
|
||||
g_source_unref (source);
|
||||
nm_info ("VPN Activation (%s) Stage 2 of 4 (Connection Prepare Wait) scheduled...", nm_vpn_connection_get_name (vpn));
|
||||
nm_info ("VPN Activation (%s) Stage 2 of 4 (Connection Prepare Wait) "
|
||||
"scheduled...",
|
||||
nm_vpn_connection_get_name (vpn));
|
||||
}
|
||||
|
||||
|
||||
@@ -649,7 +644,6 @@ out:
|
||||
|
||||
static void nm_vpn_service_schedule_stage3_connect (NMVPNService *service, NMVPNActRequest *req)
|
||||
{
|
||||
GSource * source = NULL;
|
||||
NMVPNConnection * vpn = NULL;
|
||||
guint id;
|
||||
|
||||
@@ -661,16 +655,14 @@ static void nm_vpn_service_schedule_stage3_connect (NMVPNService *service, NMVPN
|
||||
|
||||
nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_CONNECT);
|
||||
|
||||
source = g_idle_source_new ();
|
||||
g_source_set_callback (source, (GSourceFunc) nm_vpn_service_stage3_connect, req, NULL);
|
||||
id = g_source_attach (source, service->app_data->main_context);
|
||||
id = g_idle_add (nm_vpn_service_stage3_connect, req);
|
||||
nm_vpn_act_request_set_callback_id (req, id);
|
||||
g_source_unref (source);
|
||||
nm_info ("VPN Activation (%s) Stage 3 of 4 (Connect) scheduled...", nm_vpn_connection_get_name (vpn));
|
||||
nm_info ("VPN Activation (%s) Stage 3 of 4 (Connect) scheduled...",
|
||||
nm_vpn_connection_get_name (vpn));
|
||||
}
|
||||
|
||||
|
||||
static gboolean nm_vpn_service_stage4_ip_config_get_timeout (gpointer *user_data)
|
||||
static gboolean nm_vpn_service_stage4_ip_config_get_timeout (gpointer user_data)
|
||||
{
|
||||
NMVPNActRequest * req = (NMVPNActRequest *) user_data;
|
||||
NMVPNService * service;
|
||||
@@ -701,7 +693,6 @@ static gboolean nm_vpn_service_stage4_ip_config_get_timeout (gpointer *user_data
|
||||
|
||||
static void nm_vpn_service_schedule_stage4_ip_config_get_timeout (NMVPNService *service, NMVPNActRequest *req)
|
||||
{
|
||||
GSource * source = NULL;
|
||||
NMVPNConnection * vpn = NULL;
|
||||
guint id;
|
||||
|
||||
@@ -714,12 +705,11 @@ static void nm_vpn_service_schedule_stage4_ip_config_get_timeout (NMVPNService *
|
||||
nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_IP_CONFIG_GET);
|
||||
|
||||
/* 20 second timeout waiting for IP config signal from VPN service */
|
||||
source = g_timeout_source_new (20000);
|
||||
g_source_set_callback (source, (GSourceFunc) nm_vpn_service_stage4_ip_config_get_timeout, req, NULL);
|
||||
id = g_source_attach (source, service->app_data->main_context);
|
||||
id = g_timeout_add (20000, nm_vpn_service_stage4_ip_config_get_timeout, req);
|
||||
nm_vpn_act_request_set_callback_id (req, id);
|
||||
g_source_unref (source);
|
||||
nm_info ("VPN Activation (%s) Stage 4 of 4 (IP Config Get) timeout scheduled...", nm_vpn_connection_get_name (vpn));
|
||||
nm_info ("VPN Activation (%s) Stage 4 of 4 (IP Config Get) timeout "
|
||||
" scheduled...",
|
||||
nm_vpn_connection_get_name (vpn));
|
||||
}
|
||||
|
||||
|
||||
@@ -730,12 +720,12 @@ static void nm_vpn_service_cancel_callback (NMVPNService *service, NMVPNActReque
|
||||
g_return_if_fail (service != NULL);
|
||||
g_return_if_fail (req != NULL);
|
||||
|
||||
if ((id = nm_vpn_act_request_get_callback_id (req)) != 0)
|
||||
{
|
||||
g_source_destroy (g_main_context_find_source_by_id (service->app_data->main_context, id));
|
||||
if ((id = nm_vpn_act_request_get_callback_id (req)) == 0)
|
||||
return;
|
||||
|
||||
g_source_destroy (g_main_context_find_source_by_id (NULL, id));
|
||||
nm_vpn_act_request_set_callback_id (req, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
|
Reference in New Issue
Block a user