Skip to content

Commit

Permalink
Merge pull request #21 from yschaeff/enf-daemon-rework
Browse files Browse the repository at this point in the history
Rework daemon code.
  • Loading branch information
jelu committed Mar 4, 2014
2 parents 211e74e + fe23a68 commit 20c4fa5
Show file tree
Hide file tree
Showing 34 changed files with 499 additions and 530 deletions.
55 changes: 33 additions & 22 deletions enforcer-ng/src/daemon/cfg.c
Expand Up @@ -50,7 +50,7 @@ static const char* conf_str = "config";
*/
engineconfig_type*
engine_config(allocator_type* allocator, const char* cfgfile,
int cmdline_verbosity)
int cmdline_verbosity, engineconfig_type* oldcfg)
{
engineconfig_type* ecfg;
const char* rngfile = ODS_SE_RNGDIR "/conf.rng";
Expand Down Expand Up @@ -87,44 +87,55 @@ engine_config(allocator_type* allocator, const char* cfgfile,
/* open cfgfile */
cfgfd = ods_fopen(cfgfile, NULL, "r");
if (cfgfd) {
if (oldcfg) {
/* This is a reload */
ecfg->cfg_filename = allocator_strdup(allocator, oldcfg->cfg_filename);
ecfg->clisock_filename = allocator_strdup(allocator, oldcfg->clisock_filename);
ecfg->working_dir = allocator_strdup(allocator, oldcfg->working_dir);
ecfg->username = allocator_strdup(allocator, oldcfg->username);
ecfg->group = allocator_strdup(allocator, oldcfg->group);
ecfg->chroot = allocator_strdup(allocator, oldcfg->chroot);
ecfg->pid_filename = allocator_strdup(allocator, oldcfg->pid_filename);
ecfg->datastore = allocator_strdup(allocator, oldcfg->datastore);
ecfg->db_host = allocator_strdup(allocator, oldcfg->db_host);
ecfg->db_username = allocator_strdup(allocator, oldcfg->db_username);
ecfg->db_password = allocator_strdup(allocator, oldcfg->db_password);
ecfg->db_port = oldcfg->db_port;
} else {
ecfg->cfg_filename = allocator_strdup(allocator, cfgfile);
ecfg->clisock_filename = parse_conf_clisock_filename(allocator, cfgfile);
ecfg->working_dir = parse_conf_working_dir(allocator, cfgfile);
ecfg->username = parse_conf_username(allocator, cfgfile);
ecfg->group = parse_conf_group(allocator, cfgfile);
ecfg->chroot = parse_conf_chroot(allocator, cfgfile);
ecfg->pid_filename = parse_conf_pid_filename(allocator, cfgfile);
ecfg->datastore = parse_conf_datastore(allocator, cfgfile);
ecfg->db_host = parse_conf_db_host(allocator, cfgfile);
ecfg->db_username = parse_conf_db_username(allocator, cfgfile);
ecfg->db_password = parse_conf_db_password(allocator, cfgfile);
ecfg->db_port = parse_conf_db_port(cfgfile);
}
/* get values */
ecfg->cfg_filename = allocator_strdup(allocator, cfgfile);
ecfg->policy_filename = parse_conf_policy_filename(allocator,
cfgfile);
ecfg->zonelist_filename = parse_conf_zonelist_filename(allocator,
cfgfile);
ecfg->zonefetch_filename = parse_conf_zonefetch_filename(allocator,
cfgfile);
ecfg->log_filename = parse_conf_log_filename(allocator, cfgfile);
ecfg->pid_filename = parse_conf_pid_filename(allocator, cfgfile);
ecfg->delegation_signer_submit_command =
parse_conf_delegation_signer_submit_command(allocator, cfgfile);
ecfg->delegation_signer_retract_command =
parse_conf_delegation_signer_retract_command(allocator, cfgfile);
ecfg->clisock_filename = parse_conf_clisock_filename(allocator,
cfgfile);
ecfg->working_dir = parse_conf_working_dir(allocator, cfgfile);
ecfg->username = parse_conf_username(allocator, cfgfile);
ecfg->group = parse_conf_group(allocator, cfgfile);
ecfg->chroot = parse_conf_chroot(allocator, cfgfile);
ecfg->datastore = parse_conf_datastore(allocator, cfgfile);
ecfg->db_host = parse_conf_db_host(allocator,cfgfile);
ecfg->db_username = parse_conf_db_username(allocator,cfgfile);
ecfg->db_password = parse_conf_db_password(allocator,cfgfile);
ecfg->use_syslog = parse_conf_use_syslog(cfgfile);
ecfg->num_worker_threads = parse_conf_worker_threads(cfgfile);
ecfg->manual_keygen = parse_conf_manual_keygen(cfgfile);
ecfg->hsm = parse_conf_repositories(cfgfile);
/* If any verbosity has been specified at cmd line we will use that */
if (cmdline_verbosity > 0) {
ecfg->verbosity = cmdline_verbosity;
}
else {
ecfg->verbosity = parse_conf_verbosity(cfgfile);
}
ecfg->db_port = parse_conf_db_port(cfgfile);
ecfg->automatic_keygen_duration =
parse_conf_automatic_keygen_period(cfgfile);
ecfg->verbosity = cmdline_verbosity > 0 ?
cmdline_verbosity : parse_conf_verbosity(cfgfile);
ecfg->automatic_keygen_duration =
parse_conf_automatic_keygen_period(cfgfile);

/* done */
ods_fclose(cfgfd);
Expand Down
2 changes: 1 addition & 1 deletion enforcer-ng/src/daemon/cfg.h
Expand Up @@ -91,7 +91,7 @@ struct engineconfig_struct {
*
*/
engineconfig_type* engine_config(allocator_type* allocator,
const char* cfgfile, int cmdline_verbosity);
const char* cfgfile, int cmdline_verbosity, engineconfig_type* oldcfg);

/**
* Check configuration.
Expand Down
11 changes: 7 additions & 4 deletions enforcer-ng/src/daemon/cmdhandler.c
Expand Up @@ -418,6 +418,9 @@ int handled_help_cmd(int sockfd, engine_type* engine,const char *cmd, ssize_t n)
" the earliest scheduled task.\n"
#endif
"flush Execute all scheduled tasks immediately.\n"
);
ods_writen(sockfd, buf, strlen(buf));
(void) snprintf(buf, ODS_SE_MAXLINE,
"running Returns acknowledgment that the engine is running.\n"
"reload Reload the engine.\n"
"stop Stop the engine and terminate the process.\n"
Expand Down Expand Up @@ -461,6 +464,9 @@ int handled_unknown_cmd(int sockfd, engine_type* engine, const char *cmd, ssize_
" the earliest scheduled task.\n"
#endif
"flush Execute all scheduled tasks immediately.\n"
);
ods_writen(sockfd, buf, strlen(buf));
(void) snprintf(buf, ODS_SE_MAXLINE,
"running Returns acknowledgment that the engine is running.\n"
"reload Reload the engine.\n"
"stop Stop the engine and terminate the process.\n"
Expand Down Expand Up @@ -688,7 +694,6 @@ cmdhandler_start(cmdhandler_type* cmdhandler)
struct sockaddr_un cliaddr;
socklen_t clilen;
cmdhandler_type* cmdc = NULL;
engine_type* engine = NULL;
fd_set rset;
int connfd = 0;
int ret = 0;
Expand All @@ -697,7 +702,6 @@ cmdhandler_start(cmdhandler_type* cmdhandler)
ods_log_assert(cmdhandler->engine);
ods_log_debug("[%s] start", module_str);

engine = cmdhandler->engine;
ods_thread_detach(cmdhandler->thread_id);
FD_ZERO(&rset);
while (cmdhandler->need_to_exit == 0) {
Expand Down Expand Up @@ -741,8 +745,7 @@ cmdhandler_start(cmdhandler_type* cmdhandler)
}

ods_log_debug("[%s] done", module_str);
engine = cmdhandler->engine;
engine->cmdhandler_done = 1;
cmdhandler->engine->cmdhandler_done = 1;
return;
}

Expand Down

0 comments on commit 20c4fa5

Please sign in to comment.