Lines Matching +full:cfg +full:-

2  * daemon/unbound.c - main program for unbound DNS resolver daemon.
147 printf("-h this help.\n");
148 printf("-c file config file to read instead of %s\n", CONFIGFILE);
150 printf("-d do not fork into the background.\n");
151 printf("-p do not create a pidfile.\n");
152 printf("-v verbose (more times to increase verbosity).\n");
153 printf("-V show version number and build options.\n");
155 printf("-w opt windows option: \n");
156 printf(" install, remove - manage the services entry\n");
157 printf(" service - used to start from services control panel\n");
174 checkrlimits(struct config_file* cfg)
179 int list = ((cfg->do_udp?1:0) + (cfg->do_tcp?1 +
180 (int)cfg->incoming_num_tcp:0));
181 size_t listen_ifs = (size_t)(cfg->num_ifs==0?
182 ((cfg->do_ip4 && !cfg->if_automatic?1:0) +
183 (cfg->do_ip6?1:0)):cfg->num_ifs);
185 size_t outudpnum = (size_t)cfg->outgoing_num_ports;
186 size_t outtcpnum = cfg->outgoing_num_tcp;
195 int numthread = (cfg->num_threads?cfg->num_threads:1);
200 size_t memsize_expect = cfg->msg_cache_size + cfg->rrset_cache_size
201 + (cfg->do_tcp?cfg->stream_wait_size:0)
202 + (cfg->ip_ratelimit?cfg->ip_ratelimit_size:0)
203 + (cfg->ratelimit?cfg->ratelimit_size:0)
204 + (cfg->dnscrypt?cfg->dnscrypt_shared_secret_cache_size + cfg->dnscrypt_nonce_cache_size:0)
205 + cfg->infra_cache_numhosts * (sizeof(struct infra_key)+sizeof(struct infra_data));
206 if(strstr(cfg->module_conf, "validator") && (cfg->trust_anchor_file_list || cfg->trust_anchor_list || cfg->auto_trust_anchor_file_list || cfg->trusted_keys_file_list)) {
207 memsize_expect += cfg->key_cache_size + cfg->neg_cache_size;
210 if(cfg_has_https(cfg)) {
211 memsize_expect += cfg->http_query_buffer_size + cfg->http_response_buffer_size;
231 strncmp(ub_event_get_version(), "mini-event", 10) == 0) {
233 "mini-event cannot handle more than 1024. Config "
237 cfg->outgoing_num_ports = (int)((1024
238 - numthread*perthread_noudp
239 - 10 /* safety margin */) /numthread);
241 cfg->outgoing_num_ports);
245 strncmp(ub_event_get_version(), "winsock-event", 13) == 0) {
251 cfg->outgoing_num_ports = (int)((64
252 - perthread_noudp
253 - 2/* safety margin */));
255 cfg->outgoing_num_ports);
257 (size_t)cfg->outgoing_num_ports)+misc;
279 cfg->outgoing_num_ports = (int)((avail
280 - numthread*perthread_noudp
281 - 10 /* safety margin */) /numthread);
283 cfg->outgoing_num_ports);
294 (void)cfg;
301 apply_settings(struct daemon* daemon, struct config_file* cfg,
305 verbosity = cmdline_verbose + cfg->verbosity;
307 cfg->use_syslog = 0;
308 free(cfg->logfile);
309 cfg->logfile = NULL;
311 daemon_apply_cfg(daemon, cfg);
312 checkrlimits(cfg);
314 if (cfg->use_systemd && cfg->do_daemonize) {
315 log_warn("use-systemd and do-daemonize should not be enabled at the same time");
318 log_ident_set_or_default(cfg->log_identity);
324 * @return: the pid from the file or -1 if none.
335 if ((fd = open(file, O_RDONLY)) == -1) {
339 return -1;
342 if (((l = read(fd, pidbuf, sizeof(pidbuf)))) == -1) {
347 return -1;
354 return -1;
357 pidbuf[sizeof(pidbuf)-1] = 0;
361 return -1;
382 , 0644)) == -1) {
388 ssize_t r = write(fd, pidbuf+count, strlen(pidbuf)-count);
389 if(r == -1) {
417 if((old = readpid(pidfile)) != -1) {
444 case -1:
452 if(setsid() == -1)
455 if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
468 setup_listen_sslctx(void** ctx, int is_dot, int is_doh, struct config_file* cfg)
472 cfg->ssl_service_key, cfg->ssl_service_pem, NULL,
473 cfg->tls_ciphers, cfg->tls_ciphersuites,
474 (cfg->tls_session_ticket_keys.first &&
475 cfg->tls_session_ticket_keys.first->str[0] != 0),
480 (void)ctx;(void)is_dot;(void)is_doh;(void)cfg;
486 setup_sslctxs(struct daemon* daemon, struct config_file* cfg)
489 if(!(daemon->rc = daemon_remote_create(cfg)))
490 fatal_exit("could not set up remote-control");
491 if(cfg->ssl_service_key && cfg->ssl_service_key[0]) {
494 if(cfg->tls_session_ticket_keys.first &&
495 cfg->tls_session_ticket_keys.first->str[0] != 0) {
497 cfg->tls_session_ticket_keys.first)) {
501 (void)setup_listen_sslctx(&daemon->listen_dot_sslctx, 1, 0, cfg);
503 if(cfg_has_https(cfg)) {
504 (void)setup_listen_sslctx(&daemon->listen_doh_sslctx, 0, 1, cfg);
508 if(cfg_has_quic(cfg)) {
509 if(!(daemon->listen_quic_sslctx = quic_sslctx_create(
510 cfg->ssl_service_key, cfg->ssl_service_pem, NULL))) {
516 if(!(daemon->connect_dot_sslctx = connect_sslctx_create(NULL, NULL,
517 cfg->tls_cert_bundle, cfg->tls_win_cert)))
520 (void)daemon;(void)cfg;
526 perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
539 if(cfg->username && cfg->username[0]) {
540 if((pwd = getpwnam(cfg->username)) == NULL)
541 fatal_exit("user '%s' does not exist.", cfg->username);
546 w_config_adjust_directory(cfg);
550 (void)setup_sslctxs(daemon, cfg);
554 if(cfg->use_syslog) {
555 log_init(cfg->logfile, cfg->use_syslog, cfg->chrootdir);
560 * So, using a logfile, the user does not see errors unless -d is
565 pidinchroot = need_pidfile && (!(cfg->chrootdir && cfg->chrootdir[0]) ||
566 (cfg->chrootdir && cfg->chrootdir[0] &&
567 strncmp(cfg->pidfile, cfg->chrootdir,
568 strlen(cfg->chrootdir))==0));
571 if(cfg->pidfile && cfg->pidfile[0] && need_pidfile) {
573 if(cfg->pidfile[0] == '/')
574 daemon->pidfile = strdup(cfg->pidfile);
575 else daemon->pidfile = fname_after_chroot(cfg->pidfile,
576 cfg, 1);
577 if(!daemon->pidfile)
586 if(!(cfg->username && cfg->username[0]))
587 checkoldpid(daemon->pidfile, pidinchroot);
592 if(!debug_mode && cfg->do_daemonize) {
598 if(cfg->pidfile && cfg->pidfile[0] && need_pidfile) {
599 writepid(daemon->pidfile, getpid());
608 if(cfg->username && cfg->username[0] && cfg_uid != (uid_t)-1) {
616 cfg->username, strerror(errno));
625 if(cfg->chrootdir && cfg->chrootdir[0]) {
626 if(chdir(cfg->chrootdir)) {
628 cfg->chrootdir, strerror(errno));
630 verbose(VERB_QUERY, "chdir to %s", cfg->chrootdir);
631 if(chroot(cfg->chrootdir))
633 cfg->chrootdir, strerror(errno));
636 cfg->chrootdir, strerror(errno));
637 verbose(VERB_QUERY, "chroot to %s", cfg->chrootdir);
638 if(strncmp(*cfgfile, cfg->chrootdir,
639 strlen(cfg->chrootdir)) == 0)
640 (*cfgfile) += strlen(cfg->chrootdir);
643 if(daemon->pidfile && daemon->pidfile[0] &&
644 strncmp(daemon->pidfile, cfg->chrootdir,
645 strlen(cfg->chrootdir))==0) {
646 char* old = daemon->pidfile;
647 daemon->pidfile = strdup(old+strlen(cfg->chrootdir));
649 if(!daemon->pidfile)
652 daemon->chroot = strdup(cfg->chrootdir);
653 if(!daemon->chroot)
660 if(cfg->directory && cfg->directory[0]) {
661 char* dir = cfg->directory;
662 if(cfg->chrootdir && cfg->chrootdir[0] &&
663 strncmp(dir, cfg->chrootdir,
664 strlen(cfg->chrootdir)) == 0)
665 dir += strlen(cfg->chrootdir);
677 if(cfg->username && cfg->username[0] && cfg_uid != (uid_t)-1) {
679 if(initgroups(cfg->username, cfg_gid) != 0)
681 cfg->username, strerror(errno));
695 cfg->username, strerror(errno));
704 cfg->username, strerror(errno));
706 cfg->username);
711 if(!cfg->use_syslog)
712 log_init(cfg->logfile, cfg->use_syslog, cfg->chrootdir);
713 daemon->cfgfile = strdup(*cfgfile);
714 if(!daemon->cfgfile)
721 * @param cmdline_verbose: verbosity resulting from commandline -v.
729 struct config_file* cfg = NULL;
735 while(!daemon->need_to_exit) {
741 if(!(cfg = config_create()))
743 if(!config_read(cfg, cfgfile, daemon->chroot)) {
746 " Maybe try unbound -dd, it stays on "
748 "or unbound-checkconf", cfgfile);
751 apply_settings(daemon, cfg, cmdline_verbose, debug_mode);
753 config_lookup_uid(cfg);
759 perform_setup(daemon, cfg, debug_mode, &cfgfile, need_pidfile);
763 if(!cfg->use_syslog)
764 log_init(cfg->logfile, 0, cfg->chrootdir);
772 config_delete(cfg);
777 if(daemon->pidfile) {
780 fd = open(daemon->pidfile, O_WRONLY | O_TRUNC
785 if(fd != -1)
788 unlink(daemon->pidfile);
825 while( (c=getopt(argc, argv, "c:dhpvw:V")) != -1) {
856 argc -= optind;