MXS-463: Filepaths are now properly formatted for printing
The various global directory setter functions now process the input they receive and remove redundant and trailing forward slashes from the directory paths.
This commit is contained in:
parent
05a7f5759b
commit
4ef89d213b
@ -17,66 +17,101 @@
|
||||
*/
|
||||
|
||||
#include <gwdirs.h>
|
||||
#include <gw.h>
|
||||
|
||||
/**
|
||||
* Set the configuration file directory
|
||||
* @param str Path to directory
|
||||
*/
|
||||
void set_configdir(char* str)
|
||||
{
|
||||
free(configdir);
|
||||
clean_up_pathname(str);
|
||||
configdir = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log file directory
|
||||
* @param str Path to directory
|
||||
*/
|
||||
void set_logdir(char* str)
|
||||
{
|
||||
free(logdir);
|
||||
clean_up_pathname(str);
|
||||
logdir = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the language file directory
|
||||
* @param str Path to directory
|
||||
*/
|
||||
void set_langdir(char* str)
|
||||
{
|
||||
free(langdir);
|
||||
clean_up_pathname(str);
|
||||
langdir = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the PID file directory
|
||||
* @param str Path to directory
|
||||
*/
|
||||
void set_piddir(char* str)
|
||||
{
|
||||
free(piddir);
|
||||
clean_up_pathname(str);
|
||||
piddir = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache directory
|
||||
* @param str Path to directory
|
||||
*/
|
||||
void set_cachedir(char* param)
|
||||
{
|
||||
free(cachedir);
|
||||
clean_up_pathname(param);
|
||||
cachedir = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data directory
|
||||
* @param str Path to directory
|
||||
*/
|
||||
void set_datadir(char* param)
|
||||
{
|
||||
free(maxscaledatadir);
|
||||
clean_up_pathname(param);
|
||||
maxscaledatadir = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the library directory. Modules will be loaded from here.
|
||||
* @param str Path to directory
|
||||
*/
|
||||
void set_libdir(char* param)
|
||||
{
|
||||
free(libdir);
|
||||
clean_up_pathname(param);
|
||||
libdir = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directory with all the modules.
|
||||
* @return The module directory
|
||||
*/
|
||||
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
|
||||
* @return The path to the cache directory
|
||||
*/
|
||||
char* get_cachedir()
|
||||
{
|
||||
return cachedir ? cachedir : (char*)default_cachedir;
|
||||
}
|
||||
|
||||
void set_cachedir(char* param)
|
||||
{
|
||||
if (cachedir)
|
||||
{
|
||||
free(cachedir);
|
||||
}
|
||||
|
||||
cachedir = param;
|
||||
return cachedir ? cachedir : (char*) default_cachedir;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,35 +120,41 @@ void set_cachedir(char* param)
|
||||
*/
|
||||
char* get_datadir()
|
||||
{
|
||||
return maxscaledatadir ? maxscaledatadir : (char*)default_datadir;
|
||||
}
|
||||
|
||||
void set_datadir(char* param)
|
||||
{
|
||||
if (maxscaledatadir)
|
||||
{
|
||||
free(maxscaledatadir);
|
||||
}
|
||||
|
||||
maxscaledatadir = param;
|
||||
return maxscaledatadir ? maxscaledatadir : (char*) default_datadir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration file directory
|
||||
* @return The path to the configuration file directory
|
||||
*/
|
||||
char* get_configdir()
|
||||
{
|
||||
return configdir ? configdir : (char*)default_configdir;
|
||||
return configdir ? configdir : (char*) default_configdir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PID file directory which contains maxscale.pid
|
||||
* @return Path to the PID file directory
|
||||
*/
|
||||
char* get_piddir()
|
||||
{
|
||||
return piddir ? piddir : (char*)default_piddir;
|
||||
return piddir ? piddir : (char*) default_piddir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the log file directory
|
||||
* @return Path to the log file directory
|
||||
*/
|
||||
char* get_logdir()
|
||||
{
|
||||
return logdir ? logdir : (char*)default_logdir;
|
||||
return logdir ? logdir : (char*) default_logdir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Path to the directory which contains the errmsg.sys language file
|
||||
* @return Path to the language file directory
|
||||
*/
|
||||
char* get_langdir()
|
||||
{
|
||||
return langdir ? langdir : (char*)default_langdir;
|
||||
return langdir ? langdir : (char*) default_langdir;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <gwdirs.h>
|
||||
#include <random_jkiss.h>
|
||||
|
||||
#include "gw.h"
|
||||
|
||||
/**
|
||||
* Generate a random printable character
|
||||
*
|
||||
@ -67,6 +69,7 @@ secrets_readKeys(const char* path)
|
||||
if (path != NULL)
|
||||
{
|
||||
snprintf(secret_file, PATH_MAX, "%s/.secrets", path);
|
||||
clean_up_pathname(secret_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -224,7 +227,7 @@ int secrets_writeKeys(const char *path)
|
||||
}
|
||||
|
||||
snprintf(secret_file, PATH_MAX + 9, "%s/.secrets", path);
|
||||
secret_file[PATH_MAX + 9] = '\0';
|
||||
clean_up_pathname(secret_file);
|
||||
|
||||
/* Open for writing | Create | Truncate the file for writing */
|
||||
if ((fd = open(secret_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR)) < 0)
|
||||
|
@ -278,3 +278,44 @@ char *create_hex_sha1_sha1_passwd(char *passwd)
|
||||
|
||||
return hexpasswd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove duplicate and trailing forward slashes from a path.
|
||||
* @param path Path to clean up
|
||||
*/
|
||||
void clean_up_pathname(char *path)
|
||||
{
|
||||
char *data = path;
|
||||
size_t len = strlen(path);
|
||||
|
||||
if (len > PATH_MAX)
|
||||
{
|
||||
MXS_WARNING("Pathname too long: %s", path);
|
||||
}
|
||||
|
||||
while (*data != '\0')
|
||||
{
|
||||
if (*data == '/')
|
||||
{
|
||||
if (*(data + 1) == '/')
|
||||
{
|
||||
memmove(data, data + 1, len);
|
||||
len--;
|
||||
}
|
||||
else if (*(data + 1) == '\0' && data != path)
|
||||
{
|
||||
*data = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
data++;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data++;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,4 +89,5 @@ int parse_bindconfig(char *, unsigned short, struct sockaddr_in *);
|
||||
int setipaddress(struct in_addr *, char *);
|
||||
char* get_libdir();
|
||||
long get_processor_count();
|
||||
void clean_up_pathname(char *path);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user