Skip to content
Snippets Groups Projects
Verified Commit ee2f97a8 authored by Tomas Krizek's avatar Tomas Krizek Committed by Petr Špaček
Browse files

daemon/main: support multiple config files

parent 6d209ef9
No related branches found
No related tags found
1 merge request!909daemon/main: support multiple config files
......@@ -55,6 +55,8 @@
/* @internal Array of ip address shorthand. */
typedef array_t(char*) addr_array_t;
typedef array_t(const char*) config_array_t;
typedef struct {
int fd;
endpoint_flags_t flags; /**< .sock_type isn't meaningful here */
......@@ -66,7 +68,7 @@ struct args {
flagged_fd_array_t fds;
int control_fd;
int forks;
const char *config;
config_array_t config;
const char *rundir;
bool interactive;
bool quiet;
......@@ -495,6 +497,7 @@ static void args_deinit(struct args *args)
for (int i = 0; i < args->fds.len; ++i)
free_const(args->fds.at[i].flags.kind);
array_clear(args->fds);
array_clear(args->config);
}
static long strtol_10(const char *s)
......@@ -534,7 +537,7 @@ static int parse_args(int argc, char **argv, struct args *args)
array_push(args->addrs_tls, optarg);
break;
case 'c':
args->config = optarg;
array_push(args->config, optarg);
break;
case 'f':
args->interactive = false;
......@@ -759,12 +762,16 @@ int main(int argc, char **argv)
}
}
if (args.config && strcmp(args.config, "-") != 0 && access(args.config, R_OK) != 0) {
kr_log_error("[system] config '%s': %s\n", args.config, strerror(errno));
return EXIT_FAILURE;
/* Check config(s) are read-able */
for (size_t i = 0; i < args.config.len; ++i) {
const char *config = args.config.at[i];
if (config != NULL && strcmp(config, "-") != 0 && access(config, R_OK) != 0) {
kr_log_error("[system] config '%s': %s\n", config, strerror(errno));
return EXIT_FAILURE;
}
}
if (!args.config && access("config", R_OK) == 0) {
args.config = "config";
if (args.config.len == 0 && access("config", R_OK) == 0) {
array_push(args.config, "config");
}
/* File-descriptor count limit: soft->hard. */
......@@ -868,20 +875,29 @@ int main(int argc, char **argv)
ret = EXIT_FAILURE;
goto cleanup;
}
if (args.config != NULL && strcmp(args.config, "-") != 0) {
if(engine_loadconf(&engine, args.config) != 0) {
bool load_defaults = true;
for (size_t i = 0; i < args.config.len; ++i) {
const char *config = args.config.at[i];
if (config == NULL)
continue;
if (strcmp(config, "-") == 0) {
load_defaults = false;
continue;
}
if(engine_loadconf(&engine, config) != 0) {
ret = EXIT_FAILURE;
goto cleanup;
}
lua_settop(engine.L, 0);
}
if (args.config == NULL || strcmp(args.config, "-") !=0) {
if(engine_load_defaults(&engine) != 0) {
ret = EXIT_FAILURE;
goto cleanup;
}
if (load_defaults && engine_load_defaults(&engine) != 0) {
ret = EXIT_FAILURE;
goto cleanup;
}
drop_capabilities();
if (engine_start(&engine) != 0) {
ret = EXIT_FAILURE;
goto cleanup;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment