56 #include <libxml/parser.h>
62 #include <sys/socket.h>
63 #include <sys/types.h>
68 static const char* engine_str =
"engine";
116 if (!engine->
taskq) {
121 if (!engine->
signq) {
134 cmdhandler_thread_start(
void* arg)
159 struct sockaddr_un servaddr;
160 const char* servsock_filename = ODS_SE_SOCKFILE;
165 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
168 "socket() failed: %s\n", engine_str, strerror(errno));
171 bzero(&servaddr,
sizeof(servaddr));
172 servaddr.sun_family = AF_UNIX;
173 strncpy(servaddr.sun_path, servsock_filename,
174 sizeof(servaddr.sun_path) - 1);
176 ret = connect(sockfd, (
const struct sockaddr*) &servaddr,
180 "connect() failed: %s\n", engine_str, strerror(errno));
204 if (self_pipe_trick(engine) == 0) {
211 ods_log_error(
"[%s] command handler self pipe trick failed, "
212 "unclean shutdown", engine_str);
291 worker_thread_start(
void* arg)
405 char* zf_filename = NULL;
406 char* zl_filename = NULL;
407 char* log_filename = NULL;
422 switch ((zfpid = fork())) {
434 if (setsid() == -1) {
441 (
unsigned long) getpid());
465 chrt, log_filename, use_syslog, verbosity);
468 if (zf_filename) { free((
void*)zf_filename); }
469 if (zl_filename) { free((
void*)zl_filename); }
470 if (grp) { free((
void*)grp); }
471 if (usr) { free((
void*)usr); }
472 if (chrt) { free((
void*)chrt); }
473 if (log_filename) { free((
void*)log_filename); }
500 if (engine->
zfpid > 0) {
501 result = kill(engine->
zfpid, SIGHUP);
509 ods_log_error(
"cannot reload zone fetcher: process id unknown");
529 if (engine->
zfpid > 0) {
530 result = kill(engine->
zfpid, SIGTERM);
532 ods_log_error(
"cannot stop zone fetcher: %s", strerror(errno));
538 ods_log_error(
"cannot stop zone fetcher: process id unknown");
575 struct sigaction action;
580 if (!engine || !engine->
config) {
594 if (start_zonefetcher(engine) != 0) {
600 status = engine_init_adapters(engine);
602 ods_log_error(
"[%s] initializing adapters failed", engine_str);
630 switch ((engine->
pid = fork())) {
633 engine_str, strerror(errno));
645 if (setsid() == -1) {
647 engine_str, strerror(errno));
651 engine->
pid = getpid();
653 (
unsigned long) engine->
pid);
658 sigfillset(&action.sa_mask);
660 sigaction(SIGHUP, &action, NULL);
661 sigaction(SIGTERM, &action, NULL);
665 if (result != HSM_OK) {
670 engine_create_workers(engine);
671 engine_create_drudgers(engine);
674 engine_start_cmdhandler(engine);
694 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
702 while (node && node != LDNS_RBTREE_NULL) {
707 node = ldns_rbtree_next(node);
725 engine_start_workers(engine);
750 "keep running", engine_str, signal);
758 engine->
need_to_exit = engine_all_zones_processed(engine);
772 engine_stop_workers(engine);
783 set_notify_ns(
zone_type* zone,
const char* cmd)
785 const char* str = NULL;
786 const char* str2 = NULL;
814 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
823 ods_log_error(
"[%s] cannot update zones: no engine or zonelist",
832 reload_zonefetcher(engine);
837 while (node && node != LDNS_RBTREE_NULL) {
842 node = ldns_rbtree_next(node);
877 engine_str, zone->
name);
901 ods_log_debug(
"[%s] reschedule task for zone %s", engine_str,
914 "signconf as soon as possible", engine_str, zone->
name);
928 ods_log_crit(
"[%s] failed to schedule task for zone %s: %s",
933 node = ldns_rbtree_next(node);
951 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
957 ods_log_error(
"[%s] cannot update zones: no engine or zonelist",
968 while (node && node != LDNS_RBTREE_NULL) {
991 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
1005 " performing full sign", engine_str, zone->
name);
1009 node = ldns_rbtree_next(node);
1023 int info,
int single_run)
1039 engine = engine_create();
1051 ods_log_error(
"[%s] cfgfile %s has errors", engine_str, cfgfile);
1067 status = engine_setup(engine);
1099 zl_changed = engine_recover(engine);
1106 ods_log_debug(
"[%s] signer configurations updated", engine_str);
1110 engine_run(engine, single_run);
1115 stop_zonefetcher(engine);
1120 engine_stop_cmdhandler(engine);
1124 if (engine && engine->
config) {
1136 xmlCleanupGlobals();
1137 xmlCleanupThreads();
1151 cond_basic_type signal_cond;