]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2454] Need way to set file descriptor limit.
authorBrian Utterback <utterback@ntp.org>
Sat, 3 Aug 2013 19:13:34 +0000 (15:13 -0400)
committerBrian Utterback <utterback@ntp.org>
Sat, 3 Aug 2013 19:13:34 +0000 (15:13 -0400)
[Bug 2453] Need a way to avoid calling mlockall.
[Bug 2451] rlimit command is missing from the table of contents in miscopt.html

bk: 51fd565eKrXuK0C7pHv9hFOwsJVrHQ

ChangeLog
html/miscopt.html
html/scripts/miscopt.txt
include/ntp_config.h
ntpd/keyword-gen.c
ntpd/ntp.conf.def
ntpd/ntp_config.c
ntpd/ntp_parser.y
ntpd/ntpd.c

index 82869660152126ff7e63af054115523cda1b99cd..46ae69640c4da3339187500da7759a040f4a24fc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+* [Bug 2454] Need way to set file descriptor limit. 
+* [Bug 2453] Need a way to avoid calling mlockall. 
+* [Bug 2451] rlimit command is missing from the table of contents in miscopt.html 
 (4.2.7p380) 2013/08/03 Released by Harlan Stenn <stenn@ntp.org>
 * CID 984511: Some systems have different printf needs for sizeof.
 (4.2.7p379) 2013/08/02 Released by Harlan Stenn <stenn@ntp.org>
index ba284214e2b5860e78cafa38e6d69ffde67d2c04..d4ee126cc293905fed5c7ffb05a883810b72fb57 100644 (file)
   <dd>
     <dl>
       <dt><tt>memlock <i>Nmegabytes</i></tt></dt>
-      <dd>Specify the number of megabytes of memory that can be allocated.  Probably only available under Linux, this option is useful when dropping root (the <tt>-i</tt> option).   The default is 32  megabytes.</dd>
+      <dd>Specify the number of megabytes of memory that can be allocated.  Probably only available under Linux, this option is useful when dropping root (the <tt>-i</tt> option).   The default is 32  megabytes. Setting this to zero will prevent any attemp to lock memory.</dd>
       <dt><tt>stacklimit <i>N4kPages</i></tt></dt>
       <dd>Specifies the maximum size of the process stack on systems with the <tt>mlockall()</tt> function. Defaults to 50 4k pages (200 4k pages in OpenBSD).</dd>
+      <dt><tt>filenum <i>N4kPages</i></tt></dt>
+      <dd>Specifies the maximum number of file descriptors ntp may have open at the same time. Defaults to system deault.</dd>
     </dl>
   </dd>
   <dt id="tos"><tt>tos [beacon <i>beacon</i> | ceiling <i>ceiling</i> | cohort {0 | 1} | floor <i>floor</i> | maxclock <i>maxclock </i>| maxdist <i>maxdist</i> | minclock <i>minclock</i> | mindist <i>mindist </i>| minsane <i>minsane</i> | orphan <i>stratum</i> | orphanwait <em>delay</em>]</tt></dt>
