#include "config.h"
#include "daemon/daemon.h"
#include "daemon/worker.h"
#include "daemon/acl_list.h"
#include "util/log.h"
#include "util/config_file.h"
#include "util/data/msgreply.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 <signal.h>
Functions | |
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 () |
Signal handling during the time when netevent is disabled. | |
static void | signal_handling_playback (struct worker *wrk) |
Replay old signals. | |
struct daemon * | daemon_init () |
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. | |
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. | |
void | close_other_pipes (struct daemon *daemon, int thr) |
Close all pipes except for the numbered thread. | |
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. | |
Variables | |
static int | sig_record_quit = 0 |
How many quit requests happened. | |
static int | sig_record_reload = 0 |
How many reload requests happened. |
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 log_err(), sig_record_quit, sig_record_reload, VERB_OPS, and verbose().
Referenced by signal_handling_record().
static void signal_handling_record | ( | ) | [static] |
Signal handling during the time when netevent is disabled.
Stores signals to replay later.
References log_err(), and record_sigh().
Referenced by daemon_cleanup(), and daemon_init().
static void signal_handling_playback | ( | struct worker * | wrk | ) | [static] |
Replay old signals.
wrk,: | worker that handles signals. |
References sig_record_quit, sig_record_reload, and worker_sighandler().
Referenced by daemon_fork().
struct daemon* daemon_init | ( | ) | [read] |
Initialize daemon structure.
References daemon::acl, acl_list_create(), alloc_init(), daemon::env, fatal_exit(), daemon::mods, modstack_init(), daemon::need_to_exit, signal_handling_record(), and daemon::superalloc.
Referenced by run_daemon().
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.
References daemon::cfg, daemon::listening_port, listening_ports_free(), listening_ports_open(), log_assert, config_file::port, and daemon::ports.
Referenced by run_daemon().
static void daemon_setup_modules | ( | struct daemon * | daemon | ) | [static] |
Setup modules.
setup module stack.
References module_env::alloc, daemon::cfg, module_env::cfg, daemon::env, fatal_exit(), daemon::mods, modstack_setup(), config_file::module_conf, module_env::need_to_validate, daemon::superalloc, and module_env::worker.
Referenced by daemon_fork().
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).
References daemon::cfg, fatal_exit(), config_file::outgoing_avail_ports, daemon::rand, and ub_random().
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.
References daemon::cfg, daemon_get_shufport(), fatal_exit(), log_assert, daemon::num, config_file::num_threads, daemon::rand, ub_initstate(), VERB_ALGO, verbose(), worker_create(), and daemon::workers.
Referenced by daemon_fork().
void close_other_pipes | ( | struct daemon * | daemon, | |
int | thr | |||
) |
Close all pipes except for the numbered thread.
References worker::cmd_recv_fd, worker::cmd_send_fd, daemon::num, and daemon::workers.
Referenced by thread_start().
static void* thread_start | ( | void * | arg | ) | [static] |
Function to start one thread.
arg,: | user argument. |
References daemon::cfg, close_other_pipes(), worker::cmd_send_fd, worker::daemon, fatal_exit(), log_thread_set(), daemon::ports, worker::thread_num, ub_thread_blocksigs(), worker_init(), 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.
References worker::cmd_recv_fd, log_assert, daemon::num, worker::thr_id, thread_start(), VERB_ALGO, verbose(), and daemon::workers.
Referenced by daemon_fork().
static void daemon_stop_others | ( | struct daemon * | daemon | ) | [static] |
Stop the other threads.
References worker::front, log_assert, daemon::num, worker::thr_id, listen_dnsport::udp_buff, VERB_ALGO, verbose(), worker_cmd_quit, worker_send_cmd(), and daemon::workers.
Referenced by daemon_fork().
void daemon_fork | ( | struct daemon * | daemon | ) |
Fork workers and start service.
When the routine exits, it is no longer forked.
References daemon::acl, acl_list_apply_cfg(), daemon::cfg, daemon_create_workers(), daemon_setup_modules(), daemon_start_others(), daemon_stop_others(), fatal_exit(), daemon::local_zones, local_zones_apply_cfg(), local_zones_create(), log_assert, log_info(), worker::need_to_exit, daemon::need_to_exit, daemon::ports, signal_handling_playback(), worker_init(), worker_work(), and daemon::workers.
Referenced by run_daemon().
void daemon_cleanup | ( | struct daemon * | daemon | ) |
Close off the worker thread information.
Bring the daemon back into state ready for daemon_fork again.
References daemon::cfg, daemon::env, daemon::local_zones, local_zones_delete(), log_assert, log_thread_set(), module_env::msg_cache, daemon::num, module_env::rrset_cache, signal_handling_record(), slabhash_clear(), rrset_cache::table, worker_delete(), and daemon::workers.
Referenced by run_daemon().
void daemon_delete | ( | struct daemon * | daemon | ) |
Delete workers, close listening ports.
References daemon::acl, acl_list_delete(), alloc_clear(), daemon::env, module_env::infra_cache, infra_delete(), listening_ports_free(), log_err(), daemon::mods, modstack_desetup(), module_env::msg_cache, daemon::pidfile, daemon::ports, daemon::rand, module_env::rrset_cache, rrset_cache_delete(), slabhash_delete(), daemon::superalloc, and ub_randfree().
Referenced by run_daemon().
int sig_record_quit = 0 [static] |
int sig_record_reload = 0 [static] |