Fixed custom directory locations not working.

This commit is contained in:
Markus Makela
2015-08-07 19:22:26 +03:00
parent 6cef7ab8cc
commit 710cfbd6c5
3 changed files with 66 additions and 54 deletions

View File

@ -1178,7 +1178,7 @@ int main(int argc, char **argv)
break; break;
case 'D': case 'D':
sprintf(datadir,"%s",optarg); sprintf(datadir,"%s",optarg);
maxscaledatadir = strdup(optarg); set_datadir(strdup(optarg));
datadir_defined = true; datadir_defined = true;
break; break;
case 'C': case 'C':
@ -1190,13 +1190,13 @@ int main(int argc, char **argv)
case 'B': case 'B':
if(handle_path_arg(&tmp_path,optarg,NULL,true,false)) if(handle_path_arg(&tmp_path,optarg,NULL,true,false))
{ {
libdir = tmp_path; set_libdir(tmp_path);
} }
break; break;
case 'A': case 'A':
if(handle_path_arg(&tmp_path,optarg,NULL,true,true)) if(handle_path_arg(&tmp_path,optarg,NULL,true,true))
{ {
cachedir = tmp_path; set_cachedir(tmp_path);
} }
break; break;
case 'S': case 'S':
@ -1552,12 +1552,9 @@ int main(int argc, char **argv)
ini_parse(cnf_file_path,cnf_preparser,NULL); ini_parse(cnf_file_path,cnf_preparser,NULL);
if(!datadir_defined)
sprintf(datadir,"%s",default_datadir);
/** Use the cache dir for the mysql folder of the embedded library */ /** Use the cache dir for the mysql folder of the embedded library */
sprintf(mysql_home, "%s/mysql", cachedir?cachedir:default_cachedir); sprintf(mysql_home, "%s/mysql", get_cachedir());
setenv("MYSQL_HOME", mysql_home, 1); setenv("MYSQL_HOME", mysql_home, 1);
@ -1628,23 +1625,14 @@ int main(int argc, char **argv)
} }
/*
if(cachedir == NULL)
cachedir = strdup(default_cachedir);
if(langdir == NULL)
langdir = strdup(default_langdir);
if(libdir == NULL)
libdir = strdup(default_libdir);
/**
* Set a data directory for the mysqld library, we use * Set a data directory for the mysqld library, we use
* a unique directory name to avoid clauses if multiple * a unique directory name to avoid clauses if multiple
* instances of the gateway are being run on the same * instances of the gateway are being run on the same
* machine. * machine.
*/ */
if(datadir[strlen(datadir)-1] != '/') sprintf(datadir,"%s/data",get_datadir());
strcat(datadir,"/");
strcat(datadir,"data");
if(mkdir(datadir, 0777) != 0){ if(mkdir(datadir, 0777) != 0){
if(errno != EEXIST){ if(errno != EEXIST){
@ -1654,7 +1642,7 @@ int main(int argc, char **argv)
} }
} }
sprintf(datadir, "%s/data%d", datadir, getpid()); sprintf(datadir, "%s/data/data%d", get_datadir(), getpid());
if(mkdir(datadir, 0777) != 0){ if(mkdir(datadir, 0777) != 0){
@ -1676,8 +1664,8 @@ int main(int argc, char **argv)
cnf_file_path, cnf_file_path,
logdir, logdir,
datadir, datadir,
libdir, get_libdir(),
cachedir); get_cachedir());
} }
LOGIF(LM, LOGIF(LM,
@ -1698,11 +1686,11 @@ int main(int argc, char **argv)
LOGIF(LM, LOGIF(LM,
(skygw_log_write_flush(LOGFILE_MESSAGE, (skygw_log_write_flush(LOGFILE_MESSAGE,
"Module directory: %s", "Module directory: %s",
libdir))); get_libdir())));
LOGIF(LM, LOGIF(LM,
(skygw_log_write_flush(LOGFILE_MESSAGE, (skygw_log_write_flush(LOGFILE_MESSAGE,
"Service cache: %s", "Service cache: %s",
cachedir))); get_cachedir())));
/*< Update the server options */ /*< Update the server options */
for (i = 0; server_options[i]; i++) for (i = 0; server_options[i]; i++)
@ -1717,7 +1705,7 @@ int main(int argc, char **argv)
snprintf(language_arg, snprintf(language_arg,
11+PATH_MAX+1, 11+PATH_MAX+1,
"--language=%s", "--language=%s",
langdir); langdir?langdir:default_langdir);
server_options[i] = language_arg; server_options[i] = language_arg;
} }
} }
@ -1773,9 +1761,6 @@ int main(int argc, char **argv)
} }
libmysqld_started = TRUE; libmysqld_started = TRUE;
if(libdir == NULL)
libdir = strdup(default_libdir);
if (!config_load(cnf_file_path)) if (!config_load(cnf_file_path))
{ {
char* fprerr = "Failed to load MaxScale configuration " char* fprerr = "Failed to load MaxScale configuration "
@ -2080,7 +2065,7 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
char pathbuffer[PATH_MAX]; char pathbuffer[PATH_MAX];
char* errstr; char* errstr;
char *tmp;
/** These are read from the configuration file. These will not override /** These are read from the configuration file. These will not override
* command line parameters but will override default values. */ * command line parameters but will override default values. */
if(strcasecmp(section,"maxscale") == 0) if(strcasecmp(section,"maxscale") == 0)
@ -2092,8 +2077,11 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
} }
else if(strcmp(name, "libdir") == 0) else if(strcmp(name, "libdir") == 0)
{ {
if(libdir == NULL) if(get_libdir() == default_libdir )
handle_path_arg(&libdir,(char*)value,NULL,true,false); {
handle_path_arg(&tmp,(char*)value,NULL,true,false);
set_libdir(tmp);
}
} }
else if(strcmp(name, "piddir") == 0) else if(strcmp(name, "piddir") == 0)
{ {
@ -2108,16 +2096,18 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
if(handle_path_arg(&tmp,(char*)value,NULL,true,false)) if(handle_path_arg(&tmp,(char*)value,NULL,true,false))
{ {
sprintf(datadir,"%s",tmp); sprintf(datadir,"%s",tmp);
maxscaledatadir = strdup(tmp); set_datadir(tmp);
datadir_defined = true; datadir_defined = true;
free(tmp);
} }
} }
} }
else if(strcmp(name, "cachedir") == 0) else if(strcmp(name, "cachedir") == 0)
{ {
if(cachedir == NULL) if(get_cachedir() == default_cachedir)
handle_path_arg((char**)&cachedir,(char*)value,NULL,true,false); {
handle_path_arg((char**)&tmp,(char*)value,NULL,true,false);
set_cachedir(tmp);
}
} }
else if(strcmp(name, "language") == 0) else if(strcmp(name, "language") == 0)
{ {

View File

@ -9,6 +9,12 @@ char* get_libdir()
return libdir?libdir:(char*)default_libdir; return libdir?libdir:(char*)default_libdir;
} }
void set_libdir(char* param)
{
if(libdir)
free(libdir);
libdir = param;
}
/** /**
* Get the service cache directory * Get the service cache directory
* @return The path to the cache directory * @return The path to the cache directory
@ -18,6 +24,12 @@ char* get_cachedir()
return cachedir?cachedir:(char*)default_cachedir; return cachedir?cachedir:(char*)default_cachedir;
} }
void set_cachedir(char* param)
{
if(cachedir)
free(cachedir);
cachedir = param;
}
/** /**
* Get the service cache directory * Get the service cache directory
@ -27,3 +39,10 @@ char* get_datadir()
{ {
return maxscaledatadir?maxscaledatadir:(char*)default_datadir; return maxscaledatadir?maxscaledatadir:(char*)default_datadir;
} }
void set_datadir(char* param)
{
if(maxscaledatadir)
free(maxscaledatadir);
maxscaledatadir = param;
}

View File

@ -25,15 +25,15 @@
#include <string.h> #include <string.h>
/** Default file locations, configured by CMake */ /** Default file locations, configured by CMake */
static const char* default_cnf_fname = "maxscale.cnf"; static const char* default_cnf_fname = "maxscale.cnf";
static const char* default_configdir = "/etc/"; static const char* default_configdir = "/etc";
static const char* default_piddir = "@MAXSCALE_VARDIR@/run/maxscale/"; /*< This should be changed to just /run eventually, static const char* default_piddir = "@MAXSCALE_VARDIR@/run/maxscale"; /*< This should be changed to just /run eventually,
* the /var/run folder is an old standard and the newe FSH 3.0 * the /var/run folder is an old standard and the newe FSH 3.0
* uses /run for PID files.*/ * uses /run for PID files.*/
static const char* default_logdir = "@MAXSCALE_VARDIR@/log/maxscale/"; static const char* default_logdir = "@MAXSCALE_VARDIR@/log/maxscale";
static const char* default_datadir = "@MAXSCALE_VARDIR@/lib/maxscale/"; static const char* default_datadir = "@MAXSCALE_VARDIR@/lib/maxscale";
static const char* default_libdir = "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@"; static const char* default_libdir = "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@";
static const char* default_cachedir = "@MAXSCALE_VARDIR@/cache/maxscale/"; static const char* default_cachedir = "@MAXSCALE_VARDIR@/cache/maxscale";
static const char* default_langdir = "@MAXSCALE_VARDIR@/lib/maxscale/"; static const char* default_langdir = "@MAXSCALE_VARDIR@/lib/maxscale";
static char* configdir = NULL; static char* configdir = NULL;
static char* logdir = NULL; static char* logdir = NULL;
@ -42,6 +42,9 @@ static char* cachedir = NULL;
static char* maxscaledatadir = NULL; static char* maxscaledatadir = NULL;
static char* langdir = NULL; static char* langdir = NULL;
static char* piddir = NULL; static char* piddir = NULL;
void set_libdir(char* param);
void set_datadir(char* param);
void set_cachedir(char* param);
char* get_libdir(); char* get_libdir();
char* get_datadir(); char* get_datadir();
char* get_cachedir(); char* get_cachedir();