gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r4013 - in GNUnet: . contrib src/include src/server src/uti


From: grothoff
Subject: [GNUnet-SVN] r4013 - in GNUnet: . contrib src/include src/server src/util/os
Date: Fri, 22 Dec 2006 16:44:07 -0800 (PST)

Author: grothoff
Date: 2006-12-22 16:43:59 -0800 (Fri, 22 Dec 2006)
New Revision: 4013

Modified:
   GNUnet/configure.ac
   GNUnet/contrib/config-daemon.scm
   GNUnet/src/include/gnunet_util_os.h
   GNUnet/src/include/platform.h
   GNUnet/src/server/gnunetd.c
   GNUnet/src/server/startup.c
   GNUnet/src/server/startup.h
   GNUnet/src/util/os/osconfig.c
Log:
fd limit patch, mostly for OS X

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2006-12-22 06:36:54 UTC (rev 4012)
+++ GNUnet/configure.ac 2006-12-23 00:43:59 UTC (rev 4013)
@@ -433,7 +433,7 @@
 AC_CHECK_HEADERS([fcntl.h math.h errno.h limits.h stdio.h locale.h sys/stat.h 
sys/types.h pthread.h],,AC_MSG_ERROR([Compiling GNUnet requires standard UNIX 
headers files]))
 
 # Checks for headers that are only required on some systems or opional (and 
where we do NOT abort if they are not there)
-AC_CHECK_HEADERS([langinfo.h sys/param.h sys/mount.h sys/statvfs.h sys/vfs.h 
arpa/inet.h fcntl.h libintl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h 
sys/time.h unistd.h kstat.h sys/sysinfo.h kvm.h sys/file.h])
+AC_CHECK_HEADERS([langinfo.h sys/param.h sys/mount.h sys/statvfs.h sys/vfs.h 
arpa/inet.h fcntl.h libintl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h 
sys/time.h unistd.h kstat.h sys/sysinfo.h kvm.h sys/file.h sys/resource.h])
 
 # Check for GMP header (and abort if not present)
 AC_CHECK_HEADERS([gmp.h],,AC_MSG_ERROR([Compiling GNUnet requires gmp.h (from 
the GNU MP library, libgmp)]))
@@ -462,7 +462,7 @@
 AC_HEADER_SYS_WAIT
 AC_TYPE_OFF_T
 AC_TYPE_UID_T
-AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol 
atoll dup2 fdatasync ftruncate gethostbyname gettimeofday memset mkdir mkfifo 
select socket strcasecmp strchr strdup strerror strstr clock_gettime getrusage 
rand uname setlocale getcwd mktime gmtime_r gmtime strlcpy strlcat ftruncate 
stat64 sbrk mmap mremap])
+AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol 
atoll dup2 fdatasync ftruncate gethostbyname gettimeofday memset mkdir mkfifo 
select socket strcasecmp strchr strdup strerror strstr clock_gettime getrusage 
rand uname setlocale getcwd mktime gmtime_r gmtime strlcpy strlcat ftruncate 
stat64 sbrk mmap mremap setrlimit])
 
 # restore LIBS
 LIBS=$SAVE_LIBS

Modified: GNUnet/contrib/config-daemon.scm
===================================================================
--- GNUnet/contrib/config-daemon.scm    2006-12-22 06:36:54 UTC (rev 4012)
+++ GNUnet/contrib/config-daemon.scm    2006-12-23 00:43:59 UTC (rev 4013)
@@ -233,6 +233,19 @@
   (cons 0 36500)
   'advanced) )
 
