Browse code

Applying errno init patch in c-rest-engine

Change-Id: Id3af9b666bc64a9509f26f4ded504e6495af4c49
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4409
Reviewed-by: Vinay Kulkarni <kulkarniv@vmware.com>
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Kumar Kaushik <kaushikk@vmware.com>

Kumar Kaushik authored on 2017/11/30 12:40:51
Showing 2 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 Name:          c-rest-engine
2 2
 Summary:       minimal http(s) server library
3 3
 Version:       1.1
4
-Release:       4%{?dist}
4
+Release:       5%{?dist}
5 5
 Group:         Applications/System
6 6
 Vendor:        VMware, Inc.
7 7
 License:       Apache 2.0
... ...
@@ -15,6 +15,7 @@ Source0:       %{name}-%{version}.tar.gz
15 15
 Patch0:        socket_RW.patch
16 16
 Patch1:        syslog_noInit.patch
17 17
 Patch2:        socket_logging.patch
18
+Patch3:        errno_init.patch
18 19
 %define sha1   c-rest-engine=a25927fd98ec92df5e210cc4941fa626604636f6
19 20
 
20 21
 %description
... ...
@@ -36,6 +37,7 @@ development libs and header files for c-rest-engine
36 36
 %patch0 -p1
37 37
 %patch1 -p1
38 38
 %patch2 -p1
39
+%patch3 -p1
39 40
 
40 41
 %build
41 42
 cd build
... ...
@@ -68,6 +70,8 @@ find %{buildroot} -name '*.la' -delete
68 68
 # %doc ChangeLog README COPYING
69 69
 
70 70
 %changelog
71
+*  Wed Nov 29 2017 Kumar Kaushik <kaushikk@vmware.com> 1.1-5
72
+-  Adding patch for right use of errno.
71 73
 *  Mon Nov 20 2017 Kumar Kaushik <kaushikk@vmware.com> 1.1-4
72 74
 -  Socket poller/read logging patch.
73 75
 *  Fri Nov 17 2017 Kumar Kaushik <kaushikk@vmware.com> 1.1-3
