Commit c83b7817 authored by Marek Vavruša's avatar Marek Vavruša

daemon: -c to set config file outside of rundir

parent fc4813ff
......@@ -489,7 +489,7 @@ int engine_cmd(struct engine *engine, const char *str)
#define l_dosandboxfile(L, filename) \
(luaL_loadfile((L), (filename)) || engine_pcall((L), 0))
static int engine_loadconf(struct engine *engine)
static int engine_loadconf(struct engine *engine, const char *config_path)
{
/* Use module path for including Lua scripts */
static const char l_paths[] = "package.path = package.path..';" PREFIX MODULEDIR "/?.lua'";
......@@ -507,8 +507,8 @@ static int engine_loadconf(struct engine *engine)
return kr_error(ENOEXEC);
}
/* Load config file */
if(access("config", F_OK ) != -1 ) {
ret = l_dosandboxfile(engine->L, "config");
if(access(config_path, F_OK ) != -1 ) {
ret = l_dosandboxfile(engine->L, config_path);
}
if (ret == 0) {
/* Load defaults */
......@@ -526,10 +526,10 @@ static int engine_loadconf(struct engine *engine)
return ret;
}
int engine_start(struct engine *engine)
int engine_start(struct engine *engine, const char *config_path)
{
/* Load configuration. */
int ret = engine_loadconf(engine);
int ret = engine_loadconf(engine, config_path);
if (ret != 0) {
return ret;
}
......
......@@ -61,7 +61,7 @@ int engine_init(struct engine *engine, mm_ctx_t *pool);
void engine_deinit(struct engine *engine);
/** @warning This function leaves 1 string result on stack. */
int engine_cmd(struct engine *engine, const char *str);
int engine_start(struct engine *engine);
int engine_start(struct engine *engine, const char *config_path);
void engine_stop(struct engine *engine);
int engine_register(struct engine *engine, const char *module, const char *precedence, const char* ref);
int engine_unregister(struct engine *engine, const char *module);
......
......@@ -130,6 +130,7 @@ static void help(int argc, char *argv[])
printf("Usage: %s [parameters] [rundir]\n", argv[0]);
printf("\nParameters:\n"
" -a, --addr=[addr] Server address (default: localhost#53).\n"
" -c, --config=[path] Config file path (relative to [rundir]) (default: config).\n"
" -k, --keyfile=[path] File containing trust anchors (DS or DNSKEY).\n"
" -f, --forks=N Start N forks sharing the configuration.\n"
" -v, --verbose Run in verbose mode.\n"
......@@ -202,12 +203,14 @@ int main(int argc, char **argv)
array_t(char*) addr_set;
array_init(addr_set);
char *keyfile = NULL;
const char *config = NULL;
static char keyfile_buf[PATH_MAX + 1];
/* Long options. */
int c = 0, li = 0, ret = 0;
struct option opts[] = {
{"addr", required_argument, 0, 'a'},
{"config", required_argument, 0, 'c'},
{"keyfile",required_argument, 0, 'k'},
{"forks",required_argument, 0, 'f'},
{"verbose", no_argument, 0, 'v'},
......@@ -215,12 +218,15 @@ int main(int argc, char **argv)
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
while ((c = getopt_long(argc, argv, "a:f:k:vVh", opts, &li)) != -1) {
while ((c = getopt_long(argc, argv, "a:c:f:k:vVh", opts, &li)) != -1) {
switch (c)
{
case 'a':
array_push(addr_set, optarg);
break;
case 'c':
config = optarg;
break;
case 'f':
g_interactive = 0;
forks = atoi(optarg);
......@@ -262,7 +268,7 @@ int main(int argc, char **argv)
if (optind < argc) {
const char *rundir = argv[optind];
if (access(rundir, W_OK) != 0) {
log_error("[system] rundir '%s': not writeable\n", rundir);
log_error("[system] rundir '%s': %s\n", rundir, strerror(errno));
return EXIT_FAILURE;
}
ret = chdir(rundir);
......@@ -270,6 +276,11 @@ int main(int argc, char **argv)
log_error("[system] rundir '%s': %s\n", rundir, strerror(errno));
return EXIT_FAILURE;
}
if(config && access(config, R_OK) != 0) {
log_error("[system] rundir '%s'\n", rundir);
log_error("[system] config '%s': %s\n", config, strerror(errno));
return EXIT_FAILURE;
}
}
kr_crypto_init();
......@@ -324,7 +335,7 @@ int main(int argc, char **argv)
}
/* Start the scripting engine */
if (ret == 0) {
ret = engine_start(&engine);
ret = engine_start(&engine, config ? config : "config");
if (ret == 0) {
if (keyfile) {
auto_free char *cmd = afmt("trust_anchors.file = '%s'", keyfile);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment