output: the need of a configuration file is now module specific.
This commit is contained in:
parent
d9007a38a7
commit
cda3b2c6eb
3 changed files with 19 additions and 7 deletions
15
src/arch.c
15
src/arch.c
|
|
@ -15,8 +15,9 @@
|
|||
#include "output/output.h"
|
||||
#include "notify/notify.h"
|
||||
#include "ini/iniparser.h"
|
||||
#include "common/util.h"
|
||||
|
||||
static dictionary *config;
|
||||
static dictionary *config = NULL;
|
||||
|
||||
|
||||
/* only way to exit the application properly
|
||||
|
|
@ -97,12 +98,14 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* Load configuration */
|
||||
config = iniparser_load("config.ini");
|
||||
if (NULL == config) {
|
||||
fprintf(stderr,"Could not load configuration");
|
||||
return EXIT_FAILURE;
|
||||
if (file_exists("config.ini")) {
|
||||
config = iniparser_load("config.ini");
|
||||
if (NULL == config) {
|
||||
fprintf(stderr, "Could not load configuration");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Setup signal handlers */
|
||||
signal(SIGTERM, sighandl);
|
||||
signal(SIGKILL, sighandl);
|
||||
|
|
|
|||
|
|
@ -11,8 +11,12 @@
|
|||
#ifndef __COMMON_UTIL_H
|
||||
#define __COMMON_UTIL_H
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void die(const char *, ...);
|
||||
|
||||
void die_errno(const char *);
|
||||
|
||||
#define file_exists(s) (access((s), F_OK) == 0)
|
||||
|
||||
#endif /* __COMMOT_UTIL_H */
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ static int database_setup();
|
|||
*/
|
||||
int output_init(dictionary *config) {
|
||||
|
||||
if (config == NULL)
|
||||
return 9;
|
||||
|
||||
// Load database information from ini config
|
||||
db.host = iniparser_getstring(config, "mysql:host", NULL);
|
||||
db.port = iniparser_getint(config, "mysql:port", 3306);
|
||||
|
|
@ -232,6 +235,8 @@ char *output_error(int error) {
|
|||
return "Error while creating table";
|
||||
case 8:
|
||||
return "Lost connection to database. Could not reconnect";
|
||||
case 9:
|
||||
return "Missing configuration";
|
||||
}
|
||||
|
||||
return "Unkown error";
|
||||
|
|
@ -289,4 +294,4 @@ static int database_setup() {
|
|||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue