git-svn: trunk@2036
Nigel Horne authored on 2006/06/21 17:54:17... | ... |
@@ -23,7 +23,7 @@ |
23 | 23 |
* |
24 | 24 |
* For installation instructions see the file INSTALL that came with this file |
25 | 25 |
*/ |
26 |
-static char const rcsid[] = "$Id: clamav-milter.c,v 1.245 2006/06/12 09:57:43 njh Exp $"; |
|
26 |
+static char const rcsid[] = "$Id: clamav-milter.c,v 1.246 2006/06/21 08:54:17 njh Exp $"; |
|
27 | 27 |
|
28 | 28 |
#define CM_VERSION "devel-120606" |
29 | 29 |
|
... | ... |
@@ -36,7 +36,6 @@ static char const rcsid[] = "$Id: clamav-milter.c,v 1.245 2006/06/12 09:57:43 nj |
36 | 36 |
#include "target.h" |
37 | 37 |
#include "str.h" |
38 | 38 |
#include "../libclamav/others.h" |
39 |
-#include "strrcpy.h" |
|
40 | 39 |
#include "clamav.h" |
41 | 40 |
#include "table.h" |
42 | 41 |
#include "network.h" |
... | ... |
@@ -1208,6 +1207,8 @@ main(int argc, char **argv) |
1208 | 1208 |
/* |
1209 | 1209 |
* FIXME: Allow connection to remote servers by TCP/IP whilst |
1210 | 1210 |
* connecting to the localserver via a UNIX domain socket |
1211 |
+ * |
|
1212 |
+ * FIXME: Should error if the --servers argument is given |
|
1211 | 1213 |
*/ |
1212 | 1214 |
numServers = 1; |
1213 | 1215 |
} else if(((cpt = cfgopt(copt, "TCPSocket")) != NULL) && cpt->enabled) { |
... | ... |
@@ -1317,6 +1318,10 @@ main(int argc, char **argv) |
1317 | 1317 |
cli_errmsg(_("Can't find any clamd servers\n")); |
1318 | 1318 |
cli_errmsg(_("Check your entry for TCPSocket in %s\n"), |
1319 | 1319 |
cfgfile); |
1320 |
+ if(use_syslog) { |
|
1321 |
+ syslog(LOG_ERR, _("Can't find any clamd server")); |
|
1322 |
+ closelog(); |
|
1323 |
+ } |
|
1320 | 1324 |
return EX_CONFIG; |
1321 | 1325 |
} |
1322 | 1326 |
#endif |
... | ... |
@@ -1762,9 +1767,27 @@ pingServer(int serverNumber) |
1762 | 1762 |
return 0; |
1763 | 1763 |
} |
1764 | 1764 |
if(connect(sock, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) < 0) { |
1765 |
- perror("connect"); |
|
1766 |
- close(sock); |
|
1767 |
- return 0; |
|
1765 |
+ /* |
|
1766 |
+ * During startup there is a race condition: clamd can |
|
1767 |
+ * start and fork, then rc will start clamav-milter |
|
1768 |
+ * before clamd has run accept(2), so we fail to |
|
1769 |
+ * connect. In case this is the situation here, we wait |
|
1770 |
+ * for a couple of seconds and try again. The sync() is |
|
1771 |
+ * because during startup the machine won't be doing |
|
1772 |
+ * much for most of the time, so we may as well do |
|
1773 |
+ * something constructive! |
|
1774 |
+ */ |
|
1775 |
+ sync(); |
|
1776 |
+ sleep(2); |
|
1777 |
+ if(connect(sock, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) < 0) { |
|
1778 |
+ char *hostname = cli_strtok(serverHostNames, |
|
1779 |
+ serverNumber, ":"); |
|
1780 |
+ |
|
1781 |
+ perror(hostname ? hostname : "connect"); |
|
1782 |
+ close(sock); |
|
1783 |
+ free(hostname); |
|
1784 |
+ return 0; |
|
1785 |
+ } |
|
1768 | 1786 |
} |
1769 | 1787 |
} |
1770 | 1788 |
|