From e2797b35250f1eb19711ab3dcecfa1051be45368 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 25 Aug 2003 21:37:57 +0000 Subject: [PATCH] Avoid UNLOCKing the critical section twice, which might cause a hang. 2003-08-25 Tor Lillqvist * glib/giowin32.c (read_thread): Avoid UNLOCKing the critical section twice, which might cause a hang. (#120653) * glib/giowin32.c (g_io_channel_unix_new): Warn if fd is both a valid file descriptor and socket. --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-10 | 8 ++++++++ ChangeLog.pre-2-12 | 8 ++++++++ ChangeLog.pre-2-4 | 8 ++++++++ ChangeLog.pre-2-6 | 8 ++++++++ ChangeLog.pre-2-8 | 8 ++++++++ glib/giowin32.c | 19 +++++++++++++------ 7 files changed, 61 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4eb13ea3..c70f0283 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-08-25 Tor Lillqvist + + * glib/giowin32.c (read_thread): Avoid UNLOCKing the critical + section twice, which might cause a hang. (#120653) + + * glib/giowin32.c (g_io_channel_unix_new): Warn if fd is both a + valid file descriptor and socket. + Mon Aug 25 12:34:36 2003 Owen Taylor * glib/gmessages.c: Escape control characters in g_logv() output. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4eb13ea3..c70f0283 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2003-08-25 Tor Lillqvist + + * glib/giowin32.c (read_thread): Avoid UNLOCKing the critical + section twice, which might cause a hang. (#120653) + + * glib/giowin32.c (g_io_channel_unix_new): Warn if fd is both a + valid file descriptor and socket. + Mon Aug 25 12:34:36 2003 Owen Taylor * glib/gmessages.c: Escape control characters in g_logv() output. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 4eb13ea3..c70f0283 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2003-08-25 Tor Lillqvist + + * glib/giowin32.c (read_thread): Avoid UNLOCKing the critical + section twice, which might cause a hang. (#120653) + + * glib/giowin32.c (g_io_channel_unix_new): Warn if fd is both a + valid file descriptor and socket. + Mon Aug 25 12:34:36 2003 Owen Taylor * glib/gmessages.c: Escape control characters in g_logv() output. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 4eb13ea3..c70f0283 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +2003-08-25 Tor Lillqvist + + * glib/giowin32.c (read_thread): Avoid UNLOCKing the critical + section twice, which might cause a hang. (#120653) + + * glib/giowin32.c (g_io_channel_unix_new): Warn if fd is both a + valid file descriptor and socket. + Mon Aug 25 12:34:36 2003 Owen Taylor * glib/gmessages.c: Escape control characters in g_logv() output. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 4eb13ea3..c70f0283 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +2003-08-25 Tor Lillqvist + + * glib/giowin32.c (read_thread): Avoid UNLOCKing the critical + section twice, which might cause a hang. (#120653) + + * glib/giowin32.c (g_io_channel_unix_new): Warn if fd is both a + valid file descriptor and socket. + Mon Aug 25 12:34:36 2003 Owen Taylor * glib/gmessages.c: Escape control characters in g_logv() output. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 4eb13ea3..c70f0283 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2003-08-25 Tor Lillqvist + + * glib/giowin32.c (read_thread): Avoid UNLOCKing the critical + section twice, which might cause a hang. (#120653) + + * glib/giowin32.c (g_io_channel_unix_new): Warn if fd is both a + valid file descriptor and socket. + Mon Aug 25 12:34:36 2003 Owen Taylor * glib/gmessages.c: Escape control characters in g_logv() output. diff --git a/glib/giowin32.c b/glib/giowin32.c index b7336a8f..dde72e71 100644 --- a/glib/giowin32.c +++ b/glib/giowin32.c @@ -234,9 +234,9 @@ read_thread (void *parameter) SetEvent (channel->space_avail_event); + LOCK (channel->mutex); while (channel->running) { - LOCK (channel->mutex); if (channel->debug) g_print ("read_thread %#x: rdp=%d, wrp=%d\n", channel->thread_id, channel->rdp, channel->wrp); @@ -294,7 +294,6 @@ read_thread (void *parameter) g_print ("read_thread %#x: rdp=%d, wrp=%d, setting data_avail\n", channel->thread_id, channel->rdp, channel->wrp); SetEvent (channel->data_avail_event); - UNLOCK (channel->mutex); } channel->running = FALSE; @@ -1604,14 +1603,22 @@ g_io_channel_win32_new_socket (int socket) GIOChannel * g_io_channel_unix_new (gint fd) { + gboolean is_fd, is_socket; struct stat st; int optval, optlen; - if (fstat (fd, &st) == 0) - return g_io_channel_win32_new_fd_internal (fd, &st); - + is_fd = (fstat (fd, &st) == 0); + optlen = sizeof (optval); - if (getsockopt (fd, SOL_SOCKET, SO_TYPE, (char *) &optval, &optlen) != SOCKET_ERROR) + is_socket = (getsockopt (fd, SOL_SOCKET, SO_TYPE, (char *) &optval, &optlen) != SOCKET_ERROR); + + if (is_fd && is_socket) + g_warning (G_STRLOC ": %d is both a file descriptor and a socket, file descriptor interpretation assumed.", fd); + + if (is_fd) + return g_io_channel_win32_new_fd_internal (fd, &st); + + if (is_socket) return g_io_channel_win32_new_socket(fd); g_warning (G_STRLOC ": %d is neither a file descriptor or a socket", fd); -- 2.34.1