common: fix G_IO_ERR handling bug. 84/261184/8
authorINSUN PYO <insun.pyo@samsung.com>
Tue, 13 Jul 2021 03:30:01 +0000 (12:30 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Wed, 14 Jul 2021 05:40:04 +0000 (14:40 +0900)
If "G_IO_IN | G_IO_ERR" occurs, function can not handle G_IO_IN.
As a result, G_IO_IN continues to trigger in the poll.

Change-Id: Iebb22830f71074aaed0fff93dab569854e4a6c71

src/common/fd-handler.c

index a2635bc..0ec1aac 100644 (file)
@@ -80,8 +80,13 @@ static gboolean channel_changed(GIOChannel *source,
        if (h->fd != g_io_channel_unix_get_fd(source))
                return TRUE;
 
-       if (condition != G_IO_IN)
-               return TRUE;
+       if (condition & (G_IO_ERR | G_IO_HUP))
+               _E("GIOChannel receives G_IO_ERR|G_IO_HUP fd = %d condition = %d", h->fd, condition);
+
+       if (!(condition & G_IO_IN) && (condition & (G_IO_ERR | G_IO_HUP))) {
+               remove_fd_read_handler((fd_handler_h *)&h);
+               return FALSE;
+       }
 
        ret = true;
        if (h->changed)
@@ -117,7 +122,7 @@ int add_fd_read_handler(int fd,
                return -ENOMEM;
        }
 
-       id = g_io_add_watch(ch, G_IO_IN | G_IO_ERR,
+       id = g_io_add_watch(ch, G_IO_IN | G_IO_ERR | G_IO_HUP,
                        channel_changed, h);
        if (id == 0) {
                _E("Failed to add watch for GIOChannel");