index 201718fc9b02370f4e40e40231387f85ea65aa97..64987c8b1efa2c2d29362b2ea1fff7a7bcb8ccd5 100644 (file)
@@ -13,6 +13,7 @@ document.write("<p>Miscellaneous Commands and Options</p><ul>\
 <li class='inline'><a href='miscopt.html#saveconfigdir'>saveconfigdir - specify saveconfig directory</a></li>\
 <li class='inline'><a href='miscopt.html#setvar'>setvar - set system variables</a></li>\
 <li class='inline'><a href='miscopt.html#tinker'>tinker - modify sacred system parameters (dangerous)</a></li>\
+<li class='inline'><a href='miscopt.html#rlimit'>rlimit - alters certain process storage allocation limits</a></li>\
 <li class='inline'><a href='miscopt.html#tos'>tos - modify service parameters</a></li>\
 <li class='inline'><a href='miscopt.html#trap'>trap - set trap address</a></li>\
 <li class='inline'><a href='miscopt.html#ttl'>ttl - set time to live</a></li>\
index 9c2f055856e01050580cc4909483ab67bb3e22c9..982594e4c6823627e7d58facebd9cf3f75b5d3f6 100644 (file)
@@ -46,6 +46,9 @@
 extern int     cmdline_server_count;
 extern char ** cmdline_servers;
 
+/* set to zero if admin doesn't want memory locked */
+extern int     do_memlock;
+
 typedef struct int_range_tag {
        int     first;
        int     last;
index dfc39982bdf6ff33f81e6cd8347525eeaa09f179..d4f77588d60cd56c53fb7f8e6b8818a571e81c9b 100644 (file)
@@ -202,6 +202,7 @@ struct key_tok ntp_keywords[] = {
 /* rlimit_option */
 { "memlock",           T_Memlock,              FOLLBY_TOKEN },
 { "stacksize",         T_Stacksize,            FOLLBY_TOKEN },
+{ "filenum",           T_Filenum,              FOLLBY_TOKEN },
 /* tinker_option */
 { "step",              T_Step,                 FOLLBY_TOKEN },
 { "panic",             T_Panic,                FOLLBY_TOKEN },
index 7a37f352d12261723b37534418f7dfdf625f2416..8fd3629ae6e339a35d7ad48d8f29f95e9a3ade6e 100644 (file)
@@ -2663,6 +2663,7 @@ pulses will not be suppressed.
 .Oo
 .Cm memlock Ar Nmegabytes |
 .Cm stacklimit Ar N4kPages
+.Cm filenum Ar Nfiledescriptors
 .Oc
 .Xc
 .Bl -tag -width indent
@@ -2672,9 +2673,11 @@ Probably only available under Linux, this option is useful
 when dropping root (the
 .Fl i
 option).
-The default is 32 megabytes.
+The default is 32 megabytes. Setting this to zero will prevent any attemp to lock memory.
 .It Cm stacklimit Ar N4kPages
 Specifies the maximum size of the process stack on systems with the
+.It Cm filenum Ar Nfiledescriptors
+Specifies the maximum number of file descriptors ntpd may have open at once. Defaults to the system default.
 .Fn mlockall
 function.
 Defaults to 50 4k pages (200 4k pages in OpenBSD).
index 28639af8592ca2d188834b3a8911303ac36e8b84..5cb6d2c222548df5f8b8b856c54b926ffb3c8b60 100644 (file)
@@ -58,6 +58,9 @@
 int    cmdline_server_count;
 char **        cmdline_servers;
 
+/* set to zero if admin doesn't want memory locked */
+int    do_memlock = 1;
+
 /*
  * "logconfig" building blocks
  */
@@ -2602,15 +2605,19 @@ config_rlimit(
                        break;
 
                case T_Memlock:
+                       if (rlimit_av->value.i != 0) {
 #if defined(HAVE_MLOCKALL) && defined(RLIMIT_MEMLOCK)
-                       ntp_rlimit(RLIMIT_MEMLOCK,
-                                  (rlim_t)(rlimit_av->value.i * 1024 * 1024),
-                                  1024 * 1024,
-                                  "MB");
+                               ntp_rlimit(RLIMIT_MEMLOCK,
+                                          (rlim_t)(rlimit_av->value.i * 1024 * 1024),
+                                          1024 * 1024,
+                                          "MB");
 #else
-                       /* STDERR as well would be fine... */
-                       msyslog(LOG_WARNING, "'rlimit memlock' specified but is not available on this system.");
+                               /* STDERR as well would be fine... */
+                               msyslog(LOG_WARNING, "'rlimit memlock' specified but is not available on this system.");
 #endif /* !(HAVE_MLOCKALL && RLIMIT_MEMLOCK) */
+                       } else {
+                               do_memlock = 0;
+                       }
                        break;
 
                case T_Stacksize:
@@ -2624,6 +2631,19 @@ config_rlimit(
                        msyslog(LOG_WARNING, "'rlimit stacksize' specified but is not available on this system.");
 #endif /* !(HAVE_MLOCKALL && RLIMIT_STACK) */
                        break;
+
+               case T_Filenum:
+#if defined(RLIMIT_NOFILE)
+                       ntp_rlimit(RLIMIT_NOFILE,
+                                 (rlim_t)(rlimit_av->value.i),
+                                 1,
+                                 "");
+#else
+                       /* STDERR as well would be fine... */
+                       msyslog(LOG_WARNING, "'rlimit filenum' specified but is not available on this system.");
+#endif /* !(RLIMIT_NOFILE) */
+                       break;
+
                }
        }
 }
@@ -4869,6 +4889,20 @@ ntp_rlimit(
                break;
 #endif /* RLIMIT_MEMLOCK */
 
+#ifdef RLIMIT_NOFILE
+           case RLIMIT_NOFILE:
+               /*
+                * For large systems the default file descriptor limit may
+                * not be enough.  
+                */
+               DPRINTF(2, ("ntp_rlimit: NOFILE: %d %s\n",
+                       (int)(rl_value / rl_scale), rl_sstr));
+               rl.rlim_cur = rl.rlim_max = rl_value;
+               if (setrlimit(RLIMIT_NOFILE, &rl) == -1)
+                       msyslog(LOG_ERR, "Cannot set RLIMIT_NOFILE: %m");
+               break;
+#endif /* RLIMIT_NOFILE */
+
            case RLIMIT_STACK:
                /*
                 * Provide a way to set the stack limit to something
index f077735ea02e541dc396e4042a62ced522837f49..a13fbb62585ecf6c6ae49788631773bfa04356be 100644 (file)
 %token <Integer>       T_False
 %token <Integer>       T_File
 %token <Integer>       T_Filegen
+%token <Integer>       T_Filenum
 %token <Integer>       T_Flag1
 %token <Integer>       T_Flag2
 %token <Integer>       T_Flag3
@@ -1005,6 +1006,7 @@ rlimit_option
 rlimit_option_keyword
        :       T_Memlock
        |       T_Stacksize
+       |       T_Filenum
        ;
 
 
index 4fcdf7421e3e4cc3d221460d3dc65a2210edc253..a01b889dea947e15b039fd5317a2cdfd32de2c57 100644 (file)
@@ -686,6 +686,7 @@ ntpdmain(
        }
 # endif
 
+       /* Setup stack size in preparation for locking pages in memory. */
 # if defined(HAVE_MLOCKALL)
 #  ifdef HAVE_SETRLIMIT
        ntp_rlimit(RLIMIT_STACK, DFLT_RLIMIT_STACK * 4096, 4096, "4k");
@@ -699,12 +700,6 @@ ntpdmain(
        ntp_rlimit(RLIMIT_MEMLOCK, DFLT_RLIMIT_MEMLOCK * 1024 * 1024, 1024 * 1024, "MB");
 #   endif      /* RLIMIT_MEMLOCK */
 #  endif       /* HAVE_SETRLIMIT */
-       /*
-        * lock the process into memory
-        */
-       if (!HAVE_OPT(SAVECONFIGQUIT) &&
-           0 != mlockall(MCL_CURRENT|MCL_FUTURE))
-               msyslog(LOG_ERR, "mlockall(): %m");
 # else /* !HAVE_MLOCKALL follows */
 #  ifdef HAVE_PLOCK
 #   ifdef PROCLOCK
@@ -717,22 +712,7 @@ ntpdmain(
                msyslog(LOG_ERR,
                        "Cannot adjust stack limit for plock: %m");
 #    endif     /* _AIX */
-       /*
-        * lock the process into memory
-        */
-       if (!HAVE_OPT(SAVECONFIGQUIT) && 0 != plock(PROCLOCK))
-               msyslog(LOG_ERR, "plock(PROCLOCK): %m");
-#   else       /* !PROCLOCK follows  */
-#    ifdef TXTLOCK
-       /*
-        * Lock text into ram
-        */
-       if (!HAVE_OPT(SAVECONFIGQUIT) && 0 != plock(TXTLOCK))
-               msyslog(LOG_ERR, "plock(TXTLOCK) error: %m");
-#    else      /* !TXTLOCK follows */
-       msyslog(LOG_ERR, "plock() - don't know what to lock!");
-#    endif     /* !TXTLOCK */
-#   endif      /* !PROCLOCK */
+#   endif      /* PROCLOCK */
 #  endif       /* HAVE_PLOCK */
 # endif        /* !HAVE_MLOCKALL */
 
@@ -795,6 +775,38 @@ ntpdmain(
         * since this will definitely be different for the gizmo board.
         */
        getconfig(argc, argv);
+
+       if (do_memlock) {
+# if defined(HAVE_MLOCKALL)
+               /*
+                * lock the process into memory
+                */
+               if (!HAVE_OPT(SAVECONFIGQUIT) &&
+                   0 != mlockall(MCL_CURRENT|MCL_FUTURE))
+                       msyslog(LOG_ERR, "mlockall(): %m");
+# else /* !HAVE_MLOCKALL follows */
+#  ifdef HAVE_PLOCK
+#   ifdef PROCLOCK
+               /*
+                * lock the process into memory
+                */
+               if (!HAVE_OPT(SAVECONFIGQUIT) && 0 != plock(PROCLOCK))
+                       msyslog(LOG_ERR, "plock(PROCLOCK): %m");
+#   else       /* !PROCLOCK follows  */
+#    ifdef TXTLOCK
+               /*
+                * Lock text into ram
+                */
+               if (!HAVE_OPT(SAVECONFIGQUIT) && 0 != plock(TXTLOCK))
+                       msyslog(LOG_ERR, "plock(TXTLOCK) error: %m");
+#    else      /* !TXTLOCK follows */
+               msyslog(LOG_ERR, "plock() - don't know what to lock!");
+#    endif     /* !TXTLOCK */
+#   endif      /* !PROCLOCK */
+#  endif       /* HAVE_PLOCK */
+# endif        /* !HAVE_MLOCKALL */
+       }
+
        loop_config(LOOP_DRIFTINIT, 0);
        report_event(EVNT_SYSRESTART, NULL, NULL);
        initializing = FALSE;