unbound.c (266114) | unbound.c (276605) |
---|---|
1/* 2 * daemon/unbound.c - main program for unbound DNS resolver daemon. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 70 unchanged lines hidden (view full) --- 79 80#ifdef USE_MINI_EVENT 81# ifdef USE_WINSOCK 82# include "util/winsock_event.h" 83# else 84# include "util/mini_event.h" 85# endif 86#else | 1/* 2 * daemon/unbound.c - main program for unbound DNS resolver daemon. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 70 unchanged lines hidden (view full) --- 79 80#ifdef USE_MINI_EVENT 81# ifdef USE_WINSOCK 82# include "util/winsock_event.h" 83# else 84# include "util/mini_event.h" 85# endif 86#else |
87# include <event.h> | 87# ifdef HAVE_EVENT_H 88# include <event.h> 89# else 90# include "event2/event.h" 91# include "event2/event_struct.h" 92# include "event2/event_compat.h" 93# endif |
88#endif 89 90#ifdef UB_ON_WINDOWS 91# include "winrc/win_svc.h" 92#endif 93 94#ifdef HAVE_NSS 95/* nss3 */ --- 162 unchanged lines hidden (view full) --- 258 return; 259 if((size_t)rlim.rlim_cur < total) { 260 avail = (size_t)rlim.rlim_cur; 261 rlim.rlim_cur = (rlim_t)(total + 10); 262 rlim.rlim_max = (rlim_t)(total + 10); 263#ifdef HAVE_SETRLIMIT 264 if(setrlimit(RLIMIT_NOFILE, &rlim) < 0) { 265 log_warn("setrlimit: %s", strerror(errno)); | 94#endif 95 96#ifdef UB_ON_WINDOWS 97# include "winrc/win_svc.h" 98#endif 99 100#ifdef HAVE_NSS 101/* nss3 */ --- 162 unchanged lines hidden (view full) --- 264 return; 265 if((size_t)rlim.rlim_cur < total) { 266 avail = (size_t)rlim.rlim_cur; 267 rlim.rlim_cur = (rlim_t)(total + 10); 268 rlim.rlim_max = (rlim_t)(total + 10); 269#ifdef HAVE_SETRLIMIT 270 if(setrlimit(RLIMIT_NOFILE, &rlim) < 0) { 271 log_warn("setrlimit: %s", strerror(errno)); |
266#else 267 if(1) { | |
268#endif 269 log_warn("cannot increase max open fds from %u to %u", 270 (unsigned)avail, (unsigned)total+10); 271 /* check that calculation below does not underflow, 272 * with 15 as margin */ 273 if(numthread*perthread_noudp+15 > avail) 274 fatal_exit("too much tcp. not enough fds."); 275 cfg->outgoing_num_ports = (int)((avail 276 - numthread*perthread_noudp 277 - 10 /* safety margin */) /numthread); 278 log_warn("continuing with less udp ports: %u", 279 cfg->outgoing_num_ports); 280 log_warn("increase ulimit or decrease threads, " 281 "ports in config to remove this warning"); 282 return; | 272#endif 273 log_warn("cannot increase max open fds from %u to %u", 274 (unsigned)avail, (unsigned)total+10); 275 /* check that calculation below does not underflow, 276 * with 15 as margin */ 277 if(numthread*perthread_noudp+15 > avail) 278 fatal_exit("too much tcp. not enough fds."); 279 cfg->outgoing_num_ports = (int)((avail 280 - numthread*perthread_noudp 281 - 10 /* safety margin */) /numthread); 282 log_warn("continuing with less udp ports: %u", 283 cfg->outgoing_num_ports); 284 log_warn("increase ulimit or decrease threads, " 285 "ports in config to remove this warning"); 286 return; |
287#ifdef HAVE_SETRLIMIT |
|
283 } | 288 } |
284 log_warn("increased limit(open files) from %u to %u", | 289#endif 290 verbose(VERB_ALGO, "increased limit(open files) from %u to %u", |
285 (unsigned)avail, (unsigned)total+10); 286 } 287#else 288 (void)cfg; 289#endif /* HAVE_GETRLIMIT */ 290#endif /* S_SPLINT_S */ 291} 292 293/** set verbosity, check rlimits, cache settings */ 294static void 295apply_settings(struct daemon* daemon, struct config_file* cfg, | 291 (unsigned)avail, (unsigned)total+10); 292 } 293#else 294 (void)cfg; 295#endif /* HAVE_GETRLIMIT */ 296#endif /* S_SPLINT_S */ 297} 298 299/** set verbosity, check rlimits, cache settings */ 300static void 301apply_settings(struct daemon* daemon, struct config_file* cfg, |
296 int cmdline_verbose) | 302 int cmdline_verbose, int debug_mode) |
297{ 298 /* apply if they have changed */ 299 verbosity = cmdline_verbose + cfg->verbosity; | 303{ 304 /* apply if they have changed */ 305 verbosity = cmdline_verbose + cfg->verbosity; |
306 if (debug_mode > 1) { 307 cfg->use_syslog = 0; 308 cfg->logfile = NULL; 309 } |
|
300 daemon_apply_cfg(daemon, cfg); 301 checkrlimits(cfg); 302} 303 304#ifdef HAVE_KILL 305/** Read existing pid from pidfile. 306 * @param file: file name of pid file. 307 * @return: the pid from the file or -1 if none. --- 342 unchanged lines hidden (view full) --- 650 if(!(cfg = config_create())) 651 fatal_exit("Could not alloc config defaults"); 652 if(!config_read(cfg, cfgfile, daemon->chroot)) { 653 if(errno != ENOENT) 654 fatal_exit("Could not read config file: %s", 655 cfgfile); 656 log_warn("Continuing with default config settings"); 657 } | 310 daemon_apply_cfg(daemon, cfg); 311 checkrlimits(cfg); 312} 313 314#ifdef HAVE_KILL 315/** Read existing pid from pidfile. 316 * @param file: file name of pid file. 317 * @return: the pid from the file or -1 if none. --- 342 unchanged lines hidden (view full) --- 660 if(!(cfg = config_create())) 661 fatal_exit("Could not alloc config defaults"); 662 if(!config_read(cfg, cfgfile, daemon->chroot)) { 663 if(errno != ENOENT) 664 fatal_exit("Could not read config file: %s", 665 cfgfile); 666 log_warn("Continuing with default config settings"); 667 } |
658 apply_settings(daemon, cfg, cmdline_verbose); | 668 apply_settings(daemon, cfg, cmdline_verbose, debug_mode); |
659 660 /* prepare */ 661 if(!daemon_open_shared_ports(daemon)) 662 fatal_exit("could not open ports"); 663 if(!done_setup) { 664 perform_setup(daemon, cfg, debug_mode, &cfgfile); 665 done_setup = 1; 666 } else { --- 63 unchanged lines hidden (view full) --- 730 cmdline_cfg = 1; 731#endif 732 break; 733 case 'v': 734 cmdline_verbose ++; 735 verbosity++; 736 break; 737 case 'd': | 669 670 /* prepare */ 671 if(!daemon_open_shared_ports(daemon)) 672 fatal_exit("could not open ports"); 673 if(!done_setup) { 674 perform_setup(daemon, cfg, debug_mode, &cfgfile); 675 done_setup = 1; 676 } else { --- 63 unchanged lines hidden (view full) --- 740 cmdline_cfg = 1; 741#endif 742 break; 743 case 'v': 744 cmdline_verbose ++; 745 verbosity++; 746 break; 747 case 'd': |
738 debug_mode = 1; | 748 debug_mode++; |
739 break; 740 case 'w': 741 winopt = optarg; 742 break; 743 case '?': 744 case 'h': 745 default: 746 usage(); --- 24 unchanged lines hidden --- | 749 break; 750 case 'w': 751 winopt = optarg; 752 break; 753 case '?': 754 case 'h': 755 default: 756 usage(); --- 24 unchanged lines hidden --- |