74 76
new file mode 100644
... ...
@@ -0,0 +1,111 @@
0
+From b9a3185e4556e8c5785a60fb57c2924bbd0529f7 Mon Sep 17 00:00:00 2001
1
+From: Kumar Kaushik <kaushikk@vmware.com>
2
+Date: Wed, 29 Nov 2017 18:47:39 -0800
3
+Subject: [PATCH] Avoiding previous errno variable use
4
+
5
+Change-Id: I76b0ef967df8b1ad6fa1844e1e461af470bb3b0f
6
+---
7
+ transport/posix/socket.c | 51 +++++++++++++++++++++++++++++++-----------------
8
+ 1 file changed, 33 insertions(+), 18 deletions(-)
9
+
10
+diff --git a/transport/posix/socket.c b/transport/posix/socket.c
11
+index 79c7a38..d3a3dbc 100644
12
+--- a/transport/posix/socket.c
13
+@@ -853,6 +853,8 @@ VmSockPosixRead(
14
+     do
15
+     {
16
+         nRead = 0;
17
++        errno = 0;
18
++        errorCode = 0;
19
+         if (pRESTHandle->pSSLInfo->isSecure && (pSocket->ssl != NULL))
20
+         {
21
+             nRead = SSL_read(pSocket->ssl, (pszBufPrev + nPrevBuf), MAX_DATA_BUFFER_LEN);
22
+@@ -864,7 +866,7 @@ VmSockPosixRead(
23
+             errorCode = errno;
24
+         }
25
+ 
26
+-        if ((nRead > 0) && (nRead <= MAX_DATA_BUFFER_LEN))
27
++        if (nRead > 0)
28
+         {
29
+             nPrevBuf += nRead;
30
+             dwError = VmRESTReallocateMemory(
31
+@@ -877,22 +879,6 @@ VmSockPosixRead(
32
+         }
33
+     }while((nRead > 0) && (nPrevBuf < pRESTHandle->pRESTConfig->maxDataPerConnMB));
34
+ 
35
+-    if (((pSocket->fd > 0) && (errorCode == EAGAIN || errorCode == EWOULDBLOCK)) || ((pRESTHandle->pSSLInfo->isSecure) && (errorCode == SSL_ERROR_WANT_READ)))
36
+-    {
37
+-        dwError = REST_ENGINE_SUCCESS;
38
+-    }
39
+-    else if (nRead < 0)
40
+-    {
41
+-        VMREST_LOG_ERROR(pRESTHandle, "Socket read failed with error code %u", errorCode);
42
+-        dwError = errorCode;
43
+-    }
44
+-    else if (nRead == 0)
45
+-    {
46
+-        VMREST_LOG_ERROR(pRESTHandle,"%s", "Socket read failed due to broken pipe");
47
+-        dwError = VM_SOCK_POSIX_ERROR_BROKEN_PIPE;
48
+-    }
49
+-    BAIL_ON_VMREST_ERROR(dwError);
50
+-
51
+     if (nPrevBuf >= pRESTHandle->pRESTConfig->maxDataPerConnMB)
52
+     {
53
+         /**** Discard the request here itself. This might be the first read IO cycle ****/
54
+@@ -901,6 +887,33 @@ VmSockPosixRead(
55
+     }
56
+     BAIL_ON_VMREST_ERROR(dwError);
57
+ 
58
++    if (nRead == -1)
59
++    {
60
++        if (((pSocket->fd > 0) && (errorCode == EAGAIN || errorCode == EWOULDBLOCK)) || ((pRESTHandle->pSSLInfo->isSecure) && (errorCode == SSL_ERROR_WANT_READ)))
61
++        {
62
++            dwError = REST_ENGINE_SUCCESS;
63
++        }
64
++        else
65
++        {
66
++            VMREST_LOG_ERROR(pRESTHandle,"%s","Unknown socket read error: errno %u, errorCode %u, nRead %d", errno, errorCode, nRead);
67
++            dwError = REST_ENGINE_FAILURE;
68
++        }
69
++    }
70
++    else
71
++    {
72
++        if (nRead == 0)
73
++        {
74
++            VMREST_LOG_ERROR(pRESTHandle,"%s","Socket Read Failed: Remote has closed the connection");
75
++            dwError = VM_SOCK_POSIX_ERROR_BROKEN_PIPE;
76
++        }
77
++        else
78
++        {
79
++            VMREST_LOG_ERROR(pRESTHandle, "Socket read failed with error code %u", errorCode);
80
++            dwError = errorCode;
81
++        }
82
++    }
83
++    BAIL_ON_VMREST_ERROR(dwError);
84
++
85
+     pSocket->pszBuffer = pszBufPrev;
86
+     pSocket->nProcessed = 0;
87
+     pSocket->nBufData = nPrevBuf;
88
+@@ -933,11 +946,12 @@ VmSockPosixRead(
89
+     if (pszBufPrev && pSocket && pRESTHandle->pSockContext)
90
+     {
91
+         /**** Delete the socket from poller ****/
92
++        
93
+         VmSockPosixEventQueueDelete_inlock(
94
+             pRESTHandle->pSockContext->pEventQueue,
95
+             pSocket
96
+             );
97
+-
98
++        
99
+         VmRESTFreeMemory(pszBufPrev);
100
+         pszBufPrev = NULL;
101
+         pSocket->pszBuffer = NULL;
102
+@@ -1566,6 +1580,7 @@ VmSockPosixSetRequestHandle(
103
+                       pSocket
104
+                       );
105
+         BAIL_ON_VMREST_ERROR(dwError);
106
++       
107
+ 
108
+         if (pSocket->pTimerSocket->fd > 0)
109
+         {