The daemon consists of global settings and a number of workers. More...
#include "config.h"#include <openssl/err.h>#include <openssl/rand.h>#include <openssl/conf.h>#include <openssl/engine.h>#include <ldns/ldns.h>#include "daemon/daemon.h"#include "daemon/worker.h"#include "daemon/remote.h"#include "daemon/acl_list.h"#include "util/log.h"#include "util/config_file.h"#include "util/data/msgreply.h"#include "util/storage/lookup3.h"#include "util/storage/slabhash.h"#include "services/listen_dnsport.h"#include "services/cache/rrset.h"#include "services/cache/infra.h"#include "services/localzone.h"#include "services/modstack.h"#include "util/module.h"#include "util/random.h"#include "util/tube.h"#include <signal.h>Functions | |
| int | ub_c_lex_destroy (void) |
| remove buffers for parsing and init | |
| static RETSIGTYPE | record_sigh (int sig) |
| used when no other sighandling happens, so we don't die when multiple signals in quick succession are sent to us. | |
| static void | signal_handling_record (void) |
| Signal handling during the time when netevent is disabled. | |
| static void | signal_handling_playback (struct worker *wrk) |
| Replay old signals. | |
| struct daemon * | daemon_init (void) |
| Initialize daemon structure. | |
| int | daemon_open_shared_ports (struct daemon *daemon) |
| Open shared listening ports (if needed). | |
| static void | daemon_setup_modules (struct daemon *daemon) |
| Setup modules. | |
| static int | daemon_get_shufport (struct daemon *daemon, int *shufport) |
| Obtain allowed port numbers, concatenate the list, and shuffle them (ready to be handed out to threads). | |
| static void | daemon_create_workers (struct daemon *daemon) |
| Allocate empty worker structures. | |
| static void * | thread_start (void *arg) |
| Function to start one thread. | |
| static void | daemon_start_others (struct daemon *daemon) |
| Fork and init the other threads. | |
| static void | daemon_stop_others (struct daemon *daemon) |
| Stop the other threads. | |
| void | daemon_fork (struct daemon *daemon) |
| Fork workers and start service. | |
| void | daemon_cleanup (struct daemon *daemon) |
| Close off the worker thread information. | |
| void | daemon_delete (struct daemon *daemon) |
| Delete workers, close listening ports. | |
| void | daemon_apply_cfg (struct daemon *daemon, struct config_file *cfg) |
| Apply config settings. | |
Variables | |
| static int | sig_record_quit = 0 |
| How many quit requests happened. | |
| static int | sig_record_reload = 0 |
| How many reload requests happened. | |
| static void * | comp_meth = NULL |
| cleaner ssl memory freeup | |
The daemon consists of global settings and a number of workers.
| static RETSIGTYPE record_sigh | ( | int | sig | ) | [static] |
used when no other sighandling happens, so we don't die when multiple signals in quick succession are sent to us.
| sig,: | signal number. |
References verbose(), VERB_OPS, sig_record_quit, sig_record_reload, and log_err().
Referenced by signal_handling_record().
| static void signal_handling_record | ( | void | ) | [static] |
Signal handling during the time when netevent is disabled.
Stores signals to replay later.
References record_sigh(), and log_err().
Referenced by daemon_init(), and daemon_cleanup().
| static void signal_handling_playback | ( | struct worker * | wrk | ) | [static] |
Replay old signals.
| wrk,: | worker that handles signals. |
References sig_record_reload, worker_sighandler(), and sig_record_quit.
Referenced by daemon_fork().
| struct daemon* daemon_init | ( | void | ) | [read] |
Initialize daemon structure.
References fatal_exit(), signal_handling_record(), comp_meth, ub_systemseed(), daemon::need_to_exit, modstack_init(), daemon::mods, daemon::env, alloc_init(), daemon::superalloc, daemon::acl, acl_list_create(), daemon::time_boot, log_err(), and daemon::time_last_stat.
Referenced by run_daemon(), and service_init().
| int daemon_open_shared_ports | ( | struct daemon * | daemon | ) |
Open shared listening ports (if needed).
The cfg member pointer must have been set for the daemon.
| daemon,: | the daemon. |
References log_assert, daemon::cfg, config_file::port, daemon::listening_port, listening_ports_free(), daemon::ports, listening_ports_open(), config_file::remote_control_enable, daemon::rc_port, daemon::rc_ports, config_file::control_port, and daemon_remote_open_ports().
Referenced by run_daemon(), and service_init().
| static void daemon_setup_modules | ( | struct daemon * | daemon | ) | [static] |
Setup modules.
setup module stack.
| daemon,: | the daemon |
References daemon::env, module_env::cfg, daemon::cfg, module_env::alloc, daemon::superalloc, module_env::worker, module_env::need_to_validate, modstack_setup(), daemon::mods, config_file::module_conf, and fatal_exit().
Referenced by daemon_fork().
| static int daemon_get_shufport | ( | struct daemon * | daemon, |
| int * | shufport | ||
| ) | [static] |
Obtain allowed port numbers, concatenate the list, and shuffle them (ready to be handed out to threads).
| daemon,: | the daemon. Uses rand and cfg. |
| shufport,: | the portlist output. |
References daemon::cfg, config_file::outgoing_avail_ports, fatal_exit(), ub_random_max(), and daemon::rand.
Referenced by daemon_create_workers().
| static void daemon_create_workers | ( | struct daemon * | daemon | ) | [static] |
Allocate empty worker structures.
With backptr and thread-number, from 0..numthread initialised. Used as user arguments to new threads. Creates the daemon random generator if it does not exist yet. The random generator stays existing between reloads with a unique state.
| daemon,: | the daemon with (new) config settings. |
References log_assert, daemon::cfg, daemon::rand, ub_initstate(), fatal_exit(), ub_random(), daemon_get_shufport(), verbose(), VERB_ALGO, daemon::num, config_file::num_threads, daemon::workers, and worker_create().
Referenced by daemon_fork().
| static void* thread_start | ( | void * | arg | ) | [static] |
Function to start one thread.
| arg,: | user argument. |
References log_thread_set(), worker::thread_num, ub_thread_blocksigs(), tube_close_write(), worker::cmd, worker::daemon, worker_init(), daemon::cfg, daemon::ports, fatal_exit(), and worker_work().
Referenced by daemon_start_others().
| static void daemon_start_others | ( | struct daemon * | daemon | ) | [static] |
Fork and init the other threads.
Main thread returns for special handling.
| daemon,: | the daemon with other threads to fork. |
References log_assert, verbose(), VERB_ALGO, daemon::num, daemon::workers, worker::thr_id, thread_start(), tube_close_read(), and worker::cmd.
Referenced by daemon_fork().
| static void daemon_stop_others | ( | struct daemon * | daemon | ) | [static] |
Stop the other threads.
| daemon,: | the daemon with other threads. |
References log_assert, verbose(), VERB_ALGO, daemon::num, worker_send_cmd(), daemon::workers, worker_cmd_quit, and worker::thr_id.
Referenced by daemon_fork().
| void daemon_fork | ( | struct daemon * | daemon | ) |
Fork workers and start service.
When the routine exits, it is no longer forked.
| daemon,: | the daemon. |
References log_assert, acl_list_apply_cfg(), daemon::acl, daemon::cfg, fatal_exit(), daemon::local_zones, local_zones_create(), local_zones_apply_cfg(), daemon_setup_modules(), daemon_create_workers(), worker_init(), daemon::workers, daemon::ports, daemon_start_others(), signal_handling_playback(), log_info(), worker_work(), daemon_stop_others(), daemon::need_to_exit, and worker::need_to_exit.
Referenced by run_daemon(), and service_main().
| void daemon_cleanup | ( | struct daemon * | daemon | ) |
Close off the worker thread information.
Bring the daemon back into state ready for daemon_fork again.
| daemon,: | the daemon. |
References log_assert, signal_handling_record(), log_thread_set(), slabhash_clear(), daemon::env, module_env::rrset_cache, rrset_cache::table, module_env::msg_cache, local_zones_delete(), daemon::local_zones, daemon_remote_clear(), daemon::rc, daemon::num, worker_delete(), daemon::workers, and daemon::cfg.
Referenced by run_daemon(), service_deinit(), and service_main().
| void daemon_delete | ( | struct daemon * | daemon | ) |
Delete workers, close listening ports.
| daemon,: | the daemon. |
References modstack_desetup(), daemon::mods, daemon::env, daemon_remote_delete(), daemon::rc, listening_ports_free(), daemon::ports, daemon::rc_ports, slabhash_delete(), module_env::msg_cache, rrset_cache_delete(), module_env::rrset_cache, infra_delete(), module_env::infra_cache, ub_randfree(), daemon::rand, alloc_clear(), daemon::superalloc, acl_list_delete(), daemon::acl, daemon::chroot, daemon::pidfile, daemon::listen_sslctx, ub_c_lex_destroy(), comp_meth, and log_err().
Referenced by run_daemon(), service_init(), and service_deinit().
| void daemon_apply_cfg | ( | struct daemon * | daemon, |
| struct config_file * | cfg | ||
| ) |
Apply config settings.
| daemon,: | the daemon. |
| cfg,: | new config settings. |
References daemon::cfg, config_apply(), daemon::env, module_env::msg_cache, config_file::msg_cache_size, slabhash_get_size(), config_file::msg_cache_slabs, slabhash::size, slabhash_delete(), slabhash_create(), HASH_DEFAULT_STARTARRAY, msgreply_sizefunc(), query_info_compare(), query_entry_delete(), reply_info_delete(), fatal_exit(), module_env::rrset_cache, rrset_cache_adjust(), daemon::superalloc, module_env::infra_cache, and infra_adjust().
Referenced by apply_settings(), and service_init().
int sig_record_quit = 0 [static] |
How many quit requests happened.
Referenced by record_sigh(), and signal_handling_playback().
int sig_record_reload = 0 [static] |
How many reload requests happened.
Referenced by record_sigh(), and signal_handling_playback().