+(define (daemon-fdlimit builder)
+ (builder
+  "GNUNETD"
+  "FDLIMIT"
+  (_ "What maximum number of open file descriptors should be requested from 
the OS?")
+  (_ 
+"The default of 1024 should be fine for most systems.  If your system can 
support more, increasing the number might help support additional clients on 
machines with plenty of bandwidth.  For embedded systems, a smaller number 
might be acceptable.  This option is mostly for OS X systems where the default 
is too low.  Note that if gnunetd cannot obtain the desired number of file 
descriptors from the operating system, it will print a warning and try to run 
with what it is given." )
+  '()
+  #t
+  1024
+  (cons 64 65536)
+  'rare) )
+
 (define (log-logfile builder)
  (builder
   "GNUNETD"
@@ -515,6 +528,7 @@
     (username builder) 
     (groupname builder) 
     (autostart builder) 
+    (daemon-fdlimit builder) 
     (fs-path builder) 
     (index-path builder) 
     (general-pidfile builder) 

Modified: GNUnet/src/include/gnunet_util_os.h
===================================================================
--- GNUnet/src/include/gnunet_util_os.h 2006-12-22 06:36:54 UTC (rev 4012)
+++ GNUnet/src/include/gnunet_util_os.h 2006-12-23 00:43:59 UTC (rev 4013)
@@ -163,6 +163,13 @@
                                void * cls);
 
 /**
+ * @brief Set maximum number of open file descriptors
+ * @return OK on success, SYSERR on error
+ */
+int os_set_fd_limit(struct GE_Context * ectx,
+                    int n);
+
+/**
  * Set our process priority
  * @return OK on success, SYSERR on error
  */

Modified: GNUnet/src/include/platform.h
===================================================================
--- GNUnet/src/include/platform.h       2006-12-22 06:36:54 UTC (rev 4012)
+++ GNUnet/src/include/platform.h       2006-12-23 00:43:59 UTC (rev 4013)
@@ -145,6 +145,9 @@
 #if HAVE_CTYPE_H
 #include <ctype.h>
 #endif
+#if HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
 
 #include <locale.h>
 #include "gettext.h"

Modified: GNUnet/src/server/gnunetd.c
===================================================================
--- GNUnet/src/server/gnunetd.c 2006-12-22 06:36:54 UTC (rev 4012)
+++ GNUnet/src/server/gnunetd.c 2006-12-23 00:43:59 UTC (rev 4013)
@@ -228,6 +228,7 @@
     GNUNET_fini(ectx, cfg);
     return 1;
   }
+  setFdLimit(ectx, cfg);
   if (OK != checkUpToDate(ectx,
                          cfg)) {
     GE_LOG(ectx,

Modified: GNUnet/src/server/startup.c
===================================================================
--- GNUnet/src/server/startup.c 2006-12-22 06:36:54 UTC (rev 4012)
+++ GNUnet/src/server/startup.c 2006-12-23 00:43:59 UTC (rev 4013)
@@ -57,7 +57,26 @@
   return OK;
 }
 
+int setFdLimit(struct GE_Context * ectx,
+               struct GC_Configuration * cfg) {
+  unsigned long long limit;
 
+  limit = 0;
+  if (0 == GC_get_configuration_value_number(cfg,
+                                            "GNUNETD",
+                                            "FDLIMIT",
+                                            0,
+                                            65536,
+                                            1024,
+                                            &limit)) {
+    if (OK != os_set_fd_limit(ectx,
+                             (int)limit)) {
+      return SYSERR;
+    }
+  }
+  return OK;
+}
+
 static char * getPIDFile(struct GC_Configuration * cfg) {
   char * pif;
 

Modified: GNUnet/src/server/startup.h
===================================================================
--- GNUnet/src/server/startup.h 2006-12-22 06:36:54 UTC (rev 4012)
+++ GNUnet/src/server/startup.h 2006-12-23 00:43:59 UTC (rev 4013)
@@ -34,6 +34,9 @@
 int changeUser(struct GE_Context * ectx,
               struct GC_Configuration * cfg);
 
+int setFdLimit(struct GE_Context * ectx,
+              struct GC_Configuration * cfg);
+
 /**
  * Write our process ID to the pid file.
  */

Modified: GNUnet/src/util/os/osconfig.c
===================================================================
--- GNUnet/src/util/os/osconfig.c       2006-12-22 06:36:54 UTC (rev 4012)
+++ GNUnet/src/util/os/osconfig.c       2006-12-23 00:43:59 UTC (rev 4013)
@@ -23,6 +23,7 @@
  * @file util/os/osconfig.c
  * @brief functions to read or change the OS configuration
  * @author Nils Durner
+ * @author Heikki Lindholm
  */
 
 #include "platform.h"
@@ -94,6 +95,35 @@
 }
 
 /**
+ * @brief Set maximum number of open file descriptors
+ * @return OK on success, SYSERR on error
+ */
+int os_set_fd_limit(struct GE_Context * ectx, 
+                    int n) {
+  if (n == 0)
+    return OK;
+#if HAVE_SETRLIMIT 
+  struct rlimit rlim;
+  int ret;
+
+  rlim.rlim_cur = n;
+  rlim.rlim_max = n;
+  ret = setrlimit(RLIMIT_NOFILE, &rlim);
+  if (ret != 0) {
+    GE_LOG_STRERROR(ectx,
+                    GE_ERROR | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+                    "setrlimit");
+    return SYSERR;
+  }
+#else
+  GE_LOG(ectx,
+         GE_WARNING | GE_USER | GE_ADMIN,
+         _("Setting open descriptor limit not supported.\n"));
+#endif
+  return OK;
+}
+
+/**
  * @brief Checks if we can start GNUnet automatically
  * @return YES if yes, NO otherwise
  */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]