50 #include <libxml/parser.h> 56 #include <sys/socket.h> 57 #include <sys/types.h> 62 static const char* engine_str =
"engine";
75 ods_log_error(
"[%s] unable to create engine: allocator_create() " 76 "failed", engine_str);
81 ods_log_error(
"[%s] unable to create engine: allocator_alloc() " 82 "failed", engine_str);
111 if (!engine->
taskq) {
116 if (!engine->
signq) {
129 cmdhandler_thread_start(
void* arg)
155 struct sockaddr_un servaddr;
156 const char* servsock_filename = ODS_SE_SOCKFILE;
159 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
162 "socket() failed (%s)", engine_str, strerror(errno));
165 bzero(&servaddr,
sizeof(servaddr));
166 servaddr.sun_family = AF_UNIX;
167 strncpy(servaddr.sun_path, servsock_filename,
168 sizeof(servaddr.sun_path) - 1);
169 ret = connect(sockfd, (
const struct sockaddr*) &servaddr,
173 "connect() failed (%s)", engine_str, strerror(errno));
197 if (self_pipe_trick(engine) == 0) {
204 ods_log_error(
"[%s] command handler self pipe trick failed, " 205 "unclean shutdown", engine_str);
215 dnshandler_thread_start(
void* arg)
252 xfrhandler_thread_start(
void* arg)
361 worker_thread_start(
void* arg)
465 struct sigaction action;
466 int sockets[2] = {0,0};
469 if (!engine || !engine->
config) {
488 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) == -1) {
495 ods_log_error(
"[%s] setup: unable to listen to sockets (%s)",
513 ods_log_error(
"[%s] setup: unable to chdir to %s (%s)", engine_str,
522 switch ((engine->
pid = fork())) {
525 engine_str, strerror(errno));
537 if (setsid() == -1) {
539 engine_str, strerror(errno));
543 engine->
pid = getpid();
545 (
unsigned long) engine->
pid);
549 sigfillset(&action.sa_mask);
551 sigaction(SIGTERM, &action, NULL);
552 sigaction(SIGHUP, &action, NULL);
553 sigaction(SIGINT, &action, NULL);
554 sigaction(SIGILL, &action, NULL);
555 sigaction(SIGUSR1, &action, NULL);
556 sigaction(SIGALRM, &action, NULL);
557 sigaction(SIGCHLD, &action, NULL);
558 action.sa_handler = SIG_IGN;
559 sigaction(SIGPIPE, &action, NULL);
561 engine_create_workers(engine);
562 engine_create_drudgers(engine);
564 engine_start_cmdhandler(engine);
565 engine_start_dnshandler(engine);
566 engine_start_xfrhandler(engine);
585 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
593 while (node && node != LDNS_RBTREE_NULL) {
600 node = ldns_rbtree_next(node);
616 engine_start_workers(engine);
631 ods_log_error(
"signer instructed to reload due to explicit signal");
639 "keep running", engine_str, (
int)engine->
signal);
646 engine->
need_to_exit = engine_all_zones_processed(engine);
657 engine_stop_workers(engine);
666 set_notify_ns(
zone_type* zone,
const char* cmd)
668 const char* str = NULL;
669 const char* str2 = NULL;
678 ods_log_error(
"[%s] unable to set notify ns: replace zonefile failed",
691 while ((token = strtok((
char*) str,
" "))) {
702 ods_log_error(
"[%s] unable to set notify ns: replace zone failed",
728 engine_str, zone->
name);
738 }
else if (zone->
xfrd) {
748 engine_str, zone->
name);
756 }
else if (zone->
notify) {
773 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
778 unsigned wake_up = 0;
790 while (node && node != LDNS_RBTREE_NULL) {
795 node = ldns_rbtree_next(node);
824 "task_create() failed", engine_str, zone->
name);
825 node = ldns_rbtree_next(node);
832 ods_log_error(
"[%s] unable to load config for inbound adapter " 833 "for zone %s: %s", engine_str, zone->
name,
838 ods_log_error(
"[%s] unable to load config for outbound adapter " 839 "for zone %s: %s", engine_str, zone->
name,
843 warnings += dnsconfig_zone(engine, zone);
863 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
869 node = ldns_rbtree_next(node);
873 ods_log_debug(
"[%s] forward notify for all zones", engine_str);
876 }
else if (warnings) {
878 "are configured with dns adapters: notify and zone transfer " 879 "requests will not work properly", engine_str);
894 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
900 ods_log_error(
"[%s] cannot recover zones: no engine or zonelist",
911 while (node && node != LDNS_RBTREE_NULL) {
933 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
947 " performing full sign", engine_str, zone->
name);
952 node = ldns_rbtree_next(node);
965 engine_start(
const char* cfgfile,
int cmdline_verbosity,
int daemonize,
966 int info,
int single_run)
981 engine = engine_create();
993 ods_log_error(
"[%s] cfgfile %s has errors", engine_str, cfgfile);
1009 status = engine_setup(engine);
1036 ods_log_info(
"[%s] signer started (version %s), pid %u",
1037 engine_str, PACKAGE_VERSION, engine->
pid);
1039 char* error = hsm_get_error(NULL);
1040 if (error != NULL) {
1044 ods_log_error(
"[%s] opening hsm failed (for engine recover)", engine_str);
1047 zl_changed = engine_recover(engine);
1055 char* error = hsm_get_error(NULL);
1056 if (error != NULL) {
1060 ods_log_error(
"[%s] opening hsm failed (for engine run)", engine_str);
1063 engine_run(engine, single_run);
1069 engine_stop_cmdhandler(engine);
1070 engine_stop_xfrhandler(engine);
1071 engine_stop_dnshandler(engine);
1074 if (engine && engine->
config) {
1087 xmlCleanupGlobals();
1088 xmlCleanupThreads();
1101 cond_basic_type signal_cond;
void engine_config_cleanup(engineconfig_type *config)
void engine_config_print(FILE *out, engineconfig_type *config)
#define lock_basic_off(cond)
void tsig_handler_cleanup(void)
void zone_cleanup(zone_type *zone)
#define ODS_SE_NOTIFY_CMD
gid_t privgid(const char *groupname)
void engine_wakeup_workers(engine_type *engine)
void ods_thread_blocksigs(void)
const char * cfg_filename
#define ods_thread_join(thr)
void engine_stop_drudgers(engine_type *engine)
void privclose(const char *username, const char *groupname)
void ods_log_debug(const char *format,...)
notify_type * notify_create(void *xfrhandler, void *zone)
#define lock_basic_destroy(lock)
ods_status dnshandler_listen(dnshandler_type *dnshandler)
cond_basic_type signal_cond
cond_basic_type q_threshold
void * allocator_alloc(allocator_type *allocator, size_t size)
const char * zonelist_filename
void xfrhandler_cleanup(xfrhandler_type *xfrhandler)
void engine_update_zones(engine_type *engine, ods_status zl_changed)
cmdhandler_type * cmdhandler_create(allocator_type *allocator, const char *filename)
void ods_fatal_exit(const char *format,...)
ods_status adapter_load_config(adapter_type *adapter)
ods_status zone_recover2(zone_type *zone)
ods_status schedule_task(schedule_type *schedule, task_type *task, int log)
void signal_set_engine(void *engine)
void ods_log_info(const char *format,...)
allocator_type * allocator
enum ods_enum_status ods_status
void worker_start(worker_type *worker)
lock_basic_type zone_lock
ods_thread_type thread_id
void ods_log_error(const char *format,...)
const char * ods_status2str(ods_status status)
ods_status tsig_handler_init(allocator_type *allocator)
void cmdhandler_start(cmdhandler_type *cmdhandler)
void worker_cleanup(worker_type *worker)
void ods_str_list_add(char ***list, char *str)
netio_handler_type dnshandler
void engine_start_drudgers(engine_type *engine)
#define lock_basic_set(cond)
void notify_cleanup(notify_type *notify)
adapter_type * adoutbound
uid_t privuid(const char *username)
void netio_add_handler(netio_type *netio, netio_handler_type *handler)
void fifoq_cleanup(fifoq_type *q)
void ods_log_crit(const char *format,...)
const char * log_filename
lock_basic_type signal_lock
const char * clisock_filename
engineconfig_type * engine_config(allocator_type *allocator, const char *cfgfile, int cmdline_verbosity)
sig_atomic_t signal_capture(sig_atomic_t dflsig)
#define lock_basic_lock(lock)
void ods_str_trim(char *str)
zone_type * zonelist_del_zone(zonelist_type *zlist, zone_type *zone)
engineconfig_type * config
int util_write_pidfile(const char *pidfile, pid_t pid)
void dnshandler_signal(dnshandler_type *dnshandler)
allocator_type * allocator_create(void *(*allocator)(size_t size), void(*deallocator)(void *))
#define lock_basic_sleep(cond, lock, sleep)
void xfrhandler_start(xfrhandler_type *xfrhandler)
void engine_start(const char *cfgfile, int cmdline_verbosity, int daemonize, int info, int single_run)
void worker_notify_all(lock_basic_type *lock, cond_basic_type *condition)
const char * notify_command
int util_check_pidfile(const char *pidfile)
ssize_t ods_writen(int fd, const void *vptr, size_t n)
void task_cleanup(task_type *task)
void xfrd_cleanup(xfrd_type *xfrd, int backup)
void worker_wakeup(worker_type *worker)
fifoq_type * fifoq_create(allocator_type *allocator)
void xfrhandler_signal(xfrhandler_type *xfrhandler)
task_type * unschedule_task(schedule_type *schedule, task_type *task)
#define EDNS_MAX_MESSAGE_LEN
cmdhandler_type * cmdhandler
void netio_remove_handler(netio_type *netio, netio_handler_type *handler)
xfrhandler_type * xfrhandler_create(allocator_type *allocator)
void fifoq_wipe(fifoq_type *q)
ods_status zone_reschedule_task(zone_type *zone, schedule_type *taskq, task_id what)
ods_status privdrop(const char *username, const char *groupname, const char *newroot, uid_t *puid, gid_t *pgid)
netio_handler_type xfrhandler
void ods_chown(const char *file, uid_t uid, gid_t gid, int getdir)
void ods_log_verbose(const char *format,...)
ods_status engine_config_check(engineconfig_type *config)
dnshandler_type * dnshandler_create(allocator_type *allocator, listener_type *interfaces)
#define lock_basic_init(lock)
void xfrd_set_timer_now(xfrd_type *xfrd)
void allocator_cleanup(allocator_type *allocator)
void edns_init(edns_data_type *data, uint16_t max_length)
listener_type * interfaces
void zonelist_cleanup(zonelist_type *zl)
worker_type * worker_create(allocator_type *allocator, int num, worker_id type)
void engine_cleanup(engine_type *engine)
void allocator_deallocate(allocator_type *allocator, void *data)
void schedule_cleanup(schedule_type *schedule)
ods_status zonelist_update(zonelist_type *zl, const char *zlfile)
lock_basic_type schedule_lock
void signal_handler(sig_atomic_t sig)
ods_thread_type thread_id
zonelist_type * zonelist_create(allocator_type *allocator)
cond_basic_type q_nonfull
void dnshandler_start(dnshandler_type *dnshandler)
netio_handler_type handler
#define ods_log_assert(x)
#define ods_thread_create(thr, func, arg)
netio_handler_type handler
void ods_log_init(const char *filename, int use_syslog, int verbosity)
ods_thread_type thread_id
xfrd_type * xfrd_create(void *xfrhandler, void *zone)
void dnshandler_fwd_notify(dnshandler_type *dnshandler, uint8_t *pkt, size_t len)
schedule_type * schedule_create(allocator_type *allocator)
const char * pid_filename
#define lock_basic_unlock(lock)
const char * ods_replace(const char *str, const char *oldstr, const char *newstr)
void ods_log_warning(const char *format,...)
void cmdhandler_cleanup(cmdhandler_type *cmdhandler)
time_t serial_disk_acquired
ods_thread_type thread_id
task_type * task_create(task_id what, time_t when, void *zone)
dnshandler_type * dnshandler
xfrhandler_type * xfrhandler
void dnshandler_cleanup(dnshandler_type *dnshandler)