Browse code

Added --pidfile

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

Nigel Horne authored on 2004/04/25 21:59:07
Showing 4 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sun Apr 25 13:58:35 BST 2004 (njh)
2
+----------------------------------
3
+ * clamav-milter:	Added --pidfile
4
+
1 5
 Fri Apr 23 11:48:07 BST 2004 (njh)
2 6
 ----------------------------------
3 7
  * libclamav/mbox.c:	If an inline text portion has been given a filename,
... ...
@@ -92,7 +92,8 @@ with that.
92 92
 
93 93
 If you see an unsafe socket error from sendmail, it means that the permissions
94 94
 of the /var/run/clamav directory are too open. Check you have correctly run
95
-chown and chmod.
95
+chown and chmod, it may also mean that clamav-milter hasn't started, run
96
+ps and check your logs.
96 97
 
97 98
 The above example shows clamav-milter, clamd and sendmail all on the
98 99
 same machine, however using TCP they may reside on different machines,
... ...
@@ -361,6 +362,7 @@ Changes
361 361
 0.70r	23/4/04	Ensure only From lines are escaped
362 362
 		Also defer generated emails if --force-scan is given
363 363
 		Better subject for quarantine e-mails
364
+0.70s	25/4/04	Added --pidfile support
364 365
 
365 366
 BUG REPORTS
366 367
 
... ...
@@ -41,7 +41,8 @@
41 41
  *
42 42
  * If you see an unsafe socket error from sendmail, it means that the
43 43
  * permissions of the /var/run/clamav directory are too open. Check you have
44
- * correctly run chown and chmod.
44
+ * correctly run chown and chmod, it may also mean that clamav-milter hasn't
45
+ * started, run ps and check your logs.
45 46
  *
46 47
  * The above example shows clamav-milter, clamd and sendmail all on the
47 48
  * same machine, however using TCP they may reside on different machines,
... ...
@@ -353,7 +354,7 @@
353 353
  *			twice at the same time (one on the incoming one on the
354 354
  *				outgoing)
355 355
  *			header_list_print, ensure From lines are escaped, may
356
- * 				not be needed but it is better to be on the
356
+ *				not be needed but it is better to be on the
357 357
  *				safe side
358 358
  *			When loadbalancing, fail to start only if no servers
359 359
  *				can be reached (used to fail if any one server
... ...
@@ -362,9 +363,13 @@
362 362
  *	0.70r	23/4/04	Ensure only From lines are escaped
363 363
  *			Also defer generated emails if --force-scan is given
364 364
  *			Better subject for quarantine e-mails
365
+ *	0.70s	25/4/04	Added --pidfile support
365 366
  *
366 367
  * Change History:
367 368
  * $Log: clamav-milter.c,v $
369
+ * Revision 1.83  2004/04/25 12:56:35  nigelhorne
370
+ * Added --pidfile
371
+ *
368 372
  * Revision 1.82  2004/04/23 09:13:30  nigelhorne
369 373
  * Better quarantine email subject
370 374
  *
... ...
@@ -596,9 +601,9 @@
596 596
  * Revision 1.6  2003/09/28 16:37:23  nigelhorne
597 597
  * Added -f flag use MaxThreads if --max-children not set
598 598
  */
599
-static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.82 2004/04/23 09:13:30 nigelhorne Exp $";
599
+static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.83 2004/04/25 12:56:35 nigelhorne Exp $";
600 600
 
601
-#define	CM_VERSION	"0.70r"
601
+#define	CM_VERSION	"0.70s"
602 602
 
603 603
 /*#define	CONFDIR	"/usr/local/etc"*/
604 604
 
... ...
@@ -857,6 +862,7 @@ help(void)
857 857
 	puts("\t--outgoing\t\t-o\tScan outgoing messages from this machine.");
858 858
 	puts("\t--noreject\t\t-N\tDon't reject viruses, silently throw them away.");
859 859
 	puts("\t--noxheader\t\t-n\tSuppress X-Virus-Scanned/X-Virus-Status headers.");
860
+	puts("\t--pidfile=FILE\t\t-i FILE\tLocation of pidfile.");
860 861
 	puts("\t--postmaster\t\t-p EMAIL\tPostmaster address [default=postmaster].");
861 862
 	puts("\t--postmaster-only\t-P\tSend warnings only to the postmaster.");
862 863
 	puts("\t--quiet\t\t\t-q\tDon't send e-mail notifications of interceptions.");
... ...
@@ -879,6 +885,7 @@ main(int argc, char **argv)
879 879
 	const char *cfgfile = CL_DEFAULT_CFG;
880 880
 	struct cfgstruct *cpt;
881 881
 	struct passwd *user;
882
+	const char *pidfile = NULL;
882 883
 	struct smfiDesc smfilter = {
883 884
 		"ClamAv", /* filter name */
884 885
 		SMFI_VERSION,	/* version code -- leave untouched */
... ...
@@ -947,6 +954,9 @@ main(int argc, char **argv)
947 947
 				"help", 0, NULL, 'h'
948 948
 			},
949 949
 			{
950
+				"pidfile", 1, NULL, 'i'
951
+			},
952
+			{
950 953
 				"local", 0, NULL, 'l'
951 954
 			},
952 955
 			{
... ...
@@ -1036,6 +1046,9 @@ main(int argc, char **argv)
1036 1036
 			case 'H':
1037 1037
 				hflag++;
1038 1038
 				break;
1039
+			case 'i':	/* pidfile */
1040
+				pidfile = optarg;
1041
+				break;
1039 1042
 			case 'l':	/* scan mail from the lan */
1040 1043
 				lflag++;
1041 1044
 				break;
... ...
@@ -1369,6 +1382,23 @@ main(int argc, char **argv)
1369 1369
 		use_syslog = 0;
1370 1370
 	}
1371 1371
 
1372
+	if(pidfile) {
1373
+		/* save the PID */
1374
+		FILE *fd;
1375
+		const mode_t old_umask = umask(0006);
1376
+
1377
+		if((fd = fopen(pidfile, "w")) == NULL) {
1378
+			if(use_syslog)
1379
+				syslog(LOG_WARNING, "Can't save PID in file %s",
1380
+					pidfile);
1381
+			cli_warnmsg("Can't save PID in file %s\n", pidfile);
1382
+		} else {
1383
+			fprintf(fd, "%d\n", (int)getpid());
1384
+			fclose(fd);
1385
+		}
1386
+		umask(old_umask);
1387
+	}
1388
+
1372 1389
 	if(cfgopt(copt, "FixStaleSocket")) {
1373 1390
 		/*
1374 1391
 		 * Get the incoming socket details - the way sendmail talks to
... ...
@@ -91,6 +91,13 @@ use this option when NOT using the \-\-bounce option.
91 91
 \fB-o, \-\-outgoing\fR
92 92
 Scan outgoing messages from this machine.
93 93
 .TP
94
+\fB-i, \-\-pidfile=FILE\fR
95
+Notifies clamav\-milter to store its process ID in FILE.
96
+The file must be createable by clamav\-milter,
97
+if the User option is set in
98
+\fBclamav.conf(5)\fR,
99
+then that user must have the rights to create the file.
100
+.TP
94 101
 \fB-p, \-\-postmaster=EMAILADDRESS\fR
95 102
 Sets the e-mail address to send notifications to when the \-\-quiet option
96 103
 is not given.