Browse code

In single INSTREAM mode, remove FD from polled set (BB #1410) Fix testcase, INSTREAM should say UNKNOWN COMMAND in old mode and close conn, sending anything after it will likely result in a broken pipe.(BB #1407)

git-svn: trunk@4826

Török Edvin authored on 2009/02/19 03:37:57
Showing 4 changed files
... ...
@@ -1,3 +1,11 @@
1
+Wed Feb 18 21:08:50 EET 2009 (edwin)
2
+------------------------------------
3
+ * clamd/server-th.c, unit_tests/check_clamd.c,
4
+ unit_tests/test-clamd.conf: In single INSTREAM mode, remove FD from
5
+ polled set (BB #1410) Fix testcase, INSTREAM should say UNKNOWN
6
+ COMMAND in old mode and close conn, sending anything after it will
7
+ likely result in a broken pipe.(BB #1407)
8
+
1 9
 Wed Feb 18 20:35:16 EET 2009 (edwin)
2 10
 ------------------------------------
3 11
  * libclamav/bignum.h: disable __mode__(TI) code (bb #1409)
... ...
@@ -121,7 +121,7 @@ static void scanner_thread(void *arg)
121 121
     logg("$Finished scanthread\n");
122 122
     if (thrmgr_group_finished(conn->group, virus ? EXIT_OTHER :
123 123
 			      errors ? EXIT_ERROR : EXIT_OK)) {
124
-	logg("$Scanthread: connection shut down\n");
124
+	logg("$Scanthread: connection shut down (FD %d)\n", conn->sd);
125 125
 	/* close connection if we were last in group */
126 126
 	shutdown(conn->sd, 2);
127 127
 	closesocket(conn->sd);
... ...
@@ -355,6 +355,7 @@ static void *acceptloop_th(void *arg)
355 355
 		continue;
356 356
 	    }
357 357
 	    if (buf->got_newdata == -1) {
358
+		logg("$Acceptloop closed FD: %d\n", buf->fd);
358 359
 		shutdown(buf->fd, 2);
359 360
 		closesocket(buf->fd);
360 361
 		buf->fd = -1;
... ...
@@ -385,7 +386,6 @@ static void *acceptloop_th(void *arg)
385 385
 	    /* listen only socket */
386 386
 	    new_sd = accept(fds->buf[i].fd, NULL, NULL);
387 387
 
388
-
389 388
 	    if (new_sd >= 0) {
390 389
 		int ret, flags;
391 390
 
... ...
@@ -399,8 +399,10 @@ static void *acceptloop_th(void *arg)
399 399
 		} else {
400 400
 			logg("^Can't get socket flags, errno %d\n", errno);
401 401
 		}
402
+#else
403
+		logg("^Nonblocking sockets not available!\n");
402 404
 #endif
403
-
405
+		logg("$Got new connection, FD %d\n", new_sd);
404 406
 		pthread_mutex_lock(&recv_fds->buf_mutex);
405 407
 		ret = fds_add(recv_fds, new_sd, 0, commandtimeout);
406 408
 		pthread_mutex_unlock(&recv_fds->buf_mutex);
... ...
@@ -443,6 +445,7 @@ static void *acceptloop_th(void *arg)
443 443
     for (i=0;i < fds->nfds; i++) {
444 444
 	if (fds->buf[i].fd == -1)
445 445
 	    continue;
446
+	logg("$Shutdown: closed fd %d\n", fds->buf[i].fd);
446 447
 	shutdown(fds->buf[i].fd, 2);
447 448
 	closesocket(fds->buf[i].fd);
448 449
     }
... ...
@@ -956,7 +959,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
956 956
 		    }
957 957
 		    if (error || !conn.group || rc) {
958 958
 			if (rc && thrmgr_group_finished(conn.group, EXIT_OK)) {
959
-			    logg("$Receive thread: closing conn, group finished\n");
959
+			    logg("$Receive thread: closing conn (FD %d), group finished\n", conn.sd);
960 960
 			    /* if there are no more active jobs */
961 961
 			    shutdown(conn.sd, 2);
962 962
 			    closesocket(conn.sd);
... ...
@@ -1056,6 +1059,8 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
1056 1056
 				conn.term = buf->term;
1057 1057
 				buf->dumpfd = -1;
1058 1058
 				buf->mode = buf->group ? MODE_COMMAND : MODE_WAITREPLY;
1059
+				if (buf->mode == MODE_WAITREPLY)
1060
+				    buf->fd = -1;
1059 1061
 				logg("$Chunks complete\n");
1060 1062
 				buf->dumpname = NULL;
1061 1063
 				if ((rc = execute_or_dispatch_command(&conn, COMMAND_INSTREAMSCAN, NULL)) < 0) {
... ...
@@ -1121,7 +1126,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
1121 1121
 		}
1122 1122
 		thrmgr_group_terminate(buf->group);
1123 1123
 		if (thrmgr_group_finished(buf->group, EXIT_ERROR)) {
1124
-		    logg("$Shutting down socket after error\n");
1124
+		    logg("$Shutting down socket after error (FD %d)\n", buf->fd);
1125 1125
 		    shutdown(buf->fd, 2);
1126 1126
 		    closesocket(buf->fd);
1127 1127
 		} else
... ...
@@ -1141,6 +1146,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
1141 1141
 		    continue;
1142 1142
 		thrmgr_group_terminate(fds->buf[i].group);
1143 1143
 		if (thrmgr_group_finished(fds->buf[i].group, EXIT_ERROR)) {
1144
+		    logg("$Shutdown closed fd %d\n", fds->buf[i].fd);
1144 1145
 		    shutdown(fds->buf[i].fd, 2);
1145 1146
 		    closesocket(fds->buf[i].fd);
1146 1147
 		    fds->buf[i].fd = -1;
... ...
@@ -256,6 +256,7 @@ START_TEST (test_compat_commands)
256 256
 
257 257
     if (!test->support_old) {
258 258
 	snprintf(nreply, sizeof(nreply), "UNKNOWN COMMAND\n");
259
+	test->extra = NULL;
259 260
     } else {
260 261
 	snprintf(nreply, sizeof(nreply), "%s\n", test->reply);
261 262
     }
... ...
@@ -1,5 +1,5 @@
1 1
 # script will fill in CWD and X
2
-LogFile CWD/clamd-testX.log
2
+LogFile CWD/../clamd-testX.log
3 3
 LogFileMaxSize 0
4 4
 LogTime yes
5 5
 Debug yes