Add module configuration directory

This directory is intended to be the default working directory for
relative pathname resolution. The actual implementation for
MXS_MODULE_PARAM_PATH is done at a later step.
This commit is contained in:
Markus Mäkelä
2017-01-11 12:52:01 +02:00
parent a196420c2d
commit 0865eada03
4 changed files with 83 additions and 13 deletions

View File

@ -388,6 +388,16 @@ or modify the contents of this directory, use _/etc/maxscale.cnf.d/_ instead.
persistdir=/var/lib/maxscale/maxscale.cnf.d/ persistdir=/var/lib/maxscale/maxscale.cnf.d/
``` ```
#### `module_configdir`
Configure the directory where module configurations are stored. Path arguments
are resolved relative to this directory. This directory should be used to store
module specific configurations e.g. dbfwfilter rule files.
```
module_configdir=/var/lib/maxscale/
```
#### `language` #### `language`
Set the folder where the errmsg.sys file is located in. MariaDB MaxScale will look for the errmsg.sys file installed with MariaDB MaxScale from this folder. Set the folder where the errmsg.sys file is located in. MariaDB MaxScale will look for the errmsg.sys file installed with MariaDB MaxScale from this folder.

View File

@ -30,6 +30,7 @@ MXS_BEGIN_DECLS
#define MXS_DEFAULT_EXEC_SUBPATH "@DEFAULT_EXEC_SUBPATH@" #define MXS_DEFAULT_EXEC_SUBPATH "@DEFAULT_EXEC_SUBPATH@"
#define MXS_DEFAULT_CONFIG_SUBPATH "@DEFAULT_CONFIG_SUBPATH@" #define MXS_DEFAULT_CONFIG_SUBPATH "@DEFAULT_CONFIG_SUBPATH@"
#define MXS_DEFAULT_CONFIG_PERSIST_SUBPATH "@DEFAULT_CONFIG_PERSIST_SUBPATH@" #define MXS_DEFAULT_CONFIG_PERSIST_SUBPATH "@DEFAULT_CONFIG_PERSIST_SUBPATH@"
#define MXS_DEFAULT_MODULE_CONFIG_SUBPATH "@DEFAULT_MODULE_CONFIG_SUBPATH@"
/** Default file locations, configured by CMake */ /** Default file locations, configured by CMake */
#define MXS_DEFAULT_CONFIGDIR "@DEFAULT_CONFIGDIR@" #define MXS_DEFAULT_CONFIGDIR "@DEFAULT_CONFIGDIR@"
@ -41,6 +42,7 @@ MXS_BEGIN_DECLS
#define MXS_DEFAULT_LANGDIR "@DEFAULT_LANGDIR@" #define MXS_DEFAULT_LANGDIR "@DEFAULT_LANGDIR@"
#define MXS_DEFAULT_EXECDIR "@DEFAULT_EXECDIR@" #define MXS_DEFAULT_EXECDIR "@DEFAULT_EXECDIR@"
#define MXS_DEFAULT_CONFIG_PERSISTDIR "@DEFAULT_CONFIG_PERSISTDIR@" #define MXS_DEFAULT_CONFIG_PERSISTDIR "@DEFAULT_CONFIG_PERSISTDIR@"
#define MXS_DEFAULT_MODULE_CONFIGDIR "@DEFAULT_MODULE_CONFIGDIR@"
static const char* default_cnf_fname = "maxscale.cnf"; static const char* default_cnf_fname = "maxscale.cnf";
static const char* default_configdir = MXS_DEFAULT_CONFIGDIR; static const char* default_configdir = MXS_DEFAULT_CONFIGDIR;
@ -56,9 +58,11 @@ static const char* default_cachedir = MXS_DEFAULT_CACHEDIR;
static const char* default_langdir = MXS_DEFAULT_LANGDIR; static const char* default_langdir = MXS_DEFAULT_LANGDIR;
static const char* default_execdir = MXS_DEFAULT_EXECDIR; static const char* default_execdir = MXS_DEFAULT_EXECDIR;
static const char* default_config_persistdir = MXS_DEFAULT_CONFIG_PERSISTDIR; static const char* default_config_persistdir = MXS_DEFAULT_CONFIG_PERSISTDIR;
static const char* default_module_configdir = MXS_DEFAULT_MODULE_CONFIGDIR;
static char* configdir = NULL; /*< Where the config file is found e.g. /etc/ */ static char* configdir = NULL; /*< Where the config file is found e.g. /etc/ */
static char* config_persistdir = NULL;/*< Persisted configs e.g. /var/lib/maxscale.cnf.d/ */ static char* config_persistdir = NULL;/*< Persisted configs e.g. /var/lib/maxscale/maxscale.cnf.d/ */
static char* module_configdir = NULL;/*< Module specific configs e.g. /var/lib/maxscale/ */
static char* logdir = NULL; static char* logdir = NULL;
static char* libdir = NULL; static char* libdir = NULL;
static char* cachedir = NULL; static char* cachedir = NULL;
@ -74,6 +78,7 @@ void set_process_datadir(char* param);
void set_cachedir(char* param); void set_cachedir(char* param);
void set_configdir(char* param); void set_configdir(char* param);
void set_config_persistdir(char* param); void set_config_persistdir(char* param);
void set_module_configdir(char* param);
void set_logdir(char* param); void set_logdir(char* param);
void set_langdir(char* param); void set_langdir(char* param);
void set_piddir(char* param); void set_piddir(char* param);
@ -84,6 +89,7 @@ char* get_process_datadir();
char* get_cachedir(); char* get_cachedir();
char* get_configdir(); char* get_configdir();
char* get_config_persistdir(); char* get_config_persistdir();
char* get_module_configdir();
char* get_piddir(); char* get_piddir();
char* get_logdir(); char* get_logdir();
char* get_langdir(); char* get_langdir();

