summary refs log tree commit diff
path: root/src/devices/nm-acd-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/nm-acd-manager.c')
-rw-r--r--src/devices/nm-acd-manager.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/devices/nm-acd-manager.c b/src/devices/nm-acd-manager.c
index 6e7a2a0f..735dd25b 100644
--- a/src/devices/nm-acd-manager.c
+++ b/src/devices/nm-acd-manager.c
@@ -38,8 +38,7 @@ struct _NMAcdManager {
 	GHashTable    *addresses;
 	guint          completed;
 	NAcd          *acd;
-	GIOChannel    *channel;
-	guint          event_id;
+	GSource       *event_source;
 
 	NMAcdCallbacks callbacks;
 	gpointer user_data;
@@ -157,7 +156,9 @@ nm_acd_manager_add_address (NMAcdManager *self, in_addr_t address)
 }
 
 static gboolean
-acd_event (GIOChannel *source, GIOCondition condition, gpointer data)
+acd_event (int fd,
+           GIOCondition condition,
+           gpointer data)
 {
 	NMAcdManager *self = data;
 	NAcdEvent *event;
@@ -183,12 +184,12 @@ acd_event (GIOChannel *source, GIOCondition condition, gpointer data)
 				r = n_acd_probe_announce (info->probe, N_ACD_DEFEND_ONCE);
 				if (r) {
 					_LOGW ("couldn't announce address %s on interface '%s': %s",
-					       nm_utils_inet4_ntop (info->address, address_str),
+					       _nm_utils_inet4_ntop (info->address, address_str),
 					       nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex),
 					       acd_error_to_string (r));
 				} else {
 					_LOGD ("announcing address %s",
-					       nm_utils_inet4_ntop (info->address, address_str));
+					       _nm_utils_inet4_ntop (info->address, address_str));
 				}
 			}
 			check_probing_done = TRUE;
@@ -201,14 +202,14 @@ acd_event (GIOChannel *source, GIOCondition condition, gpointer data)
 		case N_ACD_EVENT_DEFENDED:
 			n_acd_probe_get_userdata (event->defended.probe, (void **) &info);
 			_LOGD ("defended address %s from host %s",
-			       nm_utils_inet4_ntop (info->address, address_str),
+			       _nm_utils_inet4_ntop (info->address, address_str),
 			       (hwaddr_str = nm_utils_hwaddr_ntoa (event->defended.sender,
 			                                           event->defended.n_sender)));
 			break;
 		case N_ACD_EVENT_CONFLICT:
 			n_acd_probe_get_userdata (event->conflict.probe, (void **) &info);
 			_LOGW ("conflict for address %s detected with host %s on interface '%s'",
-			       nm_utils_inet4_ntop (info->address, address_str),
+			       _nm_utils_inet4_ntop (info->address, address_str),
 			       (hwaddr_str = nm_utils_hwaddr_ntoa (event->defended.sender,
 			                                           event->defended.n_sender)),
 			       nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex));
@@ -248,7 +249,7 @@ acd_probe_add (NMAcdManager *self,
 	r = n_acd_probe_config_new (&probe_config);
 	if (r) {
 		_LOGW ("could not create probe config for %s on interface '%s': %s",
-		       nm_utils_inet4_ntop (info->address, sbuf),
+		       _nm_utils_inet4_ntop (info->address, sbuf),
 		       nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex),
 		       acd_error_to_string (r));
 		return FALSE;
@@ -260,7 +261,7 @@ acd_probe_add (NMAcdManager *self,
 	r = n_acd_probe (self->acd, &info->probe, probe_config);
 	if (r) {
 		_LOGW ("could not start probe for %s on interface '%s': %s",
-		       nm_utils_inet4_ntop (info->address, sbuf),
+		       _nm_utils_inet4_ntop (info->address, sbuf),
 		       nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex),
 		       acd_error_to_string (r));
 		n_acd_probe_config_free (probe_config);
@@ -334,11 +335,15 @@ nm_acd_manager_start_probe (NMAcdManager *self, guint timeout)
 	if (success)
 		self->state = STATE_PROBING;
 
-	nm_assert (!self->channel);
-	nm_assert (self->event_id == 0);
+	nm_assert (!self->event_source);
 	n_acd_get_fd (self->acd, &fd);
-	self->channel = g_io_channel_unix_new (fd);
-	self->event_id = g_io_add_watch (self->channel, G_IO_IN, acd_event, self);
+	self->event_source = nm_g_unix_fd_source_new (fd,
+	                                              G_IO_IN,
+	                                              G_PRIORITY_DEFAULT,
+	                                              acd_event,
+	                                              self,
+	                                              NULL);
+	g_source_attach (self->event_source, NULL);
 
 	return success ? 0 : -NME_UNSPEC;
 }
@@ -412,20 +417,24 @@ nm_acd_manager_announce_addresses (NMAcdManager *self)
 			r = n_acd_probe_announce (info->probe, N_ACD_DEFEND_ONCE);
 			if (r) {
 				_LOGW ("couldn't announce address %s on interface '%s': %s",
-				       nm_utils_inet4_ntop (info->address, sbuf),
+				       _nm_utils_inet4_ntop (info->address, sbuf),
 				       nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex),
 				       acd_error_to_string (r));
 				success = FALSE;
 			} else
-				_LOGD ("announcing address %s", nm_utils_inet4_ntop (info->address, sbuf));
+				_LOGD ("announcing address %s", _nm_utils_inet4_ntop (info->address, sbuf));
 		}
 	}
 
-	if (!self->channel) {
-		nm_assert (self->event_id == 0);
+	if (!self->event_source) {
 		n_acd_get_fd (self->acd, &fd);
-		self->channel = g_io_channel_unix_new (fd);
-		self->event_id = g_io_add_watch (self->channel, G_IO_IN, acd_event, self);
+		self->event_source = nm_g_unix_fd_source_new (fd,
+		                                              G_IO_IN,
+		                                              G_PRIORITY_DEFAULT,
+		                                              acd_event,
+		                                              self,
+		                                              NULL);
+		g_source_attach (self->event_source, NULL);
 	}
 
 	return success ? 0 : -NME_UNSPEC;
@@ -479,8 +488,7 @@ nm_acd_manager_free (NMAcdManager *self)
 		self->callbacks.user_data_destroy (self->user_data);
 
 	nm_clear_pointer (&self->addresses, g_hash_table_destroy);
-	nm_clear_pointer (&self->channel, g_io_channel_unref);
-	nm_clear_g_source (&self->event_id);
+	nm_clear_g_source_inst (&self->event_source);
 	nm_clear_pointer (&self->acd, n_acd_unref);
 
 	g_slice_free (NMAcdManager, self);