Crash in Select 07/216607/2
authorsourav bhuwalka <s.bhuwalka@samsung.com>
Mon, 14 Oct 2019 16:27:56 +0000 (21:57 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Wed, 30 Oct 2019 01:15:42 +0000 (10:15 +0900)
Fixing bug in counter of CAPollReturned in case of shutdownFds socket
for ipserver and also introducing sleep between each subsequent
poll system call whenever the system remains idle.

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/583/commits/817a3e30d2c7f2fa6064cdfd13fc8a9294a5d956
(cherry-picked from 817a3e30d2c7f2fa6064cdfd13fc8a9294a5d956)

Change-Id: I4b6e96334fdb0c06fee2c4ce3099df9bf04ebaf3
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index 085f060..04a3495 100644 (file)
@@ -362,6 +362,13 @@ static void CAFindReadyMessage()
     {
         CAPollReturned(readFds, ret);
     }
+    else if (ret == 0)
+    {
+        usleep(1000); /* Incase of failure of FastShutdownMechanism timeout will be set to 1.
+                         some of the fields are not set by kernel on repeatedly calling
+                         poll.Applying a sleep will solve this by providing a delay
+                         between each subsequent poll system call */
+    }
     else if (ret < 0)
     {
         OIC_LOG_V(FATAL, TAG, "poll error %s", CAIPS_GET_ERROR);
@@ -398,10 +405,10 @@ static void CAPollReturned(struct pollfd *readFds, int ret)
             // Write end of the pipe is closed. Indicates the termination of UDP server.
             return;
         }
-
-        counter++;
     }
 
+   counter++;
+
     if (!caglobals.ip.terminate &&
            (caglobals.ip.netlinkFd != OC_INVALID_SOCKET) && readFds[counter].revents != 0)
     {
index 081775e..5b5f92e 100644 (file)
@@ -349,7 +349,8 @@ static void CAFindReadyMessage()
     else if (ret == 0)
     {
         usleep(1000); /* some of the fields are not set by kernel on repeatedly calling
-                         poll.Applying a timeout will solve this*/
+                         poll.Applying a sleep will solve this by providing a delay between
+                         each subsequent poll system call */
     }
     else if (ret < 0)
     {