platform: don't use GIOChannel to watch plain file descriptor for netlink socket

This commit is contained in:
Thomas Haller
2020-01-01 11:21:16 +01:00
parent e832c478b0
commit 7848c165a1

View File

@@ -418,13 +418,14 @@ typedef struct {
struct nl_sock *genl; struct nl_sock *genl;
struct nl_sock *nlh; struct nl_sock *nlh;
GSource *event_source;
guint32 nlh_seq_next; guint32 nlh_seq_next;
#if NM_MORE_LOGGING #if NM_MORE_LOGGING
guint32 nlh_seq_last_handled; guint32 nlh_seq_last_handled;
#endif #endif
guint32 nlh_seq_last_seen; guint32 nlh_seq_last_seen;
GIOChannel *event_channel;
guint event_id;
guint32 pruning[_REFRESH_ALL_TYPE_NUM]; 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 static gboolean
event_handler (GIOChannel *channel, event_handler (int fd,
GIOCondition io_condition, GIOCondition io_condition,
gpointer user_data) gpointer user_data)
{ {
@@ -8816,9 +8813,8 @@ constructed (GObject *_object)
{ {
NMPlatform *platform = NM_PLATFORM (_object); NMPlatform *platform = NM_PLATFORM (_object);
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
int channel_flags;
gboolean status;
int nle; int nle;
int fd;
nm_assert (!platform->_netns || platform->_netns == nmp_netns_get_current ()); nm_assert (!platform->_netns || platform->_netns == nmp_netns_get_current ());
@@ -8887,18 +8883,18 @@ constructed (GObject *_object)
RTNLGRP_TC, RTNLGRP_TC,
0); 0);
g_assert (!nle); 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)); fd = nl_socket_get_fd (priv->nlh);
g_io_channel_set_encoding (priv->event_channel, NULL, NULL);
channel_flags = g_io_channel_get_flags (priv->event_channel); _LOGD ("Netlink socket for events established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh), fd);
status = g_io_channel_set_flags (priv->event_channel,
channel_flags | G_IO_FLAG_NONBLOCK, NULL); priv->event_source = nm_g_unix_fd_source_new (fd,
g_assert (status); G_IO_IN | G_IO_NVAL | G_IO_PRI | G_IO_ERR | G_IO_HUP,
priv->event_id = g_io_add_watch (priv->event_channel, G_PRIORITY_DEFAULT,
(EVENT_CONDITIONS | ERROR_CONDITIONS | DISCONNECT_CONDITIONS), event_handler,
event_handler, platform); platform,
NULL);
g_source_attach (priv->event_source, NULL);
/* complete construction of the GObject instance before populating the cache. */ /* complete construction of the GObject instance before populating the cache. */
G_OBJECT_CLASS (nm_linux_platform_parent_class)->constructed (_object); G_OBJECT_CLASS (nm_linux_platform_parent_class)->constructed (_object);
@@ -8991,8 +8987,8 @@ finalize (GObject *object)
nl_socket_free (priv->genl); nl_socket_free (priv->genl);
g_source_remove (priv->event_id); nm_clear_g_source_inst (&priv->event_source);
g_io_channel_unref (priv->event_channel);
nl_socket_free (priv->nlh); nl_socket_free (priv->nlh);
if (priv->sysctl_get_prev_values) { if (priv->sysctl_get_prev_values) {