diff options
author | Thomas Haller <thaller@redhat.com> | 2020-01-13 15:49:27 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-01-13 15:49:27 +0100 |
commit | 56e91b11a24f87e57ee0ae9535c081796e4bdeb9 (patch) | |
tree | ef7884e0b2b704e2220d72a95645684dc636b8a7 | |
parent | d63cd26e6042b94485b5024595b685fd0a5f7e34 (diff) | |
parent | 5af17d80f372f691a29629075d7c2e073bc306aa (diff) | |
download | NetworkManager-56e91b11a24f87e57ee0ae9535c081796e4bdeb9.tar.gz |
all: merge branch 'th/unix-fd-source'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/378
-rw-r--r-- | clients/cli/common.c | 20 | ||||
-rw-r--r-- | clients/cloud-setup/nm-http-client.c | 9 | ||||
-rw-r--r-- | clients/common/nm-polkit-listener.c | 26 | ||||
-rw-r--r-- | clients/tui/newt/nmt-newt-form.c | 24 | ||||
-rw-r--r-- | libnm-core/tests/test-general.c | 17 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.c | 20 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 9 | ||||
-rw-r--r-- | shared/nm-test-utils-impl.c | 2 | ||||
-rw-r--r-- | shared/nm-udev-aux/nm-udev-utils.c | 20 | ||||
-rw-r--r-- | src/devices/bluetooth/nm-bluez5-dun.c | 112 | ||||
-rw-r--r-- | src/devices/nm-acd-manager.c | 34 | ||||
-rw-r--r-- | src/dhcp/nm-dhcp-nettools.c | 18 | ||||
-rw-r--r-- | src/ndisc/nm-lndp-ndisc.c | 33 | ||||
-rw-r--r-- | src/nm-connectivity.c | 8 | ||||
-rw-r--r-- | src/nm-session-monitor.c | 22 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 40 |
16 files changed, 240 insertions, 174 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c index 452f04f624..a5d9bcbb1a 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -864,7 +864,9 @@ readline_cb (char *line) } static gboolean -stdin_ready_cb (GIOChannel * io, GIOCondition condition, gpointer data) +stdin_ready_cb (int fd, + GIOCondition condition, + gpointer data) { rl_callback_read_char (); return TRUE; @@ -874,14 +876,17 @@ static char * nmc_readline_helper (const NmcConfig *nmc_config, const char *prompt) { - GIOChannel *io = NULL; - guint io_watch_id; + GSource *io_source; nmc_set_in_readline (TRUE); - io = g_io_channel_unix_new (STDIN_FILENO); - io_watch_id = g_io_add_watch (io, G_IO_IN, stdin_ready_cb, NULL); - g_io_channel_unref (io); + io_source = nm_g_unix_fd_source_new (STDIN_FILENO, + G_IO_IN, + G_PRIORITY_DEFAULT, + stdin_ready_cb, + NULL, + NULL); + g_source_attach (io_source, NULL); read_again: rl_string = NULL; @@ -930,7 +935,8 @@ read_again: rl_string = NULL; } - g_source_remove (io_watch_id); + nm_clear_g_source_inst (&io_source); + nmc_set_in_readline (FALSE); return rl_string; diff --git a/clients/cloud-setup/nm-http-client.c b/clients/cloud-setup/nm-http-client.c index 943310955a..9ceb26c3b2 100644 --- a/clients/cloud-setup/nm-http-client.c +++ b/clients/cloud-setup/nm-http-client.c @@ -5,7 +5,6 @@ #include "nm-http-client.h" #include <curl/curl.h> -#include <glib-unix.h> #include "nm-cloud-setup-utils.h" @@ -636,8 +635,12 @@ _mhandle_socketfunction_cb (CURL *e_handle, curl_socket_t fd, int what, void *us condition = 0; if (condition) { - priv->mhandle_source_socket = g_unix_fd_source_new (fd, condition); - g_source_set_callback (priv->mhandle_source_socket, G_SOURCE_FUNC (_mhandle_socket_cb), self, NULL); + priv->mhandle_source_socket = nm_g_unix_fd_source_new (fd, + condition, + G_PRIORITY_DEFAULT, + _mhandle_socket_cb, + self, + NULL); g_source_attach (priv->mhandle_source_socket, priv->context); } } diff --git a/clients/common/nm-polkit-listener.c b/clients/common/nm-polkit-listener.c index 6c635e0c0a..58684015c5 100644 --- a/clients/common/nm-polkit-listener.c +++ b/clients/common/nm-polkit-listener.c @@ -23,8 +23,8 @@ #include "nm-polkit-listener.h" #include <gio/gio.h> -#include <glib-unix.h> #include <pwd.h> +#include <fcntl.h> #include "nm-glib-aux/nm-dbus-aux.h" #include "nm-glib-aux/nm-secret-utils.h" @@ -443,12 +443,12 @@ queue_string_to_helper (AuthRequest *request, const char *response) g_string_append_c (request->out_buffer, '\n'); if (!request->child_stdin_watch_source) { - request->child_stdin_watch_source = g_unix_fd_source_new (request->child_stdin, - G_IO_OUT | G_IO_ERR | G_IO_HUP); - g_source_set_callback (request->child_stdin_watch_source, - G_SOURCE_FUNC (io_watch_can_write), - request, - NULL); + request->child_stdin_watch_source = nm_g_unix_fd_source_new (request->child_stdin, + G_IO_OUT | G_IO_ERR | G_IO_HUP, + G_PRIORITY_DEFAULT, + io_watch_can_write, + request, + NULL); g_source_attach (request->child_stdin_watch_source, request->listener->main_context); } @@ -570,12 +570,12 @@ begin_authentication (AuthRequest *request) fd_flags = fcntl (request->child_stdout, F_GETFD, 0); fcntl (request->child_stdout, F_SETFL, fd_flags | O_NONBLOCK); - request->child_stdout_watch_source = g_unix_fd_source_new (request->child_stdout, - G_IO_IN | G_IO_ERR | G_IO_HUP); - g_source_set_callback (request->child_stdout_watch_source, - G_SOURCE_FUNC (io_watch_have_data), - request, - NULL); + request->child_stdout_watch_source = nm_g_unix_fd_source_new (request->child_stdout, + G_IO_IN | G_IO_ERR | G_IO_HUP, + G_PRIORITY_DEFAULT, + io_watch_have_data, + request, + NULL); g_source_attach (request->child_stdout_watch_source, request->listener->main_context); diff --git a/clients/tui/newt/nmt-newt-form.c b/clients/tui/newt/nmt-newt-form.c index 881b6f5ddc..2142e3c567 100644 --- a/clients/tui/newt/nmt-newt-form.c +++ b/clients/tui/newt/nmt-newt-form.c @@ -312,9 +312,9 @@ static GSList *form_stack; static GSource *keypress_source; static gboolean -nmt_newt_form_keypress_callback (int fd, +nmt_newt_form_keypress_callback (int fd, GIOCondition condition, - gpointer user_data) + gpointer user_data) { g_return_val_if_fail (form_stack != NULL, FALSE); @@ -340,16 +340,14 @@ static void nmt_newt_form_real_show (NmtNewtForm *form) { if (!keypress_source) { - GIOChannel *io; - - io = g_io_channel_unix_new (STDIN_FILENO); - keypress_source = g_io_create_watch (io, G_IO_IN); + keypress_source = nm_g_unix_fd_source_new (STDIN_FILENO, + G_IO_IN, + G_PRIORITY_DEFAULT, + nmt_newt_form_keypress_callback, + NULL, + NULL); g_source_set_can_recurse (keypress_source, TRUE); - g_source_set_callback (keypress_source, - (GSourceFunc)(void (*) (void)) nmt_newt_form_keypress_callback, - NULL, NULL); g_source_attach (keypress_source, NULL); - g_io_channel_unref (io); } nmt_newt_form_build (form); @@ -416,10 +414,8 @@ nmt_newt_form_quit (NmtNewtForm *form) if (form_stack) nmt_newt_form_iterate (form_stack->data); - else if (keypress_source) { - g_source_destroy (keypress_source); - g_clear_pointer (&keypress_source, g_source_unref); - } + else + nm_clear_g_source_inst (&keypress_source); g_signal_emit (form, signals[QUIT], 0); g_object_unref (form); diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index e1cafb14b4..1bdaf5bd62 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -10,7 +10,6 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <glib-unix.h> #include "nm-std-aux/c-list-util.h" #include "nm-glib-aux/nm-enum-utils.h" @@ -8199,8 +8198,12 @@ _test_integrate_cb_idle_2 (gpointer user_data) g_assert (d->extra_sources[0]); g_assert (!d->extra_sources[1]); - extra_source = g_unix_fd_source_new (d->fd_2, G_IO_IN); - g_source_set_callback (extra_source, G_SOURCE_FUNC (_test_integrate_cb_fd_2), d, NULL); + extra_source = nm_g_unix_fd_source_new (d->fd_2, + G_IO_IN, + G_PRIORITY_DEFAULT, + _test_integrate_cb_fd_2, + d, + NULL); g_source_attach (extra_source, d->c2); d->extra_sources[1] = extra_source; @@ -8294,8 +8297,12 @@ test_integrate_maincontext (gconstpointer test_data) fd_1 = open ("/dev/null", O_RDONLY | O_CLOEXEC); g_assert (fd_1 >= 0); - fd_source_1 = g_unix_fd_source_new (fd_1, G_IO_IN); - g_source_set_callback (fd_source_1, G_SOURCE_FUNC (_test_integrate_cb_fd_1), &d, NULL); + fd_source_1 = nm_g_unix_fd_source_new (fd_1, + G_IO_IN, + G_PRIORITY_DEFAULT, + _test_integrate_cb_fd_1, + &d, + NULL); g_source_attach (fd_source_1, c2); fd_2 = open ("/dev/null", O_RDONLY | O_CLOEXEC); diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index d7581f9a65..3207d8edf9 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -3623,6 +3623,26 @@ nm_g_unix_signal_source_new (int signum, return source; } +GSource * +nm_g_unix_fd_source_new (int fd, + GIOCondition io_condition, + int priority, + gboolean (*source_func) (int fd, + GIOCondition condition, + gpointer user_data), + gpointer user_data, + GDestroyNotify destroy_notify) +{ + GSource *source; + + source = g_unix_fd_source_new (fd, io_condition); + + if (priority != G_PRIORITY_DEFAULT) + g_source_set_priority (source, priority); + g_source_set_callback (source, G_SOURCE_FUNC (source_func), user_data, destroy_notify); + return source; +} + /*****************************************************************************/ #define _CTX_LOG(fmt, ...) \ diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 0af58c4b6d..55d992a9e2 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -983,7 +983,14 @@ GSource *nm_g_timeout_source_new (guint timeout_msec, GSourceFunc func, gpointer user_data, GDestroyNotify destroy_notify); - +GSource *nm_g_unix_fd_source_new (int fd, + GIOCondition io_condition, + int priority, + gboolean (*source_func) (int fd, + GIOCondition condition, + gpointer user_data), + gpointer user_data, + GDestroyNotify destroy_notify); GSource *nm_g_unix_signal_source_new (int signum, int priority, GSourceFunc handler, diff --git a/shared/nm-test-utils-impl.c b/shared/nm-test-utils-impl.c index 0805d0b946..43176f4c7e 100644 --- a/shared/nm-test-utils-impl.c +++ b/shared/nm-test-utils-impl.c @@ -127,7 +127,7 @@ nmtstc_service_init (void) g_source_attach (timeout_source, context); child_source = g_child_watch_source_new (info->pid); - g_source_set_callback (child_source, (GSourceFunc)(void (*) (void)) _service_init_wait_child_wait, &data, NULL); + g_source_set_callback (child_source, G_SOURCE_FUNC (_service_init_wait_child_wait), &data, NULL); g_source_attach (child_source, context); had_timeout = !nmtst_main_loop_run (data.mainloop, 30000); diff --git a/shared/nm-udev-aux/nm-udev-utils.c b/shared/nm-udev-aux/nm-udev-utils.c index 1b0927dfff..c00dcd3318 100644 --- a/shared/nm-udev-aux/nm-udev-utils.c +++ b/shared/nm-udev-aux/nm-udev-utils.c @@ -164,7 +164,7 @@ nm_udev_client_enumerate_new (NMUdevClient *self) /*****************************************************************************/ static gboolean -monitor_event (GIOChannel *source, +monitor_event (int fd, GIOCondition condition, gpointer user_data) { @@ -204,7 +204,6 @@ nm_udev_client_new (const char *const*subsystems, gpointer event_user_data) { NMUdevClient *self; - GIOChannel *channel; guint n; self = g_slice_new0 (NMUdevClient); @@ -237,12 +236,14 @@ nm_udev_client_new (const char *const*subsystems, /* listen to events, and buffer them */ udev_monitor_set_receive_buffer_size (self->monitor, 4*1024*1024); udev_monitor_enable_receiving (self->monitor); - channel = g_io_channel_unix_new (udev_monitor_get_fd (self->monitor)); - self->watch_source = g_io_create_watch (channel, G_IO_IN); - g_io_channel_unref (channel); - g_source_set_callback (self->watch_source, (GSourceFunc)(void (*) (void)) monitor_event, self, NULL); + + self->watch_source = nm_g_unix_fd_source_new (udev_monitor_get_fd (self->monitor), + G_IO_IN, + G_PRIORITY_DEFAULT, + monitor_event, + self, + NULL); g_source_attach (self->watch_source, g_main_context_get_thread_default ()); - g_source_unref (self->watch_source); } } @@ -258,10 +259,7 @@ nm_udev_client_unref (NMUdevClient *self) if (!self) return NULL; - if (self->watch_source) { - g_source_destroy (self->watch_source); - self->watch_source = NULL; - } + nm_clear_g_source_inst (&self->watch_source); udev_monitor_unref (self->monitor); self->monitor = NULL; diff --git a/src/devices/bluetooth/nm-bluez5-dun.c b/src/devices/bluetooth/nm-bluez5-dun.c index 3ddfb0ef44..0d0354e21b 100644 --- a/src/devices/bluetooth/nm-bluez5-dun.c +++ b/src/devices/bluetooth/nm-bluez5-dun.c @@ -31,12 +31,12 @@ typedef struct { GError *rfcomm_sdp_search_error; + GSource *source; + gint64 connect_open_tty_started_at; gulong cancelled_id; - guint source_id; - guint8 sdp_session_try_count; } ConnectData; @@ -50,13 +50,13 @@ struct _NMBluez5DunContext { char *rfcomm_tty_path; + GSource *rfcomm_tty_poll_source; + int rfcomm_sock_fd; int rfcomm_tty_fd; int rfcomm_tty_no; int rfcomm_channel; - guint rfcomm_tty_poll_id; - bdaddr_t src; bdaddr_t dst; @@ -118,7 +118,7 @@ nm_bluez5_dun_context_get_rfcomm_dev (const NMBluez5DunContext *context) /*****************************************************************************/ static gboolean -_rfcomm_tty_poll_cb (GIOChannel *stream, +_rfcomm_tty_poll_cb (int fd, GIOCondition condition, gpointer user_data) { @@ -129,7 +129,7 @@ _rfcomm_tty_poll_cb (GIOChannel *stream, NM_FLAGS_ALL (condition, G_IO_HUP | G_IO_ERR) ? "," : "", NM_FLAGS_HAS (condition, G_IO_HUP) ? "HUP" : ""); - context->rfcomm_tty_poll_id = 0; + nm_clear_g_source_inst (&context->rfcomm_tty_poll_source); context->notify_tty_hangup_cb (context, context->notify_tty_hangup_user_data); return G_SOURCE_REMOVE; @@ -148,7 +148,7 @@ _connect_open_tty_retry_cb (gpointer user_data) if (nm_utils_get_monotonic_timestamp_nsec () > context->cdat->connect_open_tty_started_at + (30 * 100 * NM_UTILS_NSEC_PER_MSEC)) { gs_free_error GError *error = NULL; - context->cdat->source_id = 0; + nm_clear_g_source_inst (&context->cdat->source); g_set_error (&error, NM_BT_ERROR, NM_BT_ERROR_DUN_CONNECT_FAILED, @@ -166,7 +166,6 @@ _connect_open_tty_retry_cb (gpointer user_data) static int _connect_open_tty (NMBluez5DunContext *context) { - nm_auto_unref_io_channel GIOChannel *io_channel = NULL; int fd; int errsv; @@ -174,26 +173,31 @@ _connect_open_tty (NMBluez5DunContext *context) if (fd < 0) { errsv = NM_ERRNO_NATIVE (errno); - if (context->cdat->source_id == 0) { + if (!context->cdat->source) { _LOGD (context, "failed opening tty "RFCOMM_FMT": %s (%d). Start polling...", context->rfcomm_tty_no, nm_strerror_native (errsv), errsv); context->cdat->connect_open_tty_started_at = nm_utils_get_monotonic_timestamp_nsec (); - context->cdat->source_id = g_timeout_add (100, - _connect_open_tty_retry_cb, - context); + context->cdat->source = nm_g_timeout_source_new (100, + G_PRIORITY_DEFAULT, + _connect_open_tty_retry_cb, + context, + NULL); + g_source_attach (context->cdat->source, NULL); } return -errsv; } context->rfcomm_tty_fd = fd; - io_channel = g_io_channel_unix_new (context->rfcomm_tty_fd); - context->rfcomm_tty_poll_id = g_io_add_watch (io_channel, - G_IO_ERR | G_IO_HUP, - _rfcomm_tty_poll_cb, - context); + context->rfcomm_tty_poll_source = nm_g_unix_fd_source_new (context->rfcomm_tty_fd, + G_IO_ERR | G_IO_HUP, + G_PRIORITY_DEFAULT, + _rfcomm_tty_poll_cb, + context, + NULL); + g_source_attach (context->rfcomm_tty_poll_source, NULL); _context_invoke_callback_success (context); return 0; @@ -263,7 +267,7 @@ _connect_create_rfcomm (NMBluez5DunContext *context) } static gboolean -_connect_socket_connect_cb (GIOChannel *stream, +_connect_socket_connect_cb (int fd, GIOCondition condition, gpointer user_data) { @@ -273,7 +277,7 @@ _connect_socket_connect_cb (GIOChannel *stream, socklen_t slen = sizeof(errsv); int r; - context->cdat->source_id = 0; + nm_clear_g_source_inst (&context->cdat->source); r = getsockopt (context->rfcomm_sock_fd, SOL_SOCKET, SO_ERROR, &errsv, &slen); @@ -346,7 +350,6 @@ _connect_socket_connect (NMBluez5DunContext *context) if (connect (context->rfcomm_sock_fd, (struct sockaddr *) &sa, sizeof (sa)) != 0) { - nm_auto_unref_io_channel GIOChannel *io_channel = NULL; errsv = errno; if (errsv != EINPROGRESS) { @@ -363,11 +366,13 @@ _connect_socket_connect (NMBluez5DunContext *context) context->dst_str, context->rfcomm_channel); - io_channel = g_io_channel_unix_new (context->rfcomm_sock_fd); - context->cdat->source_id = g_io_add_watch (io_channel, - G_IO_OUT, - _connect_socket_connect_cb, - context); + context->cdat->source = nm_g_unix_fd_source_new (context->rfcomm_sock_fd, + G_IO_OUT, + G_PRIORITY_DEFAULT, + _connect_socket_connect_cb, + context, + NULL); + g_source_attach (context->cdat->source, NULL); return; } @@ -466,7 +471,7 @@ _connect_sdp_search_cb (uint8_t type, } static gboolean -_connect_sdp_search_io_cb (GIOChannel *io_channel, +_connect_sdp_search_io_cb (int fd, GIOCondition condition, gpointer user_data) { @@ -480,7 +485,7 @@ _connect_sdp_search_io_cb (GIOChannel *io_channel, error = g_error_new (NM_BT_ERROR, NM_BT_ERROR_DUN_CONNECT_FAILED, "Service Discovery interrupted"); - context->cdat->source_id = 0; + nm_clear_g_source_inst (&context->cdat->source); _context_invoke_callback_fail_and_free (context, error); return G_SOURCE_REMOVE; } @@ -490,7 +495,7 @@ _connect_sdp_search_io_cb (GIOChannel *io_channel, return G_SOURCE_CONTINUE; } - context->cdat->source_id = 0; + nm_clear_g_source_inst (&context->cdat->source); if ( context->rfcomm_channel < 0 && !context->cdat->rfcomm_sdp_search_error) { @@ -524,7 +529,7 @@ _connect_sdp_session_start_on_idle_cb (gpointer user_data) NMBluez5DunContext *context = user_data; gs_free_error GError *error = NULL; - context->cdat->source_id = 0; + nm_clear_g_source_inst (&context->cdat->source); _LOGD (context, "retry starting sdp-session..."); @@ -535,7 +540,7 @@ _connect_sdp_session_start_on_idle_cb (gpointer user_data) } static gboolean -_connect_sdp_io_cb (GIOChannel *io_channel, +_connect_sdp_io_cb (int fd, GIOCondition condition, gpointer user_data) { @@ -544,16 +549,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel, sdp_list_t *attrs; uuid_t svclass; uint16_t attr; - int fd; int errsv; int fd_err = 0; int r; socklen_t len = sizeof (fd_err); gs_free_error GError *error = NULL; - context->cdat->source_id = 0; - - fd = g_io_channel_unix_get_fd (io_channel); + nm_clear_g_source_inst (&context->cdat->source); _LOGD (context, "sdp-session ready to connect with fd=%d", fd); @@ -572,10 +574,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel, && --context->cdat->sdp_session_try_count > 0) { /* *sigh* */ _LOGD (context, "sdp-session failed with %s (%d). Retry in a bit", nm_strerror_native (errsv), errsv); - nm_clear_g_source (&context->cdat->source_id); - context->cdat->source_id = g_timeout_add (1000, - _connect_sdp_session_start_on_idle_cb, - context); + nm_clear_g_source_inst (&context->cdat->source); + context->cdat->source = nm_g_timeout_source_new (1000, + G_PRIORITY_DEFAULT, + _connect_sdp_session_start_on_idle_cb, + context, + NULL); + g_source_attach (context->cdat->source, NULL); return G_SOURCE_REMOVE; } @@ -615,10 +620,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel, } /* Set callback responsible for update the internal SDP transaction */ - context->cdat->source_id = g_io_add_watch (io_channel, - G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - _connect_sdp_search_io_cb, - context); + context->cdat->source = nm_g_unix_fd_source_new (fd, + G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, + G_PRIORITY_DEFAULT, + _connect_sdp_search_io_cb, + context, + NULL); + g_source_attach (context->cdat->source, NULL); done: if (error) @@ -644,11 +652,9 @@ static gboolean _connect_sdp_session_start (NMBluez5DunContext *context, GError **error) { - nm_auto_unref_io_channel GIOChannel *io_channel = NULL; - nm_assert (context->cdat); - nm_clear_g_source (&context->cdat->source_id); + nm_clear_g_source_inst (&context->cdat->source); nm_clear_pointer (&context->cdat->sdp_session, sdp_close); context->cdat->sdp_session = sdp_connect (&context->src, &context->dst, SDP_NON_BLOCKING); @@ -661,11 +667,13 @@ _connect_sdp_session_start (NMBluez5DunContext *context, return FALSE; } - io_channel = g_io_channel_unix_new (sdp_get_socket (context->cdat->sdp_session)); - context->cdat->source_id = g_io_add_watch (io_channel, - G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - _connect_sdp_io_cb, - context); + context->cdat->source = nm_g_unix_fd_source_new (sdp_get_socket (context->cdat->sdp_session), + G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, + G_PRIORITY_DEFAULT, + _connect_sdp_io_cb, + context, + NULL); + g_source_attach (context->cdat->source, NULL); return TRUE; } @@ -772,7 +780,7 @@ _context_cleanup_connect_data (NMBluez5DunContext *context) nm_clear_g_signal_handler (cdat->cancellable, &cdat->cancelled_id); - nm_clear_g_source (&cdat->source_id); + nm_clear_g_source_inst (&cdat->source); nm_clear_pointer (&cdat->sdp_session, sdp_close); @@ -836,7 +844,7 @@ _context_free (NMBluez5DunContext *context) _context_cleanup_connect_data (context); - nm_clear_g_source (&context->rfcomm_tty_poll_id); + nm_clear_g_source_inst (&context->rfcomm_tty_poll_source); if (context->rfcomm_sock_fd >= 0) { if (context->rfcomm_tty_no >= 0) { diff --git a/src/devices/nm-acd-manager.c b/src/devices/nm-acd-manager.c index 6e7a2a0f61..c771147968 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; @@ -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; } @@ -421,11 +426,15 @@ nm_acd_manager_announce_addresses (NMAcdManager *self) } } - 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); diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c index 76a2c2e0aa..c4547f4114 100644 --- a/src/dhcp/nm-dhcp-nettools.c +++ b/src/dhcp/nm-dhcp-nettools.c @@ -49,8 +49,7 @@ typedef struct { NDhcp4Client *client; NDhcp4ClientProbe *probe; NDhcp4ClientLease *lease; - GIOChannel *channel; - guint event_id; + GSource *event_source; char *lease_file; } NMDhcpNettoolsPrivate; @@ -1054,7 +1053,7 @@ dhcp4_event_handle (NMDhcpNettools *self, } static gboolean -dhcp4_event_cb (GIOChannel *source, +dhcp4_event_cb (int fd, GIOCondition condition, gpointer data) { @@ -1188,8 +1187,14 @@ nettools_create (NMDhcpNettools *self, client = NULL; n_dhcp4_client_get_fd (priv->client, &fd); - priv->channel = g_io_channel_unix_new (fd); - priv->event_id = g_io_add_watch (priv->channel, G_IO_IN, dhcp4_event_cb, self); + + priv->event_source = nm_g_unix_fd_source_new (fd, + G_IO_IN, + G_PRIORITY_DEFAULT, + dhcp4_event_cb, + self, + NULL); + g_source_attach (priv->event_source, NULL); return TRUE; } @@ -1419,8 +1424,7 @@ dispose (GObject *object) NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE ((NMDhcpNettools *) object); nm_clear_pointer (&priv->lease_file, g_free); - nm_clear_pointer (&priv->channel, g_io_channel_unref); - nm_clear_g_source (&priv->event_id); + nm_clear_g_source_inst (&priv->event_source); nm_clear_pointer (&priv->lease, n_dhcp4_client_lease_unref); nm_clear_pointer (&priv->probe, n_dhcp4_client_probe_free); nm_clear_pointer (&priv->client, n_dhcp4_client_unref); diff --git a/src/ndisc/nm-lndp-ndisc.c b/src/ndisc/nm-lndp-ndisc.c index d052426f4a..d8c1101c1c 100644 --- a/src/ndisc/nm-lndp-ndisc.c +++ b/src/ndisc/nm-lndp-ndisc.c @@ -24,9 +24,7 @@ typedef struct { struct ndp *ndp; - - GIOChannel *event_channel; - guint event_id; + GSource *event_source; } NMLndpNDiscPrivate; /*****************************************************************************/ @@ -484,9 +482,11 @@ receive_rs (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) } static gboolean -event_ready (GIOChannel *source, GIOCondition condition, NMNDisc *ndisc) +event_ready (int fd, + GIOCondition condition, + gpointer user_data) { - _nm_unused gs_unref_object NMNDisc *ndisc_keep_alive = g_object_ref (ndisc); + gs_unref_object NMNDisc *ndisc = g_object_ref (NM_NDISC (user_data)); nm_auto_pop_netns NMPNetns *netns = NULL; NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); @@ -494,7 +494,7 @@ event_ready (GIOChannel *source, GIOCondition condition, NMNDisc *ndisc) if (!nm_ndisc_netns_push (ndisc, &netns)) { /* something is very wrong. Stop handling events. */ - priv->event_id = 0; + nm_clear_g_source_inst (&priv->event_source); return G_SOURCE_REMOVE; } @@ -506,16 +506,22 @@ static void start (NMNDisc *ndisc) { NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); - int fd = ndp_get_eventfd (priv->ndp); + int fd; + + g_return_if_fail (!priv->event_source); - g_return_if_fail (!priv->event_channel); - g_return_if_fail (!priv->event_id); + fd = ndp_get_eventfd (priv->ndp); - priv->event_channel = g_io_channel_unix_new (fd); - priv->event_id = g_io_add_watch (priv->event_channel, G_IO_IN, (GIOFunc) event_ready, ndisc); + priv->event_source = nm_g_unix_fd_source_new (fd, + G_IO_IN, + G_PRIORITY_DEFAULT, + event_ready, + ndisc, + NULL); + g_source_attach (priv->event_source, NULL); /* Flush any pending messages to avoid using obsolete information */ - event_ready (priv->event_channel, 0, ndisc); + event_ready (fd, 0, ndisc); switch (nm_ndisc_get_node_type (ndisc)) { case NM_NDISC_NODE_TYPE_HOST: @@ -611,8 +617,7 @@ dispose (GObject *object) NMNDisc *ndisc = (NMNDisc *) object; NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); - nm_clear_g_source (&priv->event_id); - g_clear_pointer (&priv->event_channel, g_io_channel_unref); + nm_clear_g_source_inst (&priv->event_source); if (priv->ndp) { switch (nm_ndisc_get_node_type (ndisc)) { diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c index bcafc90893..207af583ce 100644 --- a/src/nm-connectivity.c +++ b/src/nm-connectivity.c @@ -515,8 +515,12 @@ multi_socket_cb (CURL *e_handle, curl_socket_t fd, int what, void *userdata, voi condition = 0; 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); + fdp->source = nm_g_unix_fd_source_new (fd, + condition, + G_PRIORITY_DEFAULT, + _con_curl_socketevent_cb, + fdp, + NULL); g_source_attach (fdp->source, NULL); } } diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c index 5d5fe4c95f..d189eb5a0d 100644 --- a/src/nm-session-monitor.c +++ b/src/nm-session-monitor.c @@ -48,7 +48,7 @@ struct _NMSessionMonitor { #if SESSION_TRACKING_XLOGIND struct { sd_login_monitor *monitor; - guint watch; + GSource *watch; } sd; #endif @@ -90,7 +90,9 @@ st_sd_session_exists (NMSessionMonitor *monitor, uid_t uid, gboolean active) } static gboolean -st_sd_changed (GIOChannel *stream, GIOCondition condition, gpointer user_data) +st_sd_changed (int fd, + GIOCondition condition, + gpointer user_data) { NMSessionMonitor *monitor = user_data; @@ -98,14 +100,13 @@ st_sd_changed (GIOChannel *stream, GIOCondition condition, gpointer user_data) sd_login_monitor_flush (monitor->sd.monitor); - return TRUE; + return G_SOURCE_CONTINUE; } static void st_sd_init (NMSessionMonitor *monitor) { int status; - GIOChannel *stream; if (!g_file_test ("/run/systemd/seats/", G_FILE_TEST_EXISTS)) return; @@ -115,10 +116,13 @@ st_sd_init (NMSessionMonitor *monitor) return; } - stream = g_io_channel_unix_new (sd_login_monitor_get_fd (monitor->sd.monitor)); - monitor->sd.watch = g_io_add_watch (stream, G_IO_IN, st_sd_changed, monitor); - - g_io_channel_unref (stream); + monitor->sd.watch = nm_g_unix_fd_source_new (sd_login_monitor_get_fd (monitor->sd.monitor), + G_IO_IN, + G_PRIORITY_DEFAULT, + st_sd_changed, + monitor, + NULL); + g_source_attach (monitor->sd.watch, NULL); } static void @@ -128,7 +132,7 @@ st_sd_finalize (NMSessionMonitor *monitor) sd_login_monitor_unref (monitor->sd.monitor); monitor->sd.monitor = NULL; } - nm_clear_g_source (&monitor->sd.watch); + nm_clear_g_source_inst (&monitor->sd.watch); } #endif /* SESSION_TRACKING_XLOGIND */ diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 23ebeaa3ab..4fc4a16f21 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -418,13 +418,14 @@ typedef struct { struct nl_sock *genl; struct nl_sock *nlh; + + GSource *event_source; + guint32 nlh_seq_next; #if NM_MORE_LOGGING guint32 nlh_seq_last_handled; #endif guint32 nlh_seq_last_seen; - GIOChannel *event_channel; - guint event_id; guint32 pruning[_REFRESH_ALL_TYPE_NUM]; @@ -8340,12 +8341,8 @@ tfilter_add (NMPlatform *platform, /*****************************************************************************/ -#define EVENT_CONDITIONS ((GIOCondition) (G_IO_IN | G_IO_PRI)) -#define ERROR_CONDITIONS ((GIOCondition) (G_IO_ERR | G_IO_NVAL)) -#define DISCONNECT_CONDITIONS ((GIOCondition) (G_IO_HUP)) - static gboolean -event_handler (GIOChannel *channel, +event_handler (int fd, GIOCondition io_condition, gpointer user_data) { @@ -8816,14 +8813,13 @@ constructed (GObject *_object) { NMPlatform *platform = NM_PLATFORM (_object); NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); - int channel_flags; - gboolean status; int nle; + int fd; nm_assert (!platform->_netns || platform->_netns == nmp_netns_get_current ()); if (nm_platform_get_use_udev (platform)) { - priv->udev_client = nm_udev_client_new ((const char *[]) { "net", NULL }, + priv->udev_client = nm_udev_client_new (NM_MAKE_STRV ("net"), handle_udev_event, platform); } @@ -8887,18 +8883,18 @@ constructed (GObject *_object) RTNLGRP_TC, 0); g_assert (!nle); - _LOGD ("Netlink socket for events established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh), nl_socket_get_fd (priv->nlh)); - priv->event_channel = g_io_channel_unix_new (nl_socket_get_fd (priv->nlh)); - g_io_channel_set_encoding (priv->event_channel, NULL, NULL); + fd = nl_socket_get_fd (priv->nlh); - channel_flags = g_io_channel_get_flags (priv->event_channel); - status = g_io_channel_set_flags (priv->event_channel, - channel_flags | G_IO_FLAG_NONBLOCK, NULL); - g_assert (status); - priv->event_id = g_io_add_watch (priv->event_channel, - (EVENT_CONDITIONS | ERROR_CONDITIONS | DISCONNECT_CONDITIONS), - event_handler, platform); + _LOGD ("Netlink socket for events established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh), fd); + + priv->event_source = nm_g_unix_fd_source_new (fd, + G_IO_IN | G_IO_NVAL | G_IO_PRI | G_IO_ERR | G_IO_HUP, + G_PRIORITY_DEFAULT, + event_handler, + platform, + NULL); + g_source_attach (priv->event_source, NULL); /* complete construction of the GObject instance before populating the cache. */ G_OBJECT_CLASS (nm_linux_platform_parent_class)->constructed (_object); @@ -8991,8 +8987,8 @@ finalize (GObject *object) nl_socket_free (priv->genl); - g_source_remove (priv->event_id); - g_io_channel_unref (priv->event_channel); + nm_clear_g_source_inst (&priv->event_source); + nl_socket_free (priv->nlh); if (priv->sysctl_get_prev_values) { |