git-svn: trunk@5000
Török Edvin authored on 2009/04/02 02:19:06... | ... |
@@ -1,3 +1,9 @@ |
1 |
+Wed Apr 1 20:19:00 EEST 2009 (edwin) |
|
2 |
+------------------------------------- |
|
3 |
+ * clamd/server-th.c, clamd/thrmgr.c: Automatically fix MaxQueue |
|
4 |
+ settings (bb #1521). Also use rlim_cur instead of rlim_max, because |
|
5 |
+ that is what the kernel enforces. |
|
6 |
+ |
|
1 | 7 |
Wed Apr 1 19:39:12 EEST 2009 (edwin) |
2 | 8 |
------------------------------------- |
3 | 9 |
* libclamav/pe.c: cli_parseres_special: check size before attempting |
... | ... |
@@ -740,9 +740,9 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
740 | 740 |
|
741 | 741 |
#ifndef C_WINDOWS |
742 | 742 |
if(getrlimit(RLIMIT_FSIZE, &rlim) == 0) { |
743 |
- if(rlim.rlim_max < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_FILESIZE, NULL)) |
|
743 |
+ if(rlim.rlim_cur < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_FILESIZE, NULL)) |
|
744 | 744 |
logg("^System limit for file size is lower than engine->maxfilesize\n"); |
745 |
- if(rlim.rlim_max < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_SCANSIZE, NULL)) |
|
745 |
+ if(rlim.rlim_cur < (rlim_t) cl_engine_get_num(engine, CL_ENGINE_MAX_SCANSIZE, NULL)) |
|
746 | 746 |
logg("^System limit for file size is lower than engine->maxscansize\n"); |
747 | 747 |
} else { |
748 | 748 |
logg("^Cannot obtain resource limits for file size\n"); |
... | ... |
@@ -775,6 +775,11 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
775 | 775 |
else |
776 | 776 |
logg("^Limits: Files limit protection disabled.\n"); |
777 | 777 |
|
778 |
+#if !defined(C_WINDOWS) |
|
779 |
+ if (getrlimit(RLIMIT_CORE, &rlim) == 0) { |
|
780 |
+ logg("*Limits: Core-dump limit is %lu.\n", (unsigned long)rlim.rlim_cur); |
|
781 |
+ } |
|
782 |
+#endif |
|
778 | 783 |
|
779 | 784 |
if(optget(opts, "ScanArchive")->enabled) { |
780 | 785 |
logg("Archive support enabled.\n"); |
... | ... |
@@ -930,10 +935,30 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
930 | 930 |
|
931 | 931 |
logg("*Listening daemon: PID: %u\n", (unsigned int) mainpid); |
932 | 932 |
max_threads = optget(opts, "MaxThreads")->numarg; |
933 |
- acceptdata.max_queue = max_queue = optget(opts, "MaxQueue")->numarg; |
|
933 |
+ max_queue = optget(opts, "MaxQueue")->numarg; |
|
934 | 934 |
acceptdata.commandtimeout = optget(opts, "CommandReadTimeout")->numarg; |
935 | 935 |
readtimeout = optget(opts, "ReadTimeout")->numarg; |
936 | 936 |
|
937 |
+#if !defined(C_WINDOWS) && defined(RLIMIT_NOFILE) |
|
938 |
+ if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) { |
|
939 |
+ if (max_queue*4 > rlim.rlim_cur) { |
|
940 |
+ max_queue = rlim.rlim_cur / 4; |
|
941 |
+ logg("^MaxQueue value too high, lowering to: %d\n", max_queue); |
|
942 |
+ } else if (max_queue < 2*max_threads) { |
|
943 |
+ /* increase it but only if it doesn't exceed limit otherwise */ |
|
944 |
+ int newmax = 2*max_threads; |
|
945 |
+ if (newmax*4 > rlim.rlim_cur) |
|
946 |
+ newmax = rlim.rlim_cur/4; |
|
947 |
+ if (max_queue < newmax) { |
|
948 |
+ max_queue = newmax; |
|
949 |
+ logg("^MaxQueue is lower than twice MaxThreads, increasing to: %d\n", max_queue); |
|
950 |
+ } |
|
951 |
+ } |
|
952 |
+ } |
|
953 |
+#endif |
|
954 |
+ |
|
955 |
+ acceptdata.max_queue = max_queue; |
|
956 |
+ |
|
937 | 957 |
if(optget(opts, "ClamukoScanOnAccess")->enabled) |
938 | 958 |
#ifdef CLAMUKO |
939 | 959 |
{ |
... | ... |
@@ -369,11 +369,6 @@ threadpool_t *thrmgr_new(int max_threads, int idle_timeout, int max_queue, void |
369 | 369 |
return NULL; |
370 | 370 |
} |
371 | 371 |
|
372 |
- if (2*max_threads > max_queue) { |
|
373 |
- logg("!Configuration error: MaxQueue should be at least twice MaxThreads\n"); |
|
374 |
- return NULL; |
|
375 |
- } |
|
376 |
- |
|
377 | 372 |
threadpool = (threadpool_t *) malloc(sizeof(threadpool_t)); |
378 | 373 |
if (!threadpool) { |
379 | 374 |
return NULL; |