[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
+* [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>
<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>
<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>\
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;
/* 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 },
.Oo
.Cm memlock Ar Nmegabytes |
.Cm stacklimit Ar N4kPages
+.Cm filenum Ar Nfiledescriptors
.Oc
.Xc
.Bl -tag -width indent
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).
int cmdline_server_count;
char ** cmdline_servers;
+/* set to zero if admin doesn't want memory locked */
+int do_memlock = 1;
+
/*
* "logconfig" building blocks
*/
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:
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;
+
}
}
}
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
%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
rlimit_option_keyword
: T_Memlock
| T_Stacksize
+ | T_Filenum
;
}
# 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");
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
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 */
* 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;