View File

@ -123,6 +123,7 @@ static struct option long_options[] =
{"datadir", required_argument, 0, 'D'}, {"datadir", required_argument, 0, 'D'},
{"execdir", required_argument, 0, 'E'}, {"execdir", required_argument, 0, 'E'},
{"persistdir", required_argument, 0, 'F'}, {"persistdir", required_argument, 0, 'F'},
{"module_configdir", required_argument, 0, 'M'},
{"language", required_argument, 0, 'N'}, {"language", required_argument, 0, 'N'},
{"piddir", required_argument, 0, 'P'}, {"piddir", required_argument, 0, 'P'},
{"basedir", required_argument, 0, 'R'}, {"basedir", required_argument, 0, 'R'},
@ -912,6 +913,7 @@ static void usage(void)
" stores internal MaxScale data\n" " stores internal MaxScale data\n"
" -E, --execdir=PATH path to the maxscale and other executable files\n" " -E, --execdir=PATH path to the maxscale and other executable files\n"
" -F, --persistdir=PATH path to persisted configuration directory\n" " -F, --persistdir=PATH path to persisted configuration directory\n"
" -M, --module_configdir=PATH path to module configuration directory\n"
" -N, --language=PATH path to errmsg.sys file\n" " -N, --language=PATH path to errmsg.sys file\n"
" -P, --piddir=PATH path to PID file directory\n" " -P, --piddir=PATH path to PID file directory\n"
" -R, --basedir=PATH base path for all other paths\n" " -R, --basedir=PATH base path for all other paths\n"
@ -926,16 +928,17 @@ static void usage(void)
" -?, --help show this help\n" " -?, --help show this help\n"
"\n" "\n"
"Defaults paths:\n" "Defaults paths:\n"
" config file: %s/%s\n" " config file : %s/%s\n"
" configdir : %s\n" " configdir : %s\n"
" logdir : %s\n" " logdir : %s\n"
" cachedir : %s\n" " cachedir : %s\n"
" libdir : %s\n" " libdir : %s\n"
" datadir : %s\n" " datadir : %s\n"
" execdir : %s\n" " execdir : %s\n"
" language : %s\n" " language : %s\n"
" piddir : %s\n" " piddir : %s\n"
" persistdir : %s\n" " persistdir : %s\n"
" module configdir : %s\n"
"\n" "\n"
"If '--basedir' is provided then all other paths, including the default\n" "If '--basedir' is provided then all other paths, including the default\n"
"configuration file path, are defined relative to that. As an example,\n" "configuration file path, are defined relative to that. As an example,\n"
@ -947,7 +950,7 @@ static void usage(void)
get_configdir(), default_cnf_fname, get_configdir(), default_cnf_fname,
get_configdir(), get_logdir(), get_cachedir(), get_libdir(), get_configdir(), get_logdir(), get_cachedir(), get_libdir(),
get_datadir(), get_execdir(), get_langdir(), get_piddir(), get_datadir(), get_execdir(), get_langdir(), get_piddir(),
get_config_persistdir()); get_config_persistdir(), get_module_configdir());
} }
@ -1196,6 +1199,11 @@ bool set_dirs(const char *basedir)
set_configdir(path); set_configdir(path);
} }
if (rv && (rv = handle_path_arg(&path, basedir, MXS_DEFAULT_MODULE_CONFIG_SUBPATH, true, false)))
{
set_module_configdir(path);
}
if (rv && (rv = handle_path_arg(&path, basedir, "var/" MXS_DEFAULT_DATA_SUBPATH, true, false))) if (rv && (rv = handle_path_arg(&path, basedir, "var/" MXS_DEFAULT_DATA_SUBPATH, true, false)))
{ {
set_datadir(path); set_datadir(path);
@ -1311,7 +1319,7 @@ int main(int argc, char **argv)
} }
} }
while ((opt = getopt_long(argc, argv, "dcf:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:", while ((opt = getopt_long(argc, argv, "dcf:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:",
long_options, &option_index)) != -1) long_options, &option_index)) != -1)
{ {
bool succp = true; bool succp = true;
@ -1473,6 +1481,18 @@ int main(int argc, char **argv)
succp = false; succp = false;
} }
break; break;
case 'M':
if (handle_path_arg(&tmp_path, optarg, NULL, true, true))
{
set_module_configdir(tmp_path);
}
else
{
succp = false;
}
break;
case 'R': case 'R':
if (handle_path_arg(&tmp_path, optarg, NULL, true, false)) if (handle_path_arg(&tmp_path, optarg, NULL, true, false))
{ {
@ -2485,6 +2505,20 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
} }
} }
} }
else if (strcmp(name, "module_configdir") == 0)
{
if (strcmp(get_module_configdir(), default_module_configdir) == 0)
{
if (handle_path_arg((char**)&tmp, (char*)value, NULL, true, false))
{
set_module_configdir(tmp);
}
else
{
return 0;
}
}
}
else if (strcmp(name, "syslog") == 0) else if (strcmp(name, "syslog") == 0)
{ {
if (!syslog_configured) if (!syslog_configured)

View File

@ -26,6 +26,17 @@ void set_configdir(char* str)
configdir = str; configdir = str;
} }
/**
* Set the module configuration file directory
* @param str Path to directory
*/
void set_module_configdir(char* str)
{
MXS_FREE(module_configdir);
clean_up_pathname(str);
module_configdir = str;
}
/** /**
* Set the configuration parts file directory * Set the configuration parts file directory
* @param str Path to directory * @param str Path to directory
@ -171,6 +182,15 @@ char* get_configdir()
return configdir ? configdir : (char*) default_configdir; return configdir ? configdir : (char*) default_configdir;
} }
/**
* Get the module configuration file directory
* @return The path to the module configuration file directory
*/
char* get_module_configdir()
{
return module_configdir ? module_configdir : (char*) default_module_configdir;
}
/** /**
* Get the configuration file directory * Get the configuration file directory
* @return The path to the configuration file directory * @return The path to the configuration file directory