56 #include <libxml/parser.h>
62 #include <sys/socket.h>
63 #include <sys/types.h>
68 static const char* engine_str =
"engine";
114 if (!engine->
taskq) {
119 if (!engine->
signq) {
132 cmdhandler_thread_start(
void* arg)
157 struct sockaddr_un servaddr;
158 const char* servsock_filename = ODS_SE_SOCKFILE;
163 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
166 "socket() failed: %s\n", engine_str, strerror(errno));
169 bzero(&servaddr,
sizeof(servaddr));
170 servaddr.sun_family = AF_UNIX;
171 strncpy(servaddr.sun_path, servsock_filename,
172 sizeof(servaddr.sun_path) - 1);
174 ret = connect(sockfd, (
const struct sockaddr*) &servaddr,
178 "connect() failed: %s\n", engine_str, strerror(errno));
202 if (self_pipe_trick(engine) == 0) {
209 ods_log_error(
"[%s] command handler self pipe trick failed, "
210 "unclean shutdown", engine_str);
289 worker_thread_start(
void* arg)
403 char* zf_filename = NULL;
404 char* zl_filename = NULL;
405 char* log_filename = NULL;
420 switch ((zfpid = fork())) {
432 if (setsid() == -1) {
439 (
unsigned long) getpid());
463 chrt, log_filename, use_syslog, verbosity);
466 if (zf_filename) { free((
void*)zf_filename); }
467 if (zl_filename) { free((
void*)zl_filename); }
468 if (grp) { free((
void*)grp); }
469 if (usr) { free((
void*)usr); }
470 if (chrt) { free((
void*)chrt); }
471 if (log_filename) { free((
void*)log_filename); }
498 if (engine->
zfpid > 0) {
499 result = kill(engine->
zfpid, SIGHUP);
507 ods_log_error(
"cannot reload zone fetcher: process id unknown");
527 if (engine->
zfpid > 0) {
528 result = kill(engine->
zfpid, SIGTERM);
530 ods_log_error(
"cannot stop zone fetcher: %s", strerror(errno));
536 ods_log_error(
"cannot stop zone fetcher: process id unknown");
573 struct sigaction action;
578 if (!engine || !engine->
config) {
592 if (start_zonefetcher(engine) != 0) {
598 status = engine_init_adapters(engine);
600 ods_log_error(
"[%s] initializing adapters failed", engine_str);
628 switch ((engine->
pid = fork())) {
631 engine_str, strerror(errno));
643 if (setsid() == -1) {
645 engine_str, strerror(errno));
649 engine->
pid = getpid();
651 (
unsigned long) engine->
pid);
656 sigfillset(&action.sa_mask);
658 sigaction(SIGHUP, &action, NULL);
659 sigaction(SIGTERM, &action, NULL);
663 if (result != HSM_OK) {
668 engine_create_workers(engine);
669 engine_create_drudgers(engine);
672 engine_start_cmdhandler(engine);
692 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
700 while (node && node != LDNS_RBTREE_NULL) {
705 node = ldns_rbtree_next(node);
723 engine_start_workers(engine);
748 "keep running", engine_str, signal);
756 engine->
need_to_exit = engine_all_zones_processed(engine);
770 engine_stop_workers(engine);
781 set_notify_ns(
zone_type* zone,
const char* cmd)
783 const char* str = NULL;
784 const char* str2 = NULL;
812 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
821 ods_log_error(
"[%s] cannot update zones: no engine or zonelist",
830 reload_zonefetcher(engine);
835 while (node && node != LDNS_RBTREE_NULL) {
840 node = ldns_rbtree_next(node);
874 engine_str, zone->
name);
896 ods_log_debug(
"[%s] reschedule task for zone %s", engine_str,
909 "signconf as soon as possible", engine_str, zone->
name);
922 ods_log_crit(
"[%s] failed to schedule task for zone %s: %s",
927 node = ldns_rbtree_next(node);
945 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
951 ods_log_error(
"[%s] cannot update zones: no engine or zonelist",
962 while (node && node != LDNS_RBTREE_NULL) {
985 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
999 " performing full sign", engine_str, zone->
name);
1003 node = ldns_rbtree_next(node);
1017 int info,
int single_run)
1033 engine = engine_create();
1045 ods_log_error(
"[%s] cfgfile %s has errors", engine_str, cfgfile);
1059 status = engine_setup(engine);
1091 zl_changed = engine_recover(engine);
1098 ods_log_debug(
"[%s] signer configurations updated", engine_str);
1102 engine_run(engine, single_run);
1107 stop_zonefetcher(engine);
1112 engine_stop_cmdhandler(engine);
1116 if (engine && engine->
config) {
1128 xmlCleanupGlobals();
1129 xmlCleanupThreads();
1143 cond_basic_type signal_cond;