Fix config handling
This commit is contained in:
parent
fad3d80f39
commit
fca35ade9e
18 changed files with 125 additions and 139 deletions
src
38
src/main.c
38
src/main.c
|
@ -7,6 +7,7 @@
|
|||
#include <confini.h>
|
||||
|
||||
#include <cache.h>
|
||||
#include <cli.h>
|
||||
#include <router.h>
|
||||
#include <logger.h>
|
||||
#include <config.h>
|
||||
|
@ -52,22 +53,22 @@ main(int argc, const char** argv)
|
|||
signal(SIGABRT, terminate);
|
||||
signal(SIGTERM, terminate);
|
||||
|
||||
setlogmask(LOG_UPTO(LOG_INFO));
|
||||
|
||||
openlog("emgauwa-core", 0, LOG_USER);
|
||||
setlogmask(LOG_UPTO(LOG_DEBUG));
|
||||
|
||||
/******************** LOAD CONFIG ********************/
|
||||
|
||||
config_init();
|
||||
|
||||
helper_parse_cli(argc, argv, &global_config);
|
||||
cli_parse(argc, argv, global_config);
|
||||
|
||||
FILE * const ini_file = fopen(global_config.file, "rb");
|
||||
FILE * const ini_file = fopen(global_config->file, "rb");
|
||||
if(ini_file == NULL)
|
||||
{
|
||||
LOGGER_CRIT("config file '%s' was not found\n", global_config.file);
|
||||
LOGGER_CRIT("config file '%s' was not found\n", global_config->file);
|
||||
exit(1);
|
||||
}
|
||||
if(load_ini_file(ini_file, INI_DEFAULT_FORMAT, NULL, config_load, &global_config))
|
||||
if(load_ini_file(ini_file, INI_DEFAULT_FORMAT, NULL, config_load, global_config))
|
||||
{
|
||||
LOGGER_CRIT("unable to parse ini file\n");
|
||||
exit(1);
|
||||
|
@ -75,16 +76,12 @@ main(int argc, const char** argv)
|
|||
|
||||
fclose(ini_file);
|
||||
|
||||
memset(&global_config.http_server_opts, 0, sizeof(global_config.http_server_opts));
|
||||
global_config.http_server_opts.document_root = global_config.content_dir;
|
||||
global_config.http_server_opts.enable_directory_listing = "no";
|
||||
global_config.http_server_opts.extra_headers = "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers: *\r\nAccess-Control-Allow-Methods: *";
|
||||
|
||||
if(global_config.log_file == NULL)
|
||||
if(global_config->log_file == NULL)
|
||||
{
|
||||
global_config.log_file = stdout;
|
||||
global_config->log_file = stdout;
|
||||
}
|
||||
openlog("emgauwa-core", 0, LOG_USER);
|
||||
|
||||
LOGGER_DEBUG("Loaded config from %s\n", global_config->file);
|
||||
|
||||
|
||||
/******************** SETUP CONNECTION ********************/
|
||||
|
@ -94,20 +91,20 @@ main(int argc, const char** argv)
|
|||
mg_mgr_init(&mgr, NULL);
|
||||
|
||||
char address[100];
|
||||
sprintf(address, "tcp://0.0.0.0:%u", global_config.server_port);
|
||||
sprintf(address, "tcp://0.0.0.0:%u", global_config->server_port);
|
||||
struct mg_connection *c_http = mg_bind(&mgr, address, handler_http);
|
||||
if(c_http == NULL)
|
||||
{
|
||||
LOGGER_CRIT("failed to bind http server to port %u\n", global_config.server_port);
|
||||
LOGGER_CRIT("failed to bind http server to port %u\n", global_config->server_port);
|
||||
exit(1);
|
||||
}
|
||||
mg_set_protocol_http_websocket(c_http);
|
||||
|
||||
sprintf(address, "tcp://0.0.0.0:%u", global_config.mqtt_port);
|
||||
sprintf(address, "tcp://0.0.0.0:%u", global_config->mqtt_port);
|
||||
struct mg_connection *c_mqtt = mg_bind(&mgr, address, handler_mqtt);
|
||||
if(c_mqtt == NULL)
|
||||
{
|
||||
LOGGER_CRIT("failed to bind mqtt server to port %u\n", global_config.mqtt_port);
|
||||
LOGGER_CRIT("failed to bind mqtt server to port %u\n", global_config->mqtt_port);
|
||||
exit(1);
|
||||
}
|
||||
mg_mqtt_broker_init(&brk, NULL);
|
||||
|
@ -116,6 +113,11 @@ main(int argc, const char** argv)
|
|||
|
||||
helper_drop_privileges();
|
||||
|
||||
memset(&global_config->http_server_opts, 0, sizeof(global_config->http_server_opts));
|
||||
global_config->http_server_opts.document_root = global_config->content_dir;
|
||||
global_config->http_server_opts.enable_directory_listing = "no";
|
||||
global_config->http_server_opts.extra_headers = "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers: *\r\nAccess-Control-Allow-Methods: *";
|
||||
|
||||
|
||||
/******************** INIT COMPONENTS ********************/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue