Browse code

clamdscan: improve error handling (bb#1729)

Tomasz Kojm authored on 2009/10/28 07:41:27
Showing 4 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Oct 27 23:29:09 CET 2009 (tk)
2
+---------------------------------
3
+ * clamdscan: improve error handling (bb#1729)
4
+
1 5
 Tue Oct 27 20:31:36 CET 2009 (tk)
2 6
 ---------------------------------
3 7
  * clamdscan, libclamav, clamdtop, freshclam, sigtool: fix some error path
... ...
@@ -257,7 +257,7 @@ int client(const struct optstruct *opts, int *infected)
257 257
 	struct stat sb;
258 258
 	fstat(0, &sb);
259 259
 	if((sb.st_mode & S_IFMT) != S_IFREG) scantype = STREAM;
260
-	if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL, &ret)) >= 0)
260
+	if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL, &ret, NULL, NULL)) >= 0)
261 261
 	    *infected = ret;
262 262
 	else
263 263
 	    errors = 1;
... ...
@@ -241,7 +241,7 @@ static int send_fdpass(int sockd, const char *filename) {
241 241
 /* Sends a proper scan request to clamd and parses its replies
242 242
  * This is used only in non IDSESSION mode
243 243
  * Returns the number of infected files or -1 on error */
244
-int dsresult(int sockd, int scantype, const char *filename, int *printok) {
244
+int dsresult(int sockd, int scantype, const char *filename, int *printok, int *files, int *errors) {
245 245
     int infected = 0, len, beenthere = 0;
246 246
     char *bol, *eol;
247 247
     struct RCVLN rcv;
... ...
@@ -274,12 +274,16 @@ int dsresult(int sockd, int scantype, const char *filename, int *printok) {
274 274
 
275 275
     if(len <=0) {
276 276
 	*printok = 0;
277
+	if(errors)
278
+	    (*errors)++;
277 279
 	return len;
278 280
     }
279 281
 
280 282
     while((len = recvln(&rcv, &bol, &eol))) {
281 283
 	if(len == -1) return -1;
282 284
 	beenthere = 1;
285
+	if(files)
286
+	    (*files)++;
283 287
 	if(!filename) logg("~%s\n", bol);
284 288
 	if(len > 7) {
285 289
 	    char *colon = strrchr(bol, ':');
... ...
@@ -301,6 +305,8 @@ int dsresult(int sockd, int scantype, const char *filename, int *printok) {
301 301
 		    }
302 302
 		}
303 303
 	    } else if(!memcmp(eol-7, " ERROR", 6)) {
304
+		if(errors)
305
+		    (*errors)++;
304 306
 		*printok = 0;
305 307
 		if(filename) {
306 308
 		    if(scantype >= STREAM)
... ...
@@ -369,12 +375,11 @@ static int serial_callback(struct stat *sb, char *filename, const char *path, en
369 369
 	if(filename) free(filename);
370 370
 	return CL_EOPEN;
371 371
     }
372
-    ret = dsresult(sockd, c->scantype, f, &c->printok);
372
+    ret = dsresult(sockd, c->scantype, f, &c->printok, &c->files, &c->errors);
373 373
     if(filename) free(filename);
374 374
     close(sockd);
375 375
     if(ret < 0) return CL_EOPEN;
376 376
     c->infected += ret;
377
-    c->files++;
378 377
     if(reason == visit_directory_toplev)
379 378
 	return CL_BREAK;
380 379
     return CL_SUCCESS;
... ...
@@ -401,6 +406,8 @@ int serial_client_scan(char *file, int scantype, int *infected, int maxlevel, in
401 401
 	if(cdata.printok)
402 402
 	    logg("~%s: OK\n", file);
403 403
 	return 0;
404
+    } else if(!cdata.files) {
405
+	logg("~%s: No files scanned\n", file);
404 406
     }
405 407
     return 1;
406 408
 }
... ...
@@ -462,6 +469,7 @@ static int dspresult(struct client_parallel_data *c) {
462 462
 		logg("~%s%s\n", filename, colon);
463 463
 		if(action) action(filename);
464 464
 	    } else if(!memcmp(eol-7, " ERROR", 6)) {
465
+		c->errors++;
465 466
 		c->printok = 0;
466 467
 		logg("~%s%s\n", filename, colon);
467 468
 	    }
... ...
@@ -552,6 +560,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path,
552 552
     }
553 553
     if(res <= 0) {
554 554
 	c->printok = 0;
555
+	c->errors++;
555 556
 	c->ids = cid->next;
556 557
 	c->lastid--;
557 558
 	free(cid);
... ...
@@ -36,5 +36,5 @@ void recvlninit(struct RCVLN *s, int sockd);
36 36
 int recvln(struct RCVLN *s, char **rbol, char **reol);
37 37
 int serial_client_scan(char *file, int scantype, int *infected, int maxlevel, int flags);
38 38
 int parallel_client_scan(char *file, int scantype, int *infected, int maxlevel, int flags);
39
-int dsresult(int sockd, int scantype, const char *filename, int *spam);
39
+int dsresult(int sockd, int scantype, const char *filename, int *printok, int *files, int *errors);
40 40
 #endif