summaryrefslogtreecommitdiffstats
path: root/src/server/globals.c
diff options
context:
space:
mode:
authorSimon Rettberg2013-08-01 18:14:15 +0200
committerSimon Rettberg2013-08-01 18:14:15 +0200
commit96b3a0feb963466447ca8dbc571bc5f670d533cc (patch)
treee546179f4d6d5cbb23dae202a8bf59b9f2ce95bb /src/server/globals.c
parent[SERVER] Add inih (http://code.google.com/p/inih/) for *.ini parsing (diff)
downloaddnbd3-96b3a0feb963466447ca8dbc571bc5f670d533cc.tar.gz
dnbd3-96b3a0feb963466447ca8dbc571bc5f670d533cc.tar.xz
dnbd3-96b3a0feb963466447ca8dbc571bc5f670d533cc.zip
[SERVER] Add command line options to create empty image of certain size with empty cache map (so it needs an uplink server)
Diffstat (limited to 'src/server/globals.c')
-rw-r--r--src/server/globals.c29
1 files changed, 29 insertions, 0 deletions
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 <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+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 );
+ }
+}