all: merge branch 'th/unix-fd-source'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/378
This commit is contained in:
Thomas Haller
2020-01-13 15:49:27 +01:00
16 changed files with 240 additions and 174 deletions

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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, ...) \

View File

@@ -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,

View File

@@ -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);

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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_channel);
g_return_if_fail (!priv->event_id);
g_return_if_fail (!priv->event_source);
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);
fd = ndp_get_eventfd (priv->ndp);
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)) {

View File

@@ -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);
}
}

View File

@@ -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 */

View File

@@ -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) {