Here is a patch for clamd which makes it raise the process's file
descriptor limit to the maximum supported by the OS, as long as it is safe
for the fd poll method used.

Please can this be considered for inclusion into CVS ?

Thanks,

Andy
diff -r -u clamav-devel/clamd/clamd.c clamav-devel-new/clamd/clamd.c
--- clamav-devel/clamd/clamd.c  2005-01-18 23:51:37.000000000 +0000
+++ clamav-devel-new/clamd/clamd.c      2005-02-18 23:15:29.756581000 +0000
@@ -37,7 +37,7 @@
 #include <syslog.h>
 #endif
 
-#ifdef C_LINUX
+#ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
 
@@ -61,6 +61,47 @@
 
 short debug_mode = 0, logok = 0;
 
+static void set_limits()
+{
+#ifdef HAVE_SYS_RESOURCE_H
+        struct rlimit r;
+        rlim_t old;
+#ifdef HAVE_STRERROR_R
+       char buff[BUFFSIZE + 1];
+#endif
+
+    if (getrlimit(RLIMIT_NOFILE, &r) == -1)
+    {
+#ifdef HAVE_STRERROR_R
+       logg("!getrlimit() failed: %s\n", strerror_r(errno, buff, BUFFSIZE));
+#else
+       logg("!getrlimit() failed.\n");
+#endif
+       return;
+    }
+
+    old = r.rlim_cur;
+    r.rlim_cur = r.rlim_max;
+
+#ifndef HAVE_POLL
+    if (r.rlim_cur > DEFAULT_FD_SETSIZE)
+       r.rlim_cur = DEFAULT_FD_SETSIZE;
+#endif
+
+    if (setrlimit(RLIMIT_NOFILE, &r) == -1)
+    {
+#ifdef HAVE_STRERROR_R
+       logg("!setrlimit() failed: %s\n", strerror_r(errno, buff, BUFFSIZE));
+#else
+       logg("!setrlimit() failed.\n");
+#endif
+       return;
+    }
+
+    logg("File descriptor limit increased (%d -> %d)", old, r.rlim_cur);
+#endif
+}
+
 void clamd(struct optstruct *opt)
 {
        struct cfgstruct *copt, *cpt;
@@ -175,6 +216,8 @@
 
     logg("*Verbose logging activated.\n");
 
+    set_limits();
+
 #ifdef C_LINUX
     procdev = 0;
     if(stat("/proc", &sb) != -1 && !sb.st_size)
diff -r -u clamav-devel/configure.in clamav-devel-new/configure.in
--- clamav-devel/configure.in   2005-02-13 23:01:49.000000000 +0000
+++ clamav-devel-new/configure.in       2005-02-18 20:11:53.030687000 +0000
@@ -38,7 +38,7 @@
 AC_DEFINE(FILEBUFF, 8192,   [file i/o buffer size])
 
 AC_HEADER_STDC
-AC_CHECK_HEADERS(stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h 
sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h 
sys/param.h sys/stat.h sys/types.h malloc.h poll.h regex.h limits.h sys/filio.h 
sys/uio.h)
+AC_CHECK_HEADERS(stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h 
sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h 
sys/param.h sys/stat.h sys/types.h malloc.h poll.h regex.h limits.h sys/filio.h 
sys/uio.h sys/resource.h)
 AC_CHECK_HEADER(syslog.h,AC_DEFINE(USE_SYSLOG,1,[use syslog]),)
 
 AC_TYPE_OFF_T
_______________________________________________
http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel

Reply via email to