Browse code

better fix for bb #1446, try not to get confused by half-shut sockets (bb #1441).

git-svn: trunk@4947

Török Edvin authored on 2009/03/15 00:03:15
Showing 3 changed files
... ...
@@ -1,3 +1,8 @@
1
+Sat Mar 14 17:03:08 EET 2009 (edwin)
2
+------------------------------------
3
+ * clamd/scanner.c, unit_tests/check_clamd.c: better fix for bb
4
+ #1446, try not to get confused by half-shut sockets (bb #1441).
5
+
1 6
 Sat Mar 14 16:18:00 EET 2009 (edwin)
2 7
 ------------------------------------
3 8
  * clamconf/, clamdscan/, clamdtop/, libclamav/: fix build on
... ...
@@ -88,14 +88,9 @@ int scan_callback(struct stat *sb, char *filename, const char *msg, enum cli_ftw
88 88
     int type = scandata->type;
89 89
     const struct optstruct *opt;
90 90
 
91
-    fd_set rfds;
92
-    struct timeval tv;
93
-
94
-    FD_ZERO(&rfds);
95
-    FD_SET(scandata->conn->sd, &rfds);
96
-    tv.tv_sec = tv.tv_usec = 0;
97
-    if (select(scandata->conn->sd+1, &rfds, NULL, NULL, &tv) > 0 &&
98
-	FD_ISSET(scandata->conn->sd, &rfds)) {
91
+    /* detect disconnected socket, 
92
+     * this should NOT detect half-shutdown sockets (SHUT_WR) */
93
+    if (send(scandata->conn->sd, &ret, 0, 0) == -1 && errno != EINTR) {
99 94
 	logg("$Client disconnected while command was active!\n");
100 95
 	thrmgr_group_terminate(scandata->conn->group);
101 96
 	return CL_BREAK;
... ...
@@ -231,7 +231,7 @@ static void test_command(const char *cmd, size_t len, const char *extra, const c
231 231
 	rc = send(sockd, extra, strlen(extra), 0);
232 232
 	fail_unless_fmt((size_t)rc == strlen(extra), "Unable to send() extra for %s: %s\n", cmd, strerror(errno));
233 233
     }
234
-
234
+    shutdown(sockd, SHUT_WR);
235 235
     recvdata = recvfull(sockd, &len);
236 236
 
237 237
     fail_unless_fmt(len == expect_len, "Reply has wrong size: %lu, expected %lu, reply: %s, expected: %s\n",
... ...
@@ -240,6 +240,7 @@ static void test_command(const char *cmd, size_t len, const char *extra, const c
240 240
     rc = memcmp(recvdata, expect, expect_len);
241 241
     fail_unless_fmt(!rc, "Wrong reply for command %s: |%s|, expected: |%s|\n", cmd, recvdata, expect);
242 242
     free(recvdata);
243
+
243 244
 }
244 245
 
245 246
 #ifdef CHECK_HAVE_LOOPS