Archived
1
0
Fork 0

output: the need of a configuration file is now module specific.

This commit is contained in:
Henrik Hautakoski 2010-09-26 20:09:53 +02:00
parent d9007a38a7
commit cda3b2c6eb
3 changed files with 19 additions and 7 deletions

View file

@ -15,8 +15,9 @@
#include "output/output.h" #include "output/output.h"
#include "notify/notify.h" #include "notify/notify.h"
#include "ini/iniparser.h" #include "ini/iniparser.h"
#include "common/util.h"
static dictionary *config; static dictionary *config = NULL;
/* only way to exit the application properly /* only way to exit the application properly
@ -97,12 +98,14 @@ int main(int argc, char **argv) {
} }
/* Load configuration */ /* Load configuration */
config = iniparser_load("config.ini"); if (file_exists("config.ini")) {
if (NULL == config) { config = iniparser_load("config.ini");
fprintf(stderr,"Could not load configuration"); if (NULL == config) {
return EXIT_FAILURE; fprintf(stderr, "Could not load configuration");
return EXIT_FAILURE;
}
} }
/* Setup signal handlers */ /* Setup signal handlers */
signal(SIGTERM, sighandl); signal(SIGTERM, sighandl);
signal(SIGKILL, sighandl); signal(SIGKILL, sighandl);

View file

@ -11,8 +11,12 @@
#ifndef __COMMON_UTIL_H #ifndef __COMMON_UTIL_H
#define __COMMON_UTIL_H #define __COMMON_UTIL_H
#include <unistd.h>
void die(const char *, ...); void die(const char *, ...);
void die_errno(const char *); void die_errno(const char *);
#define file_exists(s) (access((s), F_OK) == 0)
#endif /* __COMMOT_UTIL_H */ #endif /* __COMMOT_UTIL_H */

View file

@ -43,6 +43,9 @@ static int database_setup();
*/ */
int output_init(dictionary *config) { int output_init(dictionary *config) {
if (config == NULL)
return 9;
// Load database information from ini config // Load database information from ini config
db.host = iniparser_getstring(config, "mysql:host", NULL); db.host = iniparser_getstring(config, "mysql:host", NULL);
db.port = iniparser_getint(config, "mysql:port", 3306); db.port = iniparser_getint(config, "mysql:port", 3306);
@ -232,6 +235,8 @@ char *output_error(int error) {
return "Error while creating table"; return "Error while creating table";
case 8: case 8:
return "Lost connection to database. Could not reconnect"; return "Lost connection to database. Could not reconnect";
case 9:
return "Missing configuration";
} }
return "Unkown error"; return "Unkown error";
@ -289,4 +294,4 @@ static int database_setup() {
return 0; return 0;
} }