From b8139f4cffa22d5779636e8a1e984bff1e3900df Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 31 Dec 2012 23:12:17 -0800 Subject: [PATCH] shared: Fix file descriptor handling for management interface --- src/shared/mgmt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index 0e686d00d..ef9b0d1e6 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -126,15 +126,15 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond, struct mgmt *mgmt = user_data; struct mgmt_request *request; ssize_t bytes_written; - int fd; + + if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) + return FALSE; request = g_queue_pop_head(mgmt->request_queue); if (!request) return FALSE; - fd = g_io_channel_unix_get_fd(mgmt->io); - - bytes_written = write(fd, request->buf, request->len); + bytes_written = write(mgmt->fd, request->buf, request->len); if (bytes_written < 0) { g_queue_push_head(mgmt->request_queue, request); return FALSE; @@ -240,14 +240,11 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond, struct mgmt_ev_cmd_status *cs; ssize_t bytes_read; uint16_t opcode, event, index, length; - int fd; - if (cond & G_IO_NVAL) + if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) return FALSE; - fd = g_io_channel_unix_get_fd(mgmt->io); - - bytes_read = read(fd, mgmt->buf, mgmt->len); + bytes_read = read(mgmt->fd, mgmt->buf, mgmt->len); if (bytes_read < 0) return TRUE; @@ -303,6 +300,9 @@ struct mgmt *mgmt_new(int fd) { struct mgmt *mgmt; + if (fd < 0) + return NULL; + mgmt = g_try_new0(struct mgmt, 1); if (!mgmt) return NULL; -- 2.47.3