From cda3b2c6ebfe64ff0bbe1675f10f1d12c720003a Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 26 Sep 2010 20:09:53 +0200 Subject: [PATCH] output: the need of a configuration file is now module specific. --- src/arch.c | 15 +++++++++------ src/common/util.h | 4 ++++ src/output/mysql.c | 7 ++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/arch.c b/src/arch.c index 4e69d9d..28321b3 100644 --- a/src/arch.c +++ b/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); diff --git a/src/common/util.h b/src/common/util.h index 1d968ba..876fbdb 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -11,8 +11,12 @@ #ifndef __COMMON_UTIL_H #define __COMMON_UTIL_H +#include + void die(const char *, ...); void die_errno(const char *); +#define file_exists(s) (access((s), F_OK) == 0) + #endif /* __COMMOT_UTIL_H */ diff --git a/src/output/mysql.c b/src/output/mysql.c index 204b2b3..7c79463 100644 --- a/src/output/mysql.c +++ b/src/output/mysql.c @@ -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; -} \ No newline at end of file +}