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)
154 struct sockaddr_un servaddr;
155 const char* servsock_filename = ODS_SE_SOCKFILE;
158 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
161 "socket() failed (%s)", engine_str, strerror(errno));
164 bzero(&servaddr,
sizeof(servaddr));
165 servaddr.sun_family = AF_UNIX;
166 strncpy(servaddr.sun_path, servsock_filename,
167 sizeof(servaddr.sun_path) - 1);
168 ret = connect(sockfd, (
const struct sockaddr*) &servaddr,
172 "connect() failed (%s)", engine_str, strerror(errno));
196 if (self_pipe_trick(engine) == 0) {
203 ods_log_error(
"[%s] command handler self pipe trick failed, "
204 "unclean shutdown", engine_str);
215 dnshandler_thread_start(
void* arg)
254 xfrhandler_thread_start(
void* arg)
367 worker_thread_start(
void* arg)
476 struct sigaction action;
478 int sockets[2] = {0,0};
481 if (!engine || !engine->
config) {
500 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) == -1) {
507 ods_log_error(
"[%s] setup: unable to listen to sockets (%s)",
524 ods_log_error(
"[%s] setup: unable to chdir to %s (%s)", engine_str,
533 switch ((engine->
pid = fork())) {
536 engine_str, strerror(errno));
548 if (setsid() == -1) {
550 engine_str, strerror(errno));
554 engine->
pid = getpid();
556 (
unsigned long) engine->
pid);
560 sigfillset(&action.sa_mask);
562 sigaction(SIGTERM, &action, NULL);
563 sigaction(SIGHUP, &action, NULL);
564 sigaction(SIGINT, &action, NULL);
565 sigaction(SIGILL, &action, NULL);
566 sigaction(SIGUSR1, &action, NULL);
567 sigaction(SIGALRM, &action, NULL);
568 sigaction(SIGCHLD, &action, NULL);
569 action.sa_handler = SIG_IGN;
570 sigaction(SIGPIPE, &action, NULL);
573 if (result != HSM_OK) {
577 engine_create_workers(engine);
578 engine_create_drudgers(engine);
580 engine_start_cmdhandler(engine);
581 engine_start_dnshandler(engine);
582 engine_start_xfrhandler(engine);
601 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
609 while (node && node != LDNS_RBTREE_NULL) {
616 node = ldns_rbtree_next(node);
632 engine_start_workers(engine);
654 "keep running", engine_str, signal);
661 engine->
need_to_exit = engine_all_zones_processed(engine);
672 engine_stop_workers(engine);
683 set_notify_ns(
zone_type* zone,
const char* cmd)
685 const char* str = NULL;
686 const char* str2 = NULL;
695 ods_log_error(
"[%s] unable to set notify ns: replace zonefile failed",
708 while ((token = strtok((
char*) str,
" "))) {
719 ods_log_error(
"[%s] unable to set notify ns: replace zone failed",
746 engine_str, zone->
name);
756 }
else if (zone->
xfrd) {
766 engine_str, zone->
name);
774 }
else if (zone->
notify) {
791 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
796 unsigned wake_up = 0;
808 while (node && node != LDNS_RBTREE_NULL) {
813 node = ldns_rbtree_next(node);
842 "task_create() failed", engine_str, zone->
name);
843 node = ldns_rbtree_next(node);
850 ods_log_error(
"[%s] unable to load config for inbound adapter "
851 "for zone %s: %s", engine_str, zone->
name,
856 ods_log_error(
"[%s] unable to load config for outbound adapter "
857 "for zone %s: %s", engine_str, zone->
name,
861 warnings += dnsconfig_zone(engine, zone);
878 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
884 node = ldns_rbtree_next(node);
890 }
else if (warnings) {
892 "are configured with dns adapters: notify and zone transfer "
893 "requests will not work properly", engine_str);
909 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
915 ods_log_error(
"[%s] cannot recover zones: no engine or zonelist",
926 while (node && node != LDNS_RBTREE_NULL) {
948 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
962 " performing full sign", engine_str, zone->
name);
967 node = ldns_rbtree_next(node);
980 engine_start(
const char* cfgfile,
int cmdline_verbosity,
int daemonize,
981 int info,
int single_run)
997 engine = engine_create();
1009 ods_log_error(
"[%s] cfgfile %s has errors", engine_str, cfgfile);
1025 status = engine_setup(engine);
1054 ods_log_info(
"[%s] signer started (version %s), pid %u",
1055 engine_str, PACKAGE_VERSION, engine->
pid);
1056 zl_changed = engine_recover(engine);
1062 engine_run(engine, single_run);
1072 engine_stop_xfrhandler(engine);
1073 engine_stop_dnshandler(engine);
1074 engine_stop_cmdhandler(engine);
1078 if (engine && engine->
config) {
1091 xmlCleanupGlobals();
1092 xmlCleanupThreads();
1106 cond_basic_type signal_cond;