summary refs log tree commit diff
path: root/src/nm-connectivity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nm-connectivity.c')
-rw-r--r--src/nm-connectivity.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c
index 694733f6..ccac6376 100644
--- a/src/nm-connectivity.c
+++ b/src/nm-connectivity.c
@@ -1,19 +1,5 @@
-/* NetworkManager -- Network link manager
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+// SPDX-License-Identifier: GPL-2.0+
+/*
  * Copyright (C) 2011 Thomas Bechtold <thomasbechtold@jpberlin.de>
  * Copyright (C) 2011 Dan Williams <dcbw@redhat.com>
  * Copyright (C) 2016 - 2018 Red Hat, Inc.
@@ -27,6 +13,7 @@
 #include <curl/curl.h>
 #endif
 #include <linux/rtnetlink.h>
+#include <glib-unix.h>
 
 #include "c-list/src/c-list.h"
 #include "nm-core-internal.h"
@@ -327,7 +314,6 @@ _con_curl_check_connectivity (CURLM *mhandle, int sockfd, int ev_bitmask)
 {
 	NMConnectivityCheckHandle *cb_data;
 	CURLMsg *msg;
-	CURLcode eret;
 	int m_left;
 	long response_code;
 	CURLMcode ret;
@@ -336,12 +322,13 @@ _con_curl_check_connectivity (CURLM *mhandle, int sockfd, int ev_bitmask)
 
 	ret = curl_multi_socket_action (mhandle, sockfd, ev_bitmask, &running_handles);
 	if (ret != CURLM_OK) {
-		_LOGD ("connectivity check failed: (%d) %s", ret, curl_easy_strerror (ret));
+		_LOGD ("connectivity check failed: (%d) %s", ret, curl_multi_strerror (ret));
 		success = FALSE;
 	}
 
 	while ((msg = curl_multi_info_read (mhandle, &m_left))) {
 		const char *response;
+		CURLcode eret;
 
 		if (msg->msg != CURLMSG_DONE)
 			continue;
@@ -422,10 +409,9 @@ _con_curl_timeout_cb (gpointer user_data)
 {
 	NMConnectivityCheckHandle *cb_data = user_data;
 
-	cb_data->concheck.curl_timer = 0;
 	_con_curl_check_connectivity (cb_data->concheck.curl_mhandle, CURL_SOCKET_TIMEOUT, 0);
 	_complete_queued (cb_data->self);
-	return G_SOURCE_REMOVE;
+	return G_SOURCE_CONTINUE;
 }
 
 static int
@@ -441,7 +427,8 @@ multi_timer_cb (CURLM *multi, long timeout_ms, void *userdata)
 
 typedef struct {
 	NMConnectivityCheckHandle *cb_data;
-	GIOChannel *ch;
+
+	GSource *source;
 
 	/* this is a very simplistic weak-pointer. If ConCurlSockData gets
 	 * destroyed, it will set *destroy_notify to TRUE.
@@ -450,15 +437,15 @@ typedef struct {
 	 * safely access @fdp after _con_curl_check_connectivity(). */
 	gboolean *destroy_notify;
 
-	guint ev;
 } ConCurlSockData;
 
 static gboolean
-_con_curl_socketevent_cb (GIOChannel *ch, GIOCondition condition, gpointer user_data)
+_con_curl_socketevent_cb (int fd,
+                          GIOCondition condition,
+                          gpointer user_data)
 {
 	ConCurlSockData *fdp = user_data;
 	NMConnectivityCheckHandle *cb_data = fdp->cb_data;
-	int fd = g_io_channel_unix_get_fd (ch);
 	int action = 0;
 	gboolean fdp_destroyed = FALSE;
 	gboolean success;
@@ -482,12 +469,12 @@ _con_curl_socketevent_cb (GIOChannel *ch, GIOCondition condition, gpointer user_
 		nm_assert (fdp->destroy_notify == &fdp_destroyed);
 		fdp->destroy_notify = NULL;
 		if (!success)
-			fdp->ev = 0;
+			nm_clear_g_source_inst (&fdp->source);
 	}
 
 	_complete_queued (cb_data->self);
 
-	return success ? G_SOURCE_CONTINUE : G_SOURCE_REMOVE;
+	return G_SOURCE_CONTINUE;
 }
 
 static int
@@ -495,7 +482,6 @@ multi_socket_cb (CURL *e_handle, curl_socket_t fd, int what, void *userdata, voi
 {
 	NMConnectivityCheckHandle *cb_data = userdata;
 	ConCurlSockData *fdp = socketp;
-	GIOCondition condition = 0;
 
 	(void) _NM_ENSURE_TYPE (int, fd);
 
@@ -503,19 +489,21 @@ multi_socket_cb (CURL *e_handle, curl_socket_t fd, int what, void *userdata, voi
 		if (fdp) {
 			if (fdp->destroy_notify)
 				*fdp->destroy_notify = TRUE;
+			nm_clear_g_source_inst (&fdp->source);
 			curl_multi_assign (cb_data->concheck.curl_mhandle, fd, NULL);
-			nm_clear_g_source (&fdp->ev);
-			g_io_channel_unref (fdp->ch);
 			g_slice_free (ConCurlSockData, fdp);
 		}
 	} else {
+		GIOCondition condition;
+
 		if (!fdp) {
-			fdp = g_slice_new0 (ConCurlSockData);
-			fdp->cb_data = cb_data;
-			fdp->ch = g_io_channel_unix_new (fd);
+			fdp = g_slice_new (ConCurlSockData);
+			*fdp = (ConCurlSockData) {
+				.cb_data = cb_data,
+			};
 			curl_multi_assign (cb_data->concheck.curl_mhandle, fd, fdp);
 		} else
-			nm_clear_g_source (&fdp->ev);
+			nm_clear_g_source_inst (&fdp->source);
 
 		if (what == CURL_POLL_IN)
 			condition = G_IO_IN;
@@ -523,9 +511,14 @@ multi_socket_cb (CURL *e_handle, curl_socket_t fd, int what, void *userdata, voi
 			condition = G_IO_OUT;
 		else if (what == CURL_POLL_INOUT)
 			condition = G_IO_IN | G_IO_OUT;
+		else
+			condition = 0;
 
-		if (condition)
-			fdp->ev = g_io_add_watch (fdp->ch, condition, _con_curl_socketevent_cb, fdp);
+		if (condition) {
+			fdp->source = g_unix_fd_source_new (fd, condition);
+			g_source_set_callback (fdp->source, G_SOURCE_FUNC (_con_curl_socketevent_cb), fdp, NULL);
+			g_source_attach (fdp->source, NULL);
+		}
 	}
 
 	return CURLM_OK;