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);
881 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
887 node = ldns_rbtree_next(node);
891 ods_log_debug(
"[%s] forward notify for all zones", engine_str);
894 }
else if (warnings) {
896 "are configured with dns adapters: notify and zone transfer "
897 "requests will not work properly", engine_str);
913 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
919 ods_log_error(
"[%s] cannot recover zones: no engine or zonelist",
930 while (node && node != LDNS_RBTREE_NULL) {
952 ods_log_crit(
"[%s] unable to schedule task for zone %s: %s",
966 " performing full sign", engine_str, zone->
name);
971 node = ldns_rbtree_next(node);
984 engine_start(
const char* cfgfile,
int cmdline_verbosity,
int daemonize,
985 int info,
int single_run)
1001 engine = engine_create();
1013 ods_log_error(
"[%s] cfgfile %s has errors", engine_str, cfgfile);
1029 status = engine_setup(engine);
1058 ods_log_info(
"[%s] signer started (version %s), pid %u",
1059 engine_str, PACKAGE_VERSION, engine->
pid);
1060 zl_changed = engine_recover(engine);
1066 engine_run(engine, single_run);
1076 engine_stop_xfrhandler(engine);
1077 engine_stop_dnshandler(engine);
1078 engine_stop_cmdhandler(engine);
1082 if (engine && engine->
config) {
1095 xmlCleanupGlobals();
1096 xmlCleanupThreads();
1110 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)
int lhsm_reopen(const char *filename)
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)
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
int lhsm_open(const char *filename)
xfrhandler_type * xfrhandler
void dnshandler_cleanup(dnshandler_type *dnshandler)