Browse code

Support the --timeout argument

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@642 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/06/30 00:28:19
Showing 4 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Jun 29 16:27:47 BST 2004 (njh)
2
+----------------------------------
3
+  * clamav-milter:	Support --timeout option
4
+
1 5
 Tue Jun 29 09:27:42 BST 2004 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter:	Up-issued
... ...
@@ -416,6 +416,7 @@ Changes
416 416
 0.73d	28/6/04	Don't error when creating the quarantine directory if it
417 417
 			already exists
418 418
 0.74	29/6/04	Up-issued
419
+0.74a	29/6/04	Allow the child timeout to be configurable
419 420
 
420 421
 BUG REPORTS
421 422
 
... ...
@@ -26,6 +26,9 @@
26 26
  *
27 27
  * Change History:
28 28
  * $Log: clamav-milter.c,v $
29
+ * Revision 1.102  2004/06/29 15:26:14  nigelhorne
30
+ * Support the --timeout argument
31
+ *
29 32
  * Revision 1.101  2004/06/29 10:04:47  nigelhorne
30 33
  * Up issued
31 34
  *
... ...
@@ -314,9 +317,9 @@
314 314
  * Revision 1.6  2003/09/28 16:37:23  nigelhorne
315 315
  * Added -f flag use MaxThreads if --max-children not set
316 316
  */
317
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.101 2004/06/29 10:04:47 nigelhorne Exp $";
317
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.102 2004/06/29 15:26:14 nigelhorne Exp $";
318 318
 
319
-#define	CM_VERSION	"0.74"
319
+#define	CM_VERSION	"0.74a"
320 320
 
321 321
 /*#define	CONFDIR	"/usr/local/etc"*/
322 322
 
... ...
@@ -540,6 +543,10 @@ static	pthread_mutex_t	n_children_mutex = PTHREAD_MUTEX_INITIALIZER;
540 540
 static	pthread_cond_t	n_children_cond = PTHREAD_COND_INITIALIZER;
541 541
 static	unsigned	int	n_children = 0;
542 542
 static	unsigned	int	max_children = 0;
543
+static	int	child_timeout = 60;	/* number of seconds to wait for
544
+					 * a child to die. Set to 0 to
545
+					 * wait forever
546
+					 */
543 547
 short	use_syslog = 0;
544 548
 static	const	char	*pidFile;
545 549
 static	int	logVerbose = 0;
... ...
@@ -594,6 +601,7 @@ help(void)
594 594
 	puts("\t--sign\t\t\t-S\tAdd a hard-coded signature to each scanned message.");
595 595
 	puts("\t--signature-file=FILE\t-F FILE\tLocation of signature file.");
596 596
 	puts("\t--template-file=FILE\t-t FILE\tLocation of e-mail template file.");
597
+	puts("\t--timeout=SECS\t-T SECS\tTimeout waiting to childen to die.");
597 598
 	puts("\t--version\t\t-V\tPrint the version number of this software.");
598 599
 #ifdef	CL_DEBUG
599 600
 	puts("\t--debug-level=n\t\t-x n\tSets the debug level to 'n'.");
... ...
@@ -642,9 +650,9 @@ main(int argc, char **argv)
642 642
 	for(;;) {
643 643
 		int opt_index = 0;
644 644
 #ifdef	CL_DEBUG
645
-		const char *args = "a:bc:CDfF:lm:nNop:PqQ:dhHs:St:U:Vx:";
645
+		const char *args = "a:bc:CDfF:lm:nNop:PqQ:dhHs:St:T:U:Vx:";
646 646
 #else
647
-		const char *args = "a:bc:CDfF:lm:nNop:PqQ:dhHs:St:U:V";
647
+		const char *args = "a:bc:CDfF:lm:nNop:PqQ:dhHs:St:T:U:V";
648 648
 #endif
649 649
 
650 650
 		static struct option long_options[] = {
... ...
@@ -721,6 +729,9 @@ main(int argc, char **argv)
721 721
 				"template-file", 1, NULL, 't'
722 722
 			},
723 723
 			{
724
+				"timeout", 1, NULL, 'T'
725
+			},
726
+			{
724 727
 				"version", 0, NULL, 'V'
725 728
 			},
726 729
 #ifdef	CL_DEBUG
... ...
@@ -814,6 +825,9 @@ main(int argc, char **argv)
814 814
 			case 't':	/* e-mail template file */
815 815
 				templatefile = optarg;
816 816
 				break;
817
+			case 'T':	/* time to wait for child to die */
818
+				child_timeout = atoi(optarg);
819
+				break;
817 820
 			case 'U':	/* quarantine path */
818 821
 				quarantine_dir = optarg;
819 822
 				break;
... ...
@@ -1570,25 +1584,28 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
1570 1570
 					n_children, max_children);
