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;
void engine_config_cleanup(engineconfig_type *config)
void engine_config_print(FILE *out, engineconfig_type *config)
#define lock_basic_off(cond)
void zone_cleanup(zone_type *zone)
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)
#define LOCKED_SIGNAL_ENGINE_RUN
void engine_stop_drudgers(engine_type *engine)
void privclose(const char *username, const char *groupname)
void ods_log_debug(const char *format,...)
#define lock_basic_destroy(lock)
cond_basic_type signal_cond
cond_basic_type q_threshold
#define LOCKED_ZL_ENGINE_UPDATEZONES
void * allocator_alloc(allocator_type *allocator, size_t size)
const char * zonelist_filename
cmdhandler_type * cmdhandler_create(allocator_type *allocator, const char *filename)
struct engine_struct * engine
void ods_fatal_exit(const char *format,...)
#define LOCKED_ZONE_ENGINE_ADDZONE
ods_status schedule_task(schedule_type *schedule, task_type *task, int log)
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
#define LOCKED_SIGNAL_ENGINE_CAPTURE
ods_thread_type thread_id
void ods_log_error(const char *format,...)
const char * ods_status2str(ods_status status)
#define LOCKED_ZL_ENGINE_RECOVER
void cmdhandler_start(cmdhandler_type *cmdhandler)
void engine_update_zones(engine_type *engine)
void worker_cleanup(worker_type *worker)
#define LOCKED_ZONE_ENGINE_DELZONE
void engine_start_drudgers(engine_type *engine)
#define lock_basic_set(cond)
struct engine_struct * engine
adapter_type * adoutbound
#define LOCKED_SIGNAL_ENGINE_INIT
uid_t privuid(const char *username)
#define LOCKED_SCHEDULE_ENGINE_RECOVER
#define LOCKED_SIGNAL_ENGINE_SLEEP
task_type * task_create(task_id what, time_t when, const char *who, void *zone)
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)
zone_type * zonelist_del_zone(zonelist_type *zlist, zone_type *zone)
engineconfig_type * config
int util_write_pidfile(const char *pidfile, pid_t pid)
allocator_type * allocator_create(void *(*allocator)(size_t size), void(*deallocator)(void *))
#define lock_basic_sleep(cond, lock, sleep)
void engine_start(const char *cfgfile, int cmdline_verbosity, int daemonize, int info, int single_run)
const char * zonefetch_filename
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 worker_wakeup(worker_type *worker)
fifoq_type * fifoq_create(allocator_type *allocator)
task_type * unschedule_task(schedule_type *schedule, task_type *task)
cmdhandler_type * cmdhandler
void signal_set_engine(struct engine_struct *engine)
#define LOCKED_SCHEDULE_ENGINE_RESCHEDULE
ods_status privdrop(const char *username, const char *groupname, const char *newroot, uid_t *puid, gid_t *pgid)
void ods_chown(const char *file, uid_t uid, gid_t gid, int getdir)
int tools_zone_fetcher(const char *config_file, const char *zonelist_file, const char *group, const char *user, const char *chroot, const char *log_file, int use_syslog, int verbosity)
void ods_log_verbose(const char *format,...)
ods_status engine_config_check(engineconfig_type *config)
#define lock_basic_init(lock)
#define LOCKED_SCHEDULE_ENGINE_ADDZONE
void allocator_cleanup(allocator_type *allocator)
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)
zonelist_type * zonelist_create(allocator_type *allocator)
cond_basic_type q_nonfull
#define ods_log_assert(x)
#define ods_thread_create(thr, func, arg)
void ods_log_init(const char *filename, int use_syslog, int verbosity)
ods_thread_type thread_id
#define LOCKED_SCHEDULE_ENGINE_DELZONE
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,...)
ods_status adapter_init(adapter_type *adapter)
void cmdhandler_cleanup(cmdhandler_type *cmdhandler)
ods_status zone_recover(zone_type *zone)
#define LOCKED_ZONE_ENGINE_UPDZONE
int lhsm_open(const char *filename)