2005-04-15 Dan Williams <dcbw@redhat.com>
Patches from Tom Parker: - Fix memleaks - Join with worker thread rather than polling for its exit Patch from Bill Moss: - Cull duplicate ESSIDs from the scan list, taking highest strength AP git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@573 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
2005-04-15 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
|
Patches from Tom Parker:
|
||||||
|
- Fix memleaks
|
||||||
|
- Join with worker thread rather than polling for its exit
|
||||||
|
|
||||||
|
Patch from Bill Moss:
|
||||||
|
- Cull duplicate ESSIDs from the scan list, taking highest strength AP
|
||||||
|
|
||||||
2005-04-15 Dan Williams <dcbw@redhat.com>
|
2005-04-15 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
- Fixes to pass 'make distcheck'
|
- Fixes to pass 'make distcheck'
|
||||||
|
@@ -529,6 +529,8 @@ static void nm_data_free (NMData *data)
|
|||||||
g_main_loop_unref (data->main_loop);
|
g_main_loop_unref (data->main_loop);
|
||||||
g_main_context_unref (data->main_context);
|
g_main_context_unref (data->main_context);
|
||||||
|
|
||||||
|
g_io_channel_unref(data->sigterm_iochannel);
|
||||||
|
|
||||||
memset (data, 0, sizeof (NMData));
|
memset (data, 0, sizeof (NMData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -116,6 +116,7 @@ void nm_ap_list_unref (NMAccessPointList *list)
|
|||||||
nm_unlock_mutex (list->mutex, __FUNCTION__);
|
nm_unlock_mutex (list->mutex, __FUNCTION__);
|
||||||
|
|
||||||
g_mutex_free (list->mutex);
|
g_mutex_free (list->mutex);
|
||||||
|
g_free(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,6 +227,80 @@ void nm_ap_list_remove_ap_by_essid (NMAccessPointList *list, const char *network
|
|||||||
nm_ap_list_unlock (list);
|
nm_ap_list_unlock (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* nm_ap_list_remove_duplicate_essids
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list)
|
||||||
|
{
|
||||||
|
NMAccessPoint *removal_ap;
|
||||||
|
NMAccessPoint *list_ap_max;
|
||||||
|
GSList *elt_i = NULL;
|
||||||
|
GSList *elt_j = NULL;
|
||||||
|
GSList *elt_max = NULL;
|
||||||
|
GSList *removal_list = NULL;
|
||||||
|
GSList *elt;
|
||||||
|
gint8 max_strength = 0;
|
||||||
|
gint8 strengthj = 0;
|
||||||
|
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
|
||||||
|
if ((found = (nm_null_safe_strcmp (nm_ap_get_essid (list_ap_i), nm_ap_get_essid (list_ap_j)) == 0)))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
elt_max = elt_i;
|
||||||
|
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);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
removal_list = g_slist_append (removal_list, list_ap_max);
|
||||||
|
list_ap_max = list_ap_j;
|
||||||
|
max_strength = strengthj;
|
||||||
|
}
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
if ((removal_ap = (NMAccessPoint *)(elt->data)))
|
||||||
|
{
|
||||||
|
nm_ap_list_remove_ap (list, removal_ap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_slist_free (removal_list);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_ap_list_get_ap_by_essid
|
* nm_ap_list_get_ap_by_essid
|
||||||
@@ -416,7 +491,7 @@ void nm_ap_list_populate_from_nmi (NMAccessPointList *list, NMData *data)
|
|||||||
gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *merge_ap,
|
gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *merge_ap,
|
||||||
gboolean *new, gboolean *strength_changed)
|
gboolean *new, gboolean *strength_changed)
|
||||||
{
|
{
|
||||||
NMAccessPoint *list_ap;
|
NMAccessPoint *list_ap_addr, *list_ap_essid;
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
|
|
||||||
g_return_val_if_fail (list != NULL, FALSE);
|
g_return_val_if_fail (list != NULL, FALSE);
|
||||||
@@ -424,41 +499,62 @@ gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *me
|
|||||||
g_return_val_if_fail (new != NULL, FALSE);
|
g_return_val_if_fail (new != NULL, FALSE);
|
||||||
g_return_val_if_fail (strength_changed != NULL, FALSE);
|
g_return_val_if_fail (strength_changed != NULL, FALSE);
|
||||||
|
|
||||||
if (!(list_ap = nm_ap_list_get_ap_by_address (list, nm_ap_get_address (merge_ap))))
|
if ((list_ap_addr = nm_ap_list_get_ap_by_address (list, nm_ap_get_address (merge_ap))))
|
||||||
list_ap = nm_ap_list_get_ap_by_essid (list, nm_ap_get_essid (merge_ap));
|
|
||||||
|
|
||||||
if (list_ap)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* First, we check for an address match. If the merge AP has the
|
||||||
|
* same address as a list AP, the merge AP and the list AP
|
||||||
|
* must be the same physical AP. The list AP properties must be from
|
||||||
|
* a previous scan so the time_last_seen's are not equal.
|
||||||
|
* Update encryption, authentication method,
|
||||||
|
* strength, and the time_last_seen. */
|
||||||
|
|
||||||
const GTimeVal *merge_ap_seen = nm_ap_get_last_seen (merge_ap);
|
const GTimeVal *merge_ap_seen = nm_ap_get_last_seen (merge_ap);
|
||||||
const GTimeVal *list_ap_seen = nm_ap_get_last_seen (list_ap);
|
const GTimeVal *list_ap_addr_seen = nm_ap_get_last_seen (list_ap_addr);
|
||||||
|
|
||||||
/* Merge some properties on the AP that are new from scan to scan. */
|
nm_ap_set_encrypted (list_ap_addr, nm_ap_get_encrypted (merge_ap));
|
||||||
nm_ap_set_encrypted (list_ap, nm_ap_get_encrypted (merge_ap));
|
nm_ap_set_auth_method (list_ap_addr, nm_ap_get_auth_method (merge_ap));
|
||||||
nm_ap_set_auth_method (list_ap, nm_ap_get_auth_method (merge_ap));
|
if (nm_ap_get_strength (merge_ap) != nm_ap_get_strength (list_ap_addr))
|
||||||
|
|
||||||
/* Don't update the strength on the existing AP if the timestamp is
|
|
||||||
* the same as the AP we're going to merge (which means that they were
|
|
||||||
* found in the same scan, have the same ESSID, but are different APs)
|
|
||||||
* and the existing AP's strength is greater than the one we're about
|
|
||||||
* to merge. This helps keep the ESSID's reported strength that of the
|
|
||||||
* strongest AP we can see.
|
|
||||||
*/
|
|
||||||
if (!( (list_ap_seen->tv_sec == merge_ap_seen->tv_sec)
|
|
||||||
&& (nm_ap_get_strength (list_ap) > nm_ap_get_strength (merge_ap))))
|
|
||||||
{
|
{
|
||||||
nm_ap_set_strength (list_ap, nm_ap_get_strength (merge_ap));
|
nm_ap_set_strength (list_ap_addr, nm_ap_get_strength (merge_ap));
|
||||||
*strength_changed = TRUE;
|
*strength_changed = TRUE;
|
||||||
}
|
}
|
||||||
|
nm_ap_set_last_seen (list_ap_addr, merge_ap_seen);
|
||||||
|
}
|
||||||
|
else if ((list_ap_essid = nm_ap_list_get_ap_by_essid (list, nm_ap_get_essid (merge_ap))))
|
||||||
|
{
|
||||||
|
|
||||||
nm_ap_set_last_seen (list_ap, merge_ap_seen);
|
/* Second, we check for an ESSID match. In this case,
|
||||||
|
* a list AP has the same non-NULL ESSID as the merge AP. Update the
|
||||||
|
* encryption and authentication method. Update the strength and address
|
||||||
|
* except when the time_last_seen of the list AP is the same as the
|
||||||
|
* time_last_seen of the merge AP and the strength of the list AP is greater
|
||||||
|
* than or equal to the strength of the merge AP. If the time_last_seen's are
|
||||||
|
* equal, the merge AP and the list AP come from the same scan.
|
||||||
|
* Update the time_last_seen. */
|
||||||
|
|
||||||
|
const GTimeVal *merge_ap_seen = nm_ap_get_last_seen (merge_ap);
|
||||||
|
const GTimeVal *list_ap_essid_seen = nm_ap_get_last_seen (list_ap_essid);
|
||||||
|
|
||||||
|
nm_ap_set_encrypted (list_ap_essid, nm_ap_get_encrypted (merge_ap));
|
||||||
|
nm_ap_set_auth_method (list_ap_essid, nm_ap_get_auth_method (merge_ap));
|
||||||
|
|
||||||
|
if (!((list_ap_essid_seen->tv_sec == merge_ap_seen->tv_sec)
|
||||||
|
&& (nm_ap_get_strength (list_ap_essid) >= nm_ap_get_strength (merge_ap))))
|
||||||
|
{
|
||||||
|
nm_ap_set_strength (list_ap_essid, nm_ap_get_strength (merge_ap));
|
||||||
|
nm_ap_set_address (list_ap_essid, nm_ap_get_address (merge_ap));
|
||||||
|
*strength_changed = TRUE;
|
||||||
|
}
|
||||||
|
nm_ap_set_last_seen (list_ap_essid, merge_ap_seen);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Add the whole AP, list takes ownership. */
|
/* Add the merge AP to the list. */
|
||||||
|
|
||||||
nm_ap_list_append_ap (list, merge_ap);
|
nm_ap_list_append_ap (list, merge_ap);
|
||||||
*new = TRUE;
|
*new = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,6 +39,7 @@ gboolean nm_ap_list_is_empty (NMAccessPointList *list);
|
|||||||
void nm_ap_list_append_ap (NMAccessPointList *list, NMAccessPoint *ap);
|
void nm_ap_list_append_ap (NMAccessPointList *list, NMAccessPoint *ap);
|
||||||
void nm_ap_list_remove_ap (NMAccessPointList *list, NMAccessPoint *ap);
|
void nm_ap_list_remove_ap (NMAccessPointList *list, NMAccessPoint *ap);
|
||||||
void nm_ap_list_remove_ap_by_essid (NMAccessPointList *list, const char *network);
|
void nm_ap_list_remove_ap_by_essid (NMAccessPointList *list, const char *network);
|
||||||
|
void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list);
|
||||||
|
|
||||||
NMAccessPoint * nm_ap_list_get_ap_by_essid (NMAccessPointList *list, const char *network);
|
NMAccessPoint * nm_ap_list_get_ap_by_essid (NMAccessPointList *list, const char *network);
|
||||||
NMAccessPoint * nm_ap_list_get_ap_by_address (NMAccessPointList *list, const struct ether_addr *addr);
|
NMAccessPoint * nm_ap_list_get_ap_by_address (NMAccessPointList *list, const struct ether_addr *addr);
|
||||||
|
@@ -383,7 +383,8 @@ NMDevice *nm_device_new (const char *iface, const char *udi, gboolean test_dev,
|
|||||||
dev->system_config_data = nm_system_device_get_system_config (dev);
|
dev->system_config_data = nm_system_device_get_system_config (dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_thread_create (nm_device_worker, dev, FALSE, &error))
|
dev->worker = g_thread_create (nm_device_worker, dev, TRUE, &error);
|
||||||
|
if (!dev->worker)
|
||||||
{
|
{
|
||||||
nm_error ("could not create device worker thread. (glib said: '%s')", error->message);
|
nm_error ("could not create device worker thread. (glib said: '%s')", error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
@@ -518,7 +519,6 @@ static gpointer nm_device_worker (gpointer user_data)
|
|||||||
dev->loop = NULL;
|
dev->loop = NULL;
|
||||||
dev->context = NULL;
|
dev->context = NULL;
|
||||||
|
|
||||||
dev->worker_done = TRUE;
|
|
||||||
nm_device_unref (dev);
|
nm_device_unref (dev);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -531,9 +531,8 @@ void nm_device_worker_thread_stop (NMDevice *dev)
|
|||||||
|
|
||||||
if (dev->loop)
|
if (dev->loop)
|
||||||
g_main_loop_quit (dev->loop);
|
g_main_loop_quit (dev->loop);
|
||||||
nm_wait_for_completion(NM_COMPLETION_TRIES_INFINITY, 300,
|
g_thread_join(dev->worker);
|
||||||
nm_completion_boolean_test, NULL, &dev->worker_done,
|
dev->worker = NULL;
|
||||||
NULL, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -849,6 +848,7 @@ static gboolean nm_device_probe_wired_link_state (NMDevice *dev)
|
|||||||
link = (gboolean) atoi (contents);
|
link = (gboolean) atoi (contents);
|
||||||
g_free (contents);
|
g_free (contents);
|
||||||
}
|
}
|
||||||
|
g_free(carrier_path);
|
||||||
|
|
||||||
/* We say that non-carrier-detect devices always have a link, because
|
/* We say that non-carrier-detect devices always have a link, because
|
||||||
* they never get auto-selected by NM. User has to force them on us,
|
* they never get auto-selected by NM. User has to force them on us,
|
||||||
|
@@ -101,7 +101,7 @@ struct NMDevice
|
|||||||
|
|
||||||
GMainContext *context;
|
GMainContext *context;
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
gboolean worker_done;
|
GThread *worker;
|
||||||
gboolean worker_started;
|
gboolean worker_started;
|
||||||
guint renew_timeout;
|
guint renew_timeout;
|
||||||
guint rebind_timeout;
|
guint rebind_timeout;
|
||||||
|
@@ -515,6 +515,8 @@ static gboolean nm_policy_allowed_ap_list_update (gpointer user_data)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
nm_device_copy_allowed_to_dev_list (dev, data->allowed_ap_list);
|
nm_device_copy_allowed_to_dev_list (dev, data->allowed_ap_list);
|
||||||
|
|
||||||
|
nm_ap_list_remove_duplicate_essids (nm_device_ap_list_get (dev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -448,6 +448,7 @@ char *nm_get_device_driver_name (LibHalContext *ctx, NMDevice *dev)
|
|||||||
|
|
||||||
if (parent_udi && libhal_device_property_exists (ctx, parent_udi, "info.linux.driver", NULL))
|
if (parent_udi && libhal_device_property_exists (ctx, parent_udi, "info.linux.driver", NULL))
|
||||||
driver_name = libhal_device_get_property_string (ctx, parent_udi, "info.linux.driver", NULL);
|
driver_name = libhal_device_get_property_string (ctx, parent_udi, "info.linux.driver", NULL);
|
||||||
|
g_free(parent_udi);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (driver_name);
|
return (driver_name);
|
||||||
|
@@ -569,7 +569,7 @@ nm_netlink_monitor_event_handler (GIOChannel *channel,
|
|||||||
NmNetlinkMonitor *monitor)
|
NmNetlinkMonitor *monitor)
|
||||||
{
|
{
|
||||||
GError *error;
|
GError *error;
|
||||||
gchar *received_bytes;
|
gchar *received_bytes=NULL;
|
||||||
gboolean processing_is_done;
|
gboolean processing_is_done;
|
||||||
gsize num_received_bytes;
|
gsize num_received_bytes;
|
||||||
guint num_bytes_to_process;
|
guint num_bytes_to_process;
|
||||||
@@ -711,6 +711,7 @@ nm_netlink_monitor_event_handler (GIOChannel *channel,
|
|||||||
g_free (interface_name);
|
g_free (interface_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
g_free(received_bytes);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user