1571 1571
 
1572 1572
 			/*
1573
+			 * Wait for an amount of time for a child to go (default
1574
+			 * 60 seconds).
1575
+			 *
1573 1576
 			 * Use pthread_cond_timedwait rather than
1574 1577
 			 * pthread_cond_wait since the sendmail which calls
1575
-			 * us will have a timeout that we don't want to exceed
1576
-			 *
1577
-			 * Wait for a maximum of 1 minute.
1578
-			 *
1579
-			 * TODO: this timeout should be configurable
1580
-			 *
1581
-			 * It stops sendmail getting fidgety.
1578
+			 * us will have a timeout that we don't want to exceed,
1579
+			 * stops sendmail getting fidgety.
1582 1580
 			 *
1583 1581
 			 * Patch from Damian Menscher <menscher@uiuc.edu> to
1584 1582
 			 * ensure it wakes up when a child goes away
1585 1583
 			 */
1586
-			gettimeofday(&now, &tz);
1587
-			timeout.tv_sec = now.tv_sec + 60;
1588
-			timeout.tv_nsec = 0;
1584
+			if(child_timeout) {
1585
+				gettimeofday(&now, &tz);
1586
+				timeout.tv_sec = now.tv_sec + child_timeout;
1587
+				timeout.tv_nsec = 0;
1588
+			}
1589 1589
 
1590 1590
 			do
1591
-				rc = pthread_cond_timedwait(&n_children_cond, &n_children_mutex, &timeout);
1591
+				if(child_timeout == 0)
1592
+					rc = pthread_cond_wait(&n_children_cond, &n_children_mutex);
1593
+				else
1594
+					rc = pthread_cond_timedwait(&n_children_cond, &n_children_mutex, &timeout);
1592 1595
 			while((n_children >= max_children) && (rc != ETIMEDOUT));
1593 1596
 		}
1594 1597
 		n_children++;
... ...
@@ -1596,7 +1613,7 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
1596 1596
 		cli_dbgmsg(">n_children = %d\n", n_children);
1597 1597
 		pthread_mutex_unlock(&n_children_mutex);
1598 1598
 
1599
-		if(rc == ETIMEDOUT) {
1599
+		if(child_timeout && (rc == ETIMEDOUT)) {
1600 1600
 #ifdef	CL_DEBUG
1601 1601
 			if(use_syslog)
1602 1602
 				syslog(LOG_NOTICE, "Timeout waiting for a child to die");
... ...
@@ -142,10 +142,11 @@ Location of file to be appended to each scanned message. Overrides \-S.
142 142
 .TP
143 143
 \fB\-\-max\-children=n, \-m n\fR
144 144
 Set a hint of the maximum number of children. If the number is hit the
145
-maximum time a pending thread will be held up is 1 minute, so the number
146
-of threads can exceed this number for short periods of time.
145
+maximum time a pending thread will be held up is set by \-\-timeout, so the
146
+number of threads can exceed this number for short periods of time.
147 147
 There is no default, if this argument is not \fBclamav\-milter\fR will
148
-spawn as many children as is necessary.
148
+spawn as many children as is necessary up to the MaxThreads limit set
149
+in \fBclamav.conf\fR.
149 150
 .LP
150 151
 Most users will not need this option, if in doubt do not set it.
151 152
 .TP
... ...
@@ -158,9 +159,15 @@ The %v string can be escaped, thus \\%v, to send the string %v.
158 158
 Any occurance of strings in braces are replaced with the appropriate
159 159
 {sendmail-variable}.
160 160
 If the \-t option is not given, clamav\-milter defaults to a hardcoded message.
161
+.TP
162
+\fB\-\-timeout=n \-T n\fR
163
+Used in conjuction with max\-children. If clamav\-milter waits for more than
164
+\fIn\fR seconds (default 60) it proceeds with scanning. Setting \fIn\fR to zero
165
+will turn off the timeout and clamav\-milter will wait indefinately for the
166
+scanning to quit. In practice the timeout set by sendmail will then take over.
161 167
 .SH "EXAMPLES"
162 168
 .LP
163
-clamav\-milter \-\-max\-children=2 \-ol local:/var/run/clamav/clmilter.sock
169
+clamav\-milter \-ol local:/var/run/clamav/clmilter.sock
164 170
 .SH "AUTHOR"
165 171
 .LP
166 172
 clamav\-milter was written by Nigel Horne <njh@bandsman.co.uk>, the manual page was created by Tomasz Kojm <zolw@konarski.edu.pl>.