... | ... |
@@ -438,6 +438,10 @@ int main(int argc, char **argv) |
438 | 438 |
cl_engine_set_num(engine, CL_ENGINE_DISABLE_PE_STATS, 1); |
439 | 439 |
} |
440 | 440 |
|
441 |
+ if (optget(opts, "StatsTimeout")->enabled) { |
|
442 |
+ cl_engine_set_num(engine, CL_ENGINE_STATS_TIMEOUT, optget(opts, "StatsTimeout")->numarg); |
|
443 |
+ } |
|
444 |
+ |
|
441 | 445 |
if (optget(opts, "StatsHostID")->enabled) { |
442 | 446 |
char *p = optget(opts, "StatsHostID")->strarg; |
443 | 447 |
|
... | ... |
@@ -582,6 +582,10 @@ int scanmanager(const struct optstruct *opts) |
582 | 582 |
cl_engine_set_clcb_stats_add_sample(engine, NULL); |
583 | 583 |
} |
584 | 584 |
|
585 |
+ if (optget(opts, "stats-timeout")->enabled) { |
|
586 |
+ cl_engine_set_num(engine, CL_ENGINE_STATS_TIMEOUT, optget(opts, "StatsTimeout")->numarg); |
|
587 |
+ } |
|
588 |
+ |
|
585 | 589 |
if (optget(opts, "stats-host-id")->enabled) { |
586 | 590 |
char *p = optget(opts, "stats-host-id")->strarg; |
587 | 591 |
|
... | ... |
@@ -763,6 +763,10 @@ void submit_host_info(struct optstruct *opts) |
763 | 763 |
else if (strcmp(hostid, "default")) |
764 | 764 |
cl_engine_set_clcb_stats_get_hostid(engine, get_hostid); |
765 | 765 |
|
766 |
+ if (optget(opts, "stats-timeout")->enabled) { |
|
767 |
+ cl_engine_set_num(engine, CL_ENGINE_STATS_TIMEOUT, optget(opts, "StatsTimeout")->numarg); |
|
768 |
+ } |
|
769 |
+ |
|
766 | 770 |
cl_engine_free(engine); |
767 | 771 |
} |
768 | 772 |
|
... | ... |
@@ -204,7 +204,8 @@ enum cl_engine_field { |
204 | 204 |
CL_ENGINE_MAX_ZIPTYPERCG, /* uint64_t */ |
205 | 205 |
CL_ENGINE_FORCETODISK, /* uint32_t */ |
206 | 206 |
CL_ENGINE_DISABLE_CACHE, /* uint32_t */ |
207 |
- CL_ENGINE_DISABLE_PE_STATS /* uint32_t */ |
|
207 |
+ CL_ENGINE_DISABLE_PE_STATS, /* uint32_t */ |
|
208 |
+ CL_ENGINE_STATS_TIMEOUT /* uint32_t */ |
|
208 | 209 |
}; |
209 | 210 |
|
210 | 211 |
enum bytecode_security { |
... | ... |
@@ -400,6 +400,7 @@ struct cl_engine *cl_engine_new(void) |
400 | 400 |
intel->engine = new; |
401 | 401 |
intel->maxsamples = STATS_MAX_SAMPLES; |
402 | 402 |
intel->maxmem = STATS_MAX_MEM; |
403 |
+ intel->timeout = 10; |
|
403 | 404 |
new->stats_data = intel; |
404 | 405 |
new->cb_stats_add_sample = clamav_stats_add_sample; |
405 | 406 |
new->cb_stats_submit = clamav_stats_submit; |
... | ... |
@@ -542,6 +543,12 @@ int cl_engine_set_num(struct cl_engine *engine, enum cl_engine_field field, long |
542 | 542 |
engine->engine_options &= ~(ENGINE_OPTIONS_DISABLE_PE_STATS); |
543 | 543 |
} |
544 | 544 |
break; |
545 |
+ case CL_ENGINE_STATS_TIMEOUT: |
|
546 |
+ if ((engine->stats_data)) { |
|
547 |
+ cli_intel_t *intel = (cli_intel_t *)(engine->stats_data); |
|
548 |
+ |
|
549 |
+ intel->timeout = (uint32_t)num; |
|
550 |
+ } |
|
545 | 551 |
default: |
546 | 552 |
cli_errmsg("cl_engine_set_num: Incorrect field number\n"); |
547 | 553 |
return CL_EARG; |
... | ... |
@@ -353,7 +353,7 @@ void clamav_stats_submit(struct cl_engine *engine, void *cbdata) |
353 | 353 |
} |
354 | 354 |
|
355 | 355 |
if (json) { |
356 |
- submit_post(STATS_HOST, STATS_PORT, "PUT", "/clamav/1/submit/stats", json); |
|
356 |
+ submit_post(STATS_HOST, STATS_PORT, "PUT", "/clamav/1/submit/stats", json, myintel.timeout); |
|
357 | 357 |
free(json); |
358 | 358 |
} |
359 | 359 |
|
... | ... |
@@ -24,7 +24,7 @@ |
24 | 24 |
#include "libclamav/clamav.h" |
25 | 25 |
#include "libclamav/www.h" |
26 | 26 |
|
27 |
-int connect_host(const char *host, const char *port, int useAsync) |
|
27 |
+int connect_host(const char *host, const char *port, uint32_t timeout, int useAsync) |
|
28 | 28 |
{ |
29 | 29 |
int sockfd; |
30 | 30 |
struct addrinfo hints, *servinfo, *p; |
... | ... |
@@ -67,7 +67,7 @@ int connect_host(const char *host, const char *port, int useAsync) |
67 | 67 |
FD_SET(sockfd, &write_fds); |
68 | 68 |
|
69 | 69 |
/* TODO: Make this timeout configurable */ |
70 |
- tv.tv_sec = 10; |
|
70 |
+ tv.tv_sec = timeout; |
|
71 | 71 |
tv.tv_usec = 0; |
72 | 72 |
if (select(sockfd + 1, &read_fds, &write_fds, NULL, &tv) <= 0) { |
73 | 73 |
close(sockfd); |
... | ... |
@@ -150,7 +150,7 @@ char *encode_data(const char *postdata) |
150 | 150 |
return buf; |
151 | 151 |
} |
152 | 152 |
|
153 |
-void submit_post(const char *host, const char *port, const char *method, const char *url, const char *postdata) |
|
153 |
+void submit_post(const char *host, const char *port, const char *method, const char *url, const char *postdata, uint32_t timeout) |
|
154 | 154 |
{ |
155 | 155 |
int sockfd, n; |
156 | 156 |
unsigned int i; |
... | ... |
@@ -214,7 +214,7 @@ void submit_post(const char *host, const char *port, const char *method, const c |
214 | 214 |
free(encoded); |
215 | 215 |
} |
216 | 216 |
|
217 |
- sockfd = connect_host(host, port, 1); |
|
217 |
+ sockfd = connect_host(host, port, timeout, 1); |
|
218 | 218 |
if (sockfd < 0) { |
219 | 219 |
free(buf); |
220 | 220 |
return; |
... | ... |
@@ -235,7 +235,7 @@ void submit_post(const char *host, const char *port, const char *method, const c |
235 | 235 |
* while it's being processed). Give a ten-second timeout so we don't have a major |
236 | 236 |
* impact on scanning. |
237 | 237 |
*/ |
238 |
- tv.tv_sec = 10; |
|
238 |
+ tv.tv_sec = timeout; |
|
239 | 239 |
tv.tv_usec = 0; |
240 | 240 |
if ((n = select(sockfd+1, &readfds, NULL, NULL, &tv)) <= 0) |
241 | 241 |
break; |
... | ... |
@@ -1,9 +1,9 @@ |
1 | 1 |
#if !defined(_LIBCLAMAV_WWW_H) |
2 | 2 |
#define _LIBCLAMAV_WWW_H |
3 | 3 |
|
4 |
-int connect_host(const char *host, const char *port, int useAsync); |
|
4 |
+int connect_host(const char *host, const char *port, uint32_t timeout, int useAsync); |
|
5 | 5 |
size_t encoded_size(const char *postdata); |
6 | 6 |
char *encode_data(const char *postdata); |
7 |
-void submit_post(const char *host, const char *port, const char *method, const char *url, const char *postdata); |
|
7 |
+void submit_post(const char *host, const char *port, const char *method, const char *url, const char *postdata, uint32_t timeout); |
|
8 | 8 |
|
9 | 9 |
#endif |
... | ... |
@@ -186,6 +186,8 @@ const struct clam_option __clam_options[] = { |
186 | 186 |
|
187 | 187 |
{ "StatsPEDisabled", "disable-pe-stats", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_CLAMSCAN, "Disable submission of PE section statistical data", "no" }, |
188 | 188 |
|
189 |
+ { "StatsTimeout", "stats-timeout", 0, TYPE_NUMBER, MATCH_NUMBER, -1, NULL, 0, OPT_CLAMD | OPT_CLAMSCAN | OPT_FRESHCLAM, "Timeout in seconds to timeout communication with the stats server.", "10" }, |
|
190 |
+ |
|
189 | 191 |
{ "LogFileUnlock", NULL, 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER, "By default the log file is locked for writing and only a single\ndaemon process can write to it. This option disables the lock.", "yes" }, |
190 | 192 |
|
191 | 193 |
{ "LogFileMaxSize", NULL, 0, TYPE_SIZE, MATCH_SIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER, "Maximum size of the log file.\nValue of 0 disables the limit.", "5M" }, |