#include <pwd.h>
#include <sys/resource.h>
+/** if we want to enable coredumps after daemonize */
+static int enable_coredumps = 0;
+
/** print usage. */
static void usage()
{
printf("-h this help\n");
printf("-c file config file to read, unbound.conf(5).\n");
printf("-d do not fork into the background.\n");
+ printf("-C try to enable coredumps after fork into background.\n");
printf("-v verbose (multiple times increase verbosity)\n");
printf("Version %s\n", PACKAGE_VERSION);
printf("BSD licensed, see LICENSE in source package for details.\n");
log_warn("getrlimit: %s", strerror(errno));
return;
}
+ if(rlim.rlim_cur == RLIM_INFINITY)
+ return;
if((size_t)rlim.rlim_cur < total) {
log_err("Not enough sockets available. Increase "
"ulimit(open files).");
}
}
+/** printout rlimit prettily */
+static void
+print_rlim_pretty(const char* str, struct rlimit* rlim)
+{
+ if(rlim->rlim_cur == RLIM_INFINITY && rlim->rlim_max == RLIM_INFINITY)
+ log_info("%s unlimited, max unlimited", str);
+ else if(rlim->rlim_max == RLIM_INFINITY)
+ log_info("%s %d, max unlimited", str, (int)rlim->rlim_cur);
+ else if(rlim->rlim_cur == RLIM_INFINITY)
+ log_info("%s unlimited, max %d", str, (int)rlim->rlim_max);
+ else log_info("%s %d, max %d", str, (int)rlim->rlim_cur,
+ (int)rlim->rlim_max);
+}
+
+/** try to enable coredumps */
+static void
+do_coredump_enable()
+{
+ struct rlimit rlim;
+ if(getrlimit(RLIMIT_CORE, &rlim) < 0) {
+ log_warn("getrlimit(core): %s", strerror(errno));
+ return;
+ }
+ print_rlim_pretty("rlimit(core) is", &rlim);
+ if(rlim.rlim_cur == RLIM_INFINITY && rlim.rlim_max == RLIM_INFINITY) {
+ return;
+ }
+ if(rlim.rlim_cur > 10000) {
+ return;
+ }
+ rlim.rlim_cur = RLIM_INFINITY;
+ rlim.rlim_max = RLIM_INFINITY;
+ if(setrlimit(RLIMIT_CORE, &rlim) < 0) {
+ log_warn("setrlimit(core): %s", strerror(errno));
+ return;
+ }
+ if(getrlimit(RLIMIT_CORE, &rlim) < 0) {
+ log_warn("getrlimit(core, upd): %s", strerror(errno));
+ return;
+ }
+ print_rlim_pretty("updated rlimit(core) is", &rlim);
+}
+
/** to changedir, logfile */
static void
apply_dir(struct daemon* daemon, struct config_file* cfg, int cmdline_verbose)
log_init(cfg->logfile);
if(!debug_mode && cfg->do_daemonize) {
detach(cfg);
+ if(enable_coredumps)
+ do_coredump_enable();
}
if(cfg->pidfile && cfg->pidfile[0]) {
writepid(cfg->pidfile, getpid());
log_init(NULL);
/* parse the options */
- while( (c=getopt(argc, argv, "c:dhv")) != -1) {
+ while( (c=getopt(argc, argv, "Cc:dhv")) != -1) {
switch(c) {
+ case 'C':
+ enable_coredumps = 1;
+ break;
case 'c':
cfgfile = optarg;
break;
-.ig
-unbound.8 -- unbound manual
-
-Copyright (c) 2007, NLnet Labs. All rights reserved.
-
-This software is open source.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-
-Redistributions in binary form must reproduce the above copyright notice,
-this list of conditions and the following disclaimer in the documentation
-and/or other materials provided with the distribution.
-
-Neither the name of the NLNET LABS nor the names of its contributors may
-be used to endorse or promote products derived from this software without
-specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-..
+.\"
+.\" unbound.8 -- unbound manual
+.\"
+.\" Copyright (c) 2007, NLnet Labs. All rights reserved.
+.\"
+.\" See LICENSE for the license.
+.\"
+.\"
.Dd @date@
.Dt unbound 8
.Sh NAME
.Op Fl h
.Op Fl d
.Op Fl v
+.Op Fl C
.Op Fl c Ar cfgfile
.Sh DESCRIPTION
Increase verbosity. If given multiple times, more information is logged.
This is in addition to the verbosity (if any) from the config file.
+.It Fl C
+Try to enable coredumps after forking into the background. If you do not
+have permission to alter the ulimits, then this will fail. Performs
+the equivalent of 'ulimit -c unlimited'. For debug purposes.
+
.El
.Sh SEE ALSO
.Xr unbound.conf 5 .