52 #include <libxml/parser.h>
58 #include <sys/socket.h>
59 #include <sys/types.h>
64 static const char* engine_str =
"engine";
77 ods_log_error(
"[%s] unable to create engine: allocator_create() "
78 "failed", engine_str);
83 ods_log_error(
"[%s] unable to create engine: allocator_alloc() "
84 "failed", engine_str);
113 if (!engine->
taskq) {
118 if (!engine->
signq) {
131 cmdhandler_thread_start(
void* arg)
156 struct sockaddr_un servaddr;
157 const char* servsock_filename = ODS_SE_SOCKFILE;
160 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
163 "socket() failed (%s)", engine_str, strerror(errno));
166 bzero(&servaddr,
sizeof(servaddr));
167 servaddr.sun_family = AF_UNIX;
168 strncpy(servaddr.sun_path, servsock_filename,
169 sizeof(servaddr.sun_path) - 1);
170 ret = connect(sockfd, (
const struct sockaddr*) &servaddr,
174 "connect() failed (%s)", engine_str, strerror(errno));
198 if (self_pipe_trick(engine) == 0) {
205 ods_log_error(
"[%s] command handler self pipe trick failed, "
206 "unclean shutdown", engine_str);
217 dnshandler_thread_start(
void* arg)
256 xfrhandler_thread_start(
void* arg)
369 worker_thread_start(
void* arg)
478 struct sigaction action;
480 int sockets[2] = {0,0};
483 if (!engine || !engine->
config) {
502 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) == -1) {
509 ods_log_error(
"[%s] setup: unable to listen to sockets (%s)",
526 ods_log_error(
"[%s] setup: unable to chdir to %s (%s)", engine_str,
535 switch ((engine->
pid = fork())) {
538 engine_str, strerror(errno));
550 if (setsid() == -1) {
552 engine_str, strerror(errno));
556 engine->
pid = getpid();
558 (
unsigned long) engine->
pid);
562 sigfillset(&action.sa_mask);
564 sigaction(SIGTERM, &action, NULL);
565 sigaction(SIGHUP, &action, NULL);
566 sigaction(SIGINT, &action, NULL);
567 sigaction(SIGILL, &action, NULL);
568 sigaction(SIGUSR1, &action, NULL);
569 sigaction(SIGALRM, &action, NULL);
570 sigaction(SIGCHLD, &action, NULL);
571 action.sa_handler = SIG_IGN;
572 sigaction(SIGPIPE, &action, NULL);
575 if (result != HSM_OK) {
579 engine_create_workers(engine);
580 engine_create_drudgers(engine);
582 engine_start_cmdhandler(engine);
583 engine_start_dnshandler(engine);
584 engine_start_xfrhandler(engine);
603 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
611 while (node && node != LDNS_RBTREE_NULL) {
618 node = ldns_rbtree_next(node);
634 engine_start_workers(engine);
656 "keep running", engine_str, signal);
663 engine->
need_to_exit = engine_all_zones_processed(engine);
674 engine_stop_workers(engine);
685 set_notify_ns(
zone_type* zone,
const char* cmd)
687 const char* str = NULL;
688 const char* str2 = NULL;
708 while ((token = strtok((
char*) str,
" "))) {
718 ods_log_error(
"[%s] unable to set notify ns: replace zone failed",
745 engine_str, zone->
name);
755 }
else if (zone->
xfrd) {
765 engine_str, zone->
name);
773 }
else if (zone->
notify) {
790 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
795 unsigned wake_up = 0;
807 while (node && node != LDNS_RBTREE_NULL) {
812 node = ldns_rbtree_next(node);
841 "task_create() failed", engine_str, zone->
name);
842 node = ldns_rbtree_next(node);
849 ods_log_error(
"[%s] unable to load config for inbound adapter "
850 "for zone %s: %s", engine_str, zone->
name,
855 ods_log_error(
"[%s] unable to load config for outbound adapter "
856 "for zone %s: %s", engine_str, zone->
name,
860 warnings += dnsconfig_zone(engine, zone);
877 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
883 node = ldns_rbtree_next(node);
889 }
else if (warnings) {
891 "are configured with dns adapters: notify and zone transfer "
892 "requests will not work properly", engine_str);
908 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
914 ods_log_error(
"[%s] cannot recover zones: no engine or zonelist",
925 while (node && node != LDNS_RBTREE_NULL) {
946 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
960 " performing full sign", engine_str, zone->
name);
964 node = ldns_rbtree_next(node);
977 engine_start(
const char* cfgfile,
int cmdline_verbosity,
int daemonize,
978 int info,
int single_run)
994 engine = engine_create();
1006 ods_log_error(
"[%s] cfgfile %s has errors", engine_str, cfgfile);
1022 status = engine_setup(engine);
1052 zl_changed = engine_recover(engine);
1058 engine_run(engine, single_run);
1068 engine_stop_xfrhandler(engine);
1069 engine_stop_dnshandler(engine);
1070 engine_stop_cmdhandler(engine);
1074 if (engine && engine->
config) {
1087 xmlCleanupGlobals();
1088 xmlCleanupThreads();
1102 cond_basic_type signal_cond;