git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1302 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2005/02/02 17:34:04... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Wed Feb 2 08:32:46 GMT 2005 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * clamav-milter: Call watchdog when neither SESSION nor --external is |
|
4 |
+ given |
|
5 |
+ |
|
1 | 6 |
Tue Feb 1 14:47:21 GMT 2005 (njh) |
2 | 7 |
---------------------------------- |
3 | 8 |
* libclamav/blob.c: Sanitise tab characters in filenames ("Heinz Martin" |
... | ... |
@@ -26,6 +26,9 @@ |
26 | 26 |
* |
27 | 27 |
* Change History: |
28 | 28 |
* $Log: clamav-milter.c,v $ |
29 |
+ * Revision 1.176 2005/02/02 08:30:24 nigelhorne |
|
30 |
+ * Call watchdog when neither SESSION not external is given |
|
31 |
+ * |
|
29 | 32 |
* Revision 1.175 2005/02/01 08:54:45 nigelhorne |
30 | 33 |
* X-Virus-Status work |
31 | 34 |
* |
... | ... |
@@ -536,9 +539,9 @@ |
536 | 536 |
* Revision 1.6 2003/09/28 16:37:23 nigelhorne |
537 | 537 |
* Added -f flag use MaxThreads if --max-children not set |
538 | 538 |
*/ |
539 |
-static char const rcsid[] = "$Id: clamav-milter.c,v 1.175 2005/02/01 08:54:45 nigelhorne Exp $"; |
|
539 |
+static char const rcsid[] = "$Id: clamav-milter.c,v 1.176 2005/02/02 08:30:24 nigelhorne Exp $"; |
|
540 | 540 |
|
541 |
-#define CM_VERSION "0.81f" |
|
541 |
+#define CM_VERSION "0.81g" |
|
542 | 542 |
|
543 | 543 |
#if HAVE_CONFIG_H |
544 | 544 |
#include "clamav-config.h" |
... | ... |
@@ -764,9 +767,7 @@ static void setsubject(SMFICTX *ctx, const char *virusname); |
764 | 764 |
static int clamfi_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t len); |
765 | 765 |
static int isLocalAddr(in_addr_t addr); |
766 | 766 |
static void clamdIsDown(void); |
767 |
-#ifdef SESSION |
|
768 | 767 |
static void *watchdog(void *a); |
769 |
-#endif |
|
770 | 768 |
static int logg_facility(const char *name); |
771 | 769 |
static void quit(void); |
772 | 770 |
static void broadcast(const char *mess); |
... | ... |
@@ -901,10 +902,10 @@ static struct session { |
901 | 901 |
} *sessions; /* max_children elements in the array */ |
902 | 902 |
static pthread_mutex_t sstatus_mutex = PTHREAD_MUTEX_INITIALIZER; |
903 | 903 |
|
904 |
-static pthread_cond_t watchdog_cond = PTHREAD_COND_INITIALIZER; |
|
905 |
- |
|
906 | 904 |
#endif /*SESSION*/ |
907 | 905 |
|
906 |
+static pthread_cond_t watchdog_cond = PTHREAD_COND_INITIALIZER; |
|
907 |
+ |
|
908 | 908 |
#ifndef SHUT_RD |
909 | 909 |
#define SHUT_RD 0 |
910 | 910 |
#endif |
... | ... |
@@ -1004,9 +1005,7 @@ main(int argc, char **argv) |
1004 | 1004 |
const struct cfgstruct *cpt; |
1005 | 1005 |
const char *pidfile = NULL; |
1006 | 1006 |
char version[VERSION_LENGTH + 1]; |
1007 |
-#ifdef SESSION |
|
1008 | 1007 |
pthread_t tid; |
1009 |
-#endif |
|
1010 | 1008 |
struct smfiDesc smfilter = { |
1011 | 1009 |
"ClamAv", /* filter name */ |
1012 | 1010 |
SMFI_VERSION, /* version code -- leave untouched */ |
... | ... |
@@ -1877,8 +1876,8 @@ main(int argc, char **argv) |
1877 | 1877 |
#ifdef SESSION |
1878 | 1878 |
/* FIXME: add localSocket support to watchdog */ |
1879 | 1879 |
if(localSocket == NULL) |
1880 |
- pthread_create(&tid, NULL, watchdog, NULL); |
|
1881 | 1880 |
#endif |
1881 |
+ pthread_create(&tid, NULL, watchdog, NULL); |
|
1882 | 1882 |
|
1883 | 1883 |
if((cpt = cfgopt(copt, "PidFile")) != NULL) |
1884 | 1884 |
pidFile = cpt->strarg; |
... | ... |
@@ -4362,8 +4361,8 @@ qfile(struct privdata *privdata, const char *sendmailId, const char *virusname) |
4362 | 4362 |
#ifdef C_DARWIN |
4363 | 4363 |
*ptr &= '\177'; |
4364 | 4364 |
#endif |
4365 |
-#if defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32) |
|
4366 |
- if(strchr("/*?<>|\"+=,;: ", *ptr)) |
|
4365 |
+#if defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32) || defined(C_OS2) |
|
4366 |
+ if(strchr("/*?<>|\\\"+=,;:\t ", *ptr)) |
|
4367 | 4367 |
#else |
4368 | 4368 |
if(*ptr == '/') |
4369 | 4369 |
#endif |
... | ... |
@@ -4762,6 +4761,64 @@ watchdog(void *a) |
4762 | 4762 |
cli_dbgmsg("watchdog quits\n"); |
4763 | 4763 |
return NULL; |
4764 | 4764 |
} |
4765 |
+#else /*!SESSION*/ |
|
4766 |
+/* |
|
4767 |
+ * Reload the database from time to time, when using the internal scanner |
|
4768 |
+ */ |
|
4769 |
+static void * |
|
4770 |
+watchdog(void *a) |
|
4771 |
+{ |
|
4772 |
+ static pthread_mutex_t watchdog_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
4773 |
+ |
|
4774 |
+ if(external) |
|
4775 |
+ return NULL; |
|
4776 |
+ |
|
4777 |
+ while(!quitting) { |
|
4778 |
+ struct timespec ts; |
|
4779 |
+ struct timeval tp; |
|
4780 |
+ |
|
4781 |
+ gettimeofday(&tp, NULL); |
|
4782 |
+ |
|
4783 |
+ ts.tv_sec = tp.tv_sec + readTimeout - 1; |
|
4784 |
+ ts.tv_nsec = tp.tv_usec * 1000; |
|
4785 |
+ cli_dbgmsg("watchdog sleeps\n"); |
|
4786 |
+ pthread_mutex_lock(&watchdog_mutex); |
|
4787 |
+ /* |
|
4788 |
+ * Sometimes this returns EPIPE which isn't listed as a |
|
4789 |
+ * return value in the Linux man page for pthread_cond_timedwait |
|
4790 |
+ * so I'm not sure why it happens |
|
4791 |
+ */ |
|
4792 |
+ switch(pthread_cond_timedwait(&watchdog_cond, &watchdog_mutex, &ts)) { |
|
4793 |
+ case ETIMEDOUT: |
|
4794 |
+ case 0: |
|
4795 |
+ break; |
|
4796 |
+ default: |
|
4797 |
+ perror("pthread_cond_timedwait"); |
|
4798 |
+ } |
|
4799 |
+ cli_dbgmsg("watchdog wakes\n"); |
|
4800 |
+ pthread_mutex_unlock(&watchdog_mutex); |
|
4801 |
+ |
|
4802 |
+ /* |
|
4803 |
+ * Re-load the database if the server's not busy. |
|
4804 |
+ * TODO: If a reload is needed go into a mode when |
|
4805 |
+ * new scans aren't accepted, to force the number |
|
4806 |
+ * of children to 0 so that we can reload, |
|
4807 |
+ * otherwise a reload may not occur on overloaded |
|
4808 |
+ * servers |
|
4809 |
+ */ |
|
4810 |
+ pthread_mutex_lock(&n_children_mutex); |
|
4811 |
+ if((n_children == 0) && (cl_statchkdir(&dbstat) == 1)) { |
|
4812 |
+ cl_statfree(&dbstat); |
|
4813 |
+ if(use_syslog) |
|
4814 |
+ syslog(LOG_WARNING, _("Loading new database")); |
|
4815 |
+ if(loadDatabase() != 0) |
|
4816 |
+ exit(EX_CONFIG); |
|
4817 |
+ } |
|
4818 |
+ pthread_mutex_unlock(&n_children_mutex); |
|
4819 |
+ } |
|
4820 |
+ cli_dbgmsg("watchdog quits\n"); |
|
4821 |
+ return NULL; |
|
4822 |
+} |
|
4765 | 4823 |
#endif |
4766 | 4824 |
|
4767 | 4825 |
static const struct { |