Browse code

Added debug information

git-svn: trunk@440

Nigel Horne authored on 2004/03/26 20:10:27
Showing 2 changed files
... ...
@@ -290,6 +290,9 @@ Changes
290 290
 		in string.h says it returns a char *
291 291
 		Say how many bytes can't be written to clamd - it may give a
292 292
 		clue what's wrong
293
+0.70b	26/3/04	Display errno information on write failure to clamd
294
+		Ensure errno is passed to strerror
295
+		Print fd in clamfi_send debug
293 296
 
294 297
 BUG REPORTS
295 298
 
... ...
@@ -289,9 +289,15 @@
289 289
  *			in string.h says it returns a char *
290 290
  *			Say how many bytes can't be written to clamd - it may
291 291
  *			give a clue what's wrong
292
+ *	0.70b	26/3/04	Display errno information on write failure to clamd
293
+ *			Ensure errno is passed to strerror
294
+ *			Print fd in clamfi_send debug
292 295
  *
293 296
  * Change History:
294 297
  * $Log: clamav-milter.c,v $
298
+ * Revision 1.64  2004/03/26 11:10:27  nigelhorne
299
+ * Added debug information
300
+ *
295 301
  * Revision 1.63  2004/03/20 12:30:00  nigelhorne
296 302
  * strerror_r is confused on Linux
297 303
  *
... ...
@@ -466,9 +472,9 @@
466 466
  * Revision 1.6  2003/09/28 16:37:23  nigelhorne
467 467
  * Added -f flag use MaxThreads if --max-children not set
468 468
  */
469
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.63 2004/03/20 12:30:00 nigelhorne Exp $";
469
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.64 2004/03/26 11:10:27 nigelhorne Exp $";
470 470
 
471
-#define	CM_VERSION	"0.70a"
471
+#define	CM_VERSION	"0.70b"
472 472
 
473 473
 /*#define	CONFDIR	"/usr/local/etc"*/
474 474
 
... ...
@@ -1426,7 +1432,7 @@ findServer(void)
1426 1426
 
1427 1427
 static sfsistat
1428 1428
 clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
1429
-{
1429
+
1430 1430
 	char ip[INET_ADDRSTRLEN];	/* IPv4 only */
1431 1431
 	char *remoteIP;
1432 1432
 
... ...
@@ -1773,19 +1779,18 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
1773 1773
 		if(rc < 0) {
1774 1774
 			perror("connect");
1775 1775
 
1776
-			clamfi_free(privdata);
1777
-
1778 1776
 			/* 0.4 - use better error message */
1779 1777
 			if(use_syslog) {
1780 1778
 #ifdef HAVE_STRERROR_R
1781
-				strerror_r(rc, buf, sizeof(buf));
1782
-                                syslog(LOG_ERR,
1779
+				strerror_r(errno, buf, sizeof(buf));
1780
+				syslog(LOG_ERR,
1783 1781
 					"Failed to connect to port %d given by clamd: %s",
1784 1782
 					port, buf);
1785 1783
 #else
1786
-                               syslog(LOG_ERR, "Failed to connect to port %d given by clamd: %s", port, strerror(rc));
1784
+				syslog(LOG_ERR, "Failed to connect to port %d given by clamd: %s", port, strerror(errno));
1787 1785
 #endif
1788 1786
 			}
1787
+			clamfi_free(privdata);
1789 1788
 
1790 1789
 			return cl_error;
1791 1790
 		}
... ...
@@ -1796,10 +1801,7 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
1796 1796
 	privdata->from = strdup(argv[0]);
1797 1797
 	privdata->to = NULL;
1798 1798
 
1799
-	if (hflag)
1800
-		privdata->headers = header_list_new();
1801
-	else
1802
-		privdata->headers = NULL;
1799
+	privdata->headers = (hflag) ? header_list_new() : NULL;
1803 1800
 
1804 1801
 	if(smfi_setpriv(ctx, privdata) == MI_SUCCESS)
1805 1802
 		return SMFIS_CONTINUE;
... ...
@@ -1818,7 +1820,7 @@ clamfi_envrcpt(SMFICTX *ctx, char **argv)
1818 1818
 		syslog(LOG_DEBUG, "clamfi_envrcpt: %s", argv[0]);
1819 1819
 
1820 1820
 #ifdef	CL_DEBUG
1821
-	printf("clamfi_envrcpt: %s \n", argv[0]);
1821
+	printf("clamfi_envrcpt: %s\n", argv[0]);
1822 1822
 #endif
1823 1823
 
1824 1824
 	clamfi_send(privdata, 0, "To: %s\n", argv[0]);
... ...
@@ -1828,7 +1830,7 @@ clamfi_envrcpt(SMFICTX *ctx, char **argv)
1828 1828
 
1829 1829
 		assert(privdata->numTo == 0);
1830 1830
 	} else
1831
-		privdata->to = realloc(privdata->to, sizeof(char *) * (privdata->numTo + 2));
1831
+		privdata->to = cli_realloc(privdata->to, sizeof(char *) * (privdata->numTo + 2));
1832 1832
 
1833 1833
 	privdata->to[privdata->numTo] = strdup(argv[0]);
1834 1834
 	privdata->to[++privdata->numTo] = NULL;
... ...
@@ -2398,7 +2400,8 @@ clamfi_send(const struct privdata *privdata, size_t len, const char *format, ...
2398 2398
 	}
2399 2399
 #ifdef	CL_DEBUG
2400 2400
 	if(debug_level >= 9)
2401
-		printf("clamfi_send: len=%u bufsiz=%u\n", len, sizeof(output));
2401
+		printf("clamfi_send: len=%u bufsiz=%u, fd=%d\n",
2402
+			len, sizeof(output), privdata->dataSocket);
2402 2403
 #endif
2403 2404
 
2404 2405
 	while(len > 0) {
... ...
@@ -2406,13 +2409,24 @@ clamfi_send(const struct privdata *privdata, size_t len, const char *format, ...
2406 2406
 			write(privdata->dataSocket, ptr, len) :
2407 2407
 			send(privdata->dataSocket, ptr, len, 0);
2408 2408
 
2409
+		assert(privdata->dataSocket >= 0);
2410
+
2409 2411
 		if(nbytes == -1) {
2410 2412
 			if(errno == EINTR)
2411 2413
 				continue;
2412 2414
 			perror("send");
2415
+			if(use_syslog) {
2416
+#ifdef HAVE_STRERROR_R
2417
+				char buf[32];
2418
+				strerror_r(errno, buf, sizeof(buf));
2419
+				syslog(LOG_ERR,
2420
+					"write failure (%u bytes) to clamd: %s",
2421
+					len, buf);
2422
+#else
2423
+				syslog(LOG_ERR, "write failure (%u bytes) to clamd: %s", len, strerror(errno));
2424
+#endif
2425
+			}
2413 2426
 			checkClamd();
2414
-			if(use_syslog)
2415
-				syslog(LOG_ERR, "write failure (%u bytes) to clamd", len);
2416 2427
 
2417 2428
 			return -1;
2418 2429
 		}
... ...
@@ -2577,10 +2591,10 @@ checkClamd(void)
2577 2577
 	char buf[9];
2578 2578
 
2579 2579
 	if(!localSocket)
2580
-		return;
2580
+		return;	/* communicating via TCP */
2581 2581
 
2582 2582
 	if(pidFile == NULL)
2583
-		return;
2583
+		return;	/* PidFile directive missing from clamav.conf */
2584 2584
 
2585 2585
 	fd = open(pidFile, O_RDONLY);
2586 2586
 	if(fd < 0) {