fix: better logging behaviour
This commit is contained in:
parent
011c5a6102
commit
0530a350df
30 changed files with 343 additions and 176 deletions
src
37
src/main.c
37
src/main.c
|
@ -4,6 +4,7 @@
|
|||
#include <time.h>
|
||||
#include <lmdb.h>
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <logger.h>
|
||||
#include <mongoose.h>
|
||||
|
@ -31,19 +32,19 @@ static struct mg_mgr mgr;
|
|||
static void
|
||||
terminate(int signum)
|
||||
{
|
||||
LOG_INFO("terminating controller (%d)\n", signum);
|
||||
LOGGER_INFO("terminating controller (%d)\n", signum);
|
||||
|
||||
// TODO fix mg_mgr_free() causing loop (can't terminate)
|
||||
//LOG_DEBUG("freeing mongoose manager\n");
|
||||
//LOGGER_DEBUG("freeing mongoose manager\n");
|
||||
//mg_mgr_free(&mgr);
|
||||
|
||||
LOG_DEBUG("closing database\n");
|
||||
LOGGER_DEBUG("closing database\n");
|
||||
mdb_env_close(global_mdb_env);
|
||||
|
||||
LOG_DEBUG("freeing global controller\n");
|
||||
LOGGER_DEBUG("freeing global controller\n");
|
||||
controller_free(global_controller);
|
||||
|
||||
LOG_DEBUG("freeing relay configs config\n");
|
||||
LOGGER_DEBUG("freeing relay configs config\n");
|
||||
free(global_config.relay_configs);
|
||||
|
||||
exit(signum);
|
||||
|
@ -67,32 +68,46 @@ main(int argc, const char** argv)
|
|||
signal(SIGABRT, terminate);
|
||||
signal(SIGTERM, terminate);
|
||||
|
||||
setlogmask(LOG_UPTO(LOG_INFO));
|
||||
|
||||
|
||||
/******************** LOAD CONFIG ********************/
|
||||
|
||||
global_config.file = "controller.ini";
|
||||
global_config.log_level = LOG_LEVEL_INFO;
|
||||
global_config.discovery_port = 4421;
|
||||
global_config.mqtt_port = 1885;
|
||||
|
||||
global_config.log_level = LOG_INFO;
|
||||
global_config.log_file = stdout;
|
||||
|
||||
strcpy(global_config.user, "");
|
||||
strcpy(global_config.group, "");
|
||||
|
||||
helper_parse_cli(argc, argv, &global_config);
|
||||
|
||||
FILE * const ini_file = fopen(global_config.file, "rb");
|
||||
if(ini_file == NULL)
|
||||
{
|
||||
LOG_FATAL("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, helper_load_config, &global_config))
|
||||
if(load_ini_file( ini_file, INI_DEFAULT_FORMAT, NULL, config_load, &global_config))
|
||||
{
|
||||
LOG_FATAL("unable to parse ini file\n");
|
||||
LOGGER_CRIT("unable to parse ini file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fclose(ini_file);
|
||||
|
||||
if(global_config.log_file == NULL)
|
||||
{
|
||||
global_config.log_file = stdout;
|
||||
}
|
||||
openlog("emgauwa-controller", 0, LOG_USER);
|
||||
|
||||
if(sizeof(time_t) < 8)
|
||||
{
|
||||
LOG_WARN("this system is not using 8-bit time\n");
|
||||
LOGGER_WARNING("this system is not using 8-bit time\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,6 +127,8 @@ main(int argc, const char** argv)
|
|||
|
||||
controller_save(global_controller, global_mdb_env);
|
||||
|
||||
helper_drop_privileges();
|
||||
|
||||
|
||||
/******************** SETUP WIRINGPI ********************/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue