From 96b3a0feb963466447ca8dbc571bc5f670d533cc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 1 Aug 2013 18:14:15 +0200 Subject: [SERVER] Add command line options to create empty image of certain size with empty cache map (so it needs an uplink server) --- src/server/globals.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/server/globals.c') diff --git a/src/server/globals.c b/src/server/globals.c index bfc682b..d84e3f7 100644 --- a/src/server/globals.c +++ b/src/server/globals.c @@ -1,7 +1,36 @@ #include "globals.h" +#include "ini.h" +#include "memlog.h" #include "../types.h" #include +#include +#include +char *_configDir = NULL; char *_basePath = NULL; int _vmdkLegacyMode = FALSE; int _shutdown = 0; + +#define SAVE_TO_VAR_STR(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) { if (_ ## kk != NULL) free(_ ## kk); _ ## kk = strdup(value); } } while (0) +#define SAVE_TO_VAR_BOOL(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) _ ## kk = atoi(value) != 0 || strcmp(value, "true") == 0 || strcmp(value, "True") == 0 || strcmp(value, "TRUE") == 0; } while (0) +#define SAVE_TO_VAR_INT(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) _ ## kk = atoi(value); } while (0) + +static int ini_handler(void *custom, const char* section, const char* key, const char* value) +{ + SAVE_TO_VAR_STR( dnbd3, basePath ); + SAVE_TO_VAR_BOOL( dnbd3, vmdkLegacyMode ); + return TRUE; +} + +void globals_loadConfig() +{ + char *name = NULL; + asprintf( &name, "%s/%s", _configDir, CONFIG_FILENAME ); + if ( name == NULL ) return; + ini_parse( name, &ini_handler, NULL ); + free( name ); + if ( _basePath != NULL && _basePath[0] != '/' ) { + memlogf( "[ERROR] _basePath must be absolute!" ); + exit( EXIT_FAILURE ); + } +} -- cgit v1.2.3-55-g7522