You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
Fix for MDEV-12578: Connector/C doesn't read .my.cnf file in home directory.
After lookup in standard directories C/C now also checks in home directory for configuration file .my.cnf
This commit is contained in:
@@ -30,12 +30,14 @@
|
||||
static const char *ini_exts[]= {"ini", "cnf", 0};
|
||||
static const char *ini_dirs[]= {"C:", ".", 0};
|
||||
static const char *ini_env_dirs[]= {"WINDOWS", "HOMEPATH", 0};
|
||||
#define ENV_HOME_DIR "HOMEPATH"
|
||||
#define R_OK 4
|
||||
#else
|
||||
#include <unistd.h>
|
||||
static const char *ini_exts[]= {"cnf", 0};
|
||||
static const char *ini_dirs[]= {"/etc", "/etc/mysql", ".", 0};
|
||||
static const char *ini_env_dirs[]= {"HOME", "SYSCONFDIR", 0};
|
||||
#define ENV_HOME_DIR "HOME"
|
||||
#endif
|
||||
|
||||
extern my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value);
|
||||
@@ -43,6 +45,7 @@ extern my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option,
|
||||
char *_mariadb_get_default_file(char *filename, size_t length)
|
||||
{
|
||||
int dirs; int exts;
|
||||
char *env;
|
||||
|
||||
for (dirs= 0; ini_dirs[dirs]; dirs++)
|
||||
{
|
||||
@@ -58,13 +61,23 @@ char *_mariadb_get_default_file(char *filename, size_t length)
|
||||
{
|
||||
for (exts= 0; ini_exts[exts]; exts++)
|
||||
{
|
||||
char *env= getenv(ini_env_dirs[dirs]);
|
||||
env= getenv(ini_env_dirs[dirs]);
|
||||
snprintf(filename, length,
|
||||
"%s%cmy.%s", env, FN_LIBCHAR, ini_exts[exts]);
|
||||
if (!access(filename, R_OK))
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
|
||||
/* check for .my file in home directoy */
|
||||
env= getenv(ENV_HOME_DIR);
|
||||
for (exts= 0; ini_exts[exts]; exts++)
|
||||
{
|
||||
snprintf(filename, length,
|
||||
"%s%c.my.%s", env, FN_LIBCHAR, ini_exts[exts]);
|
||||
if (!access(filename, R_OK))
|
||||
return filename;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -454,10 +454,13 @@ void get_envvars() {
|
||||
|
||||
if (!hostname && (envvar= getenv("MYSQL_TEST_HOST")))
|
||||
hostname= envvar;
|
||||
if (!username && (envvar= getenv("MYSQL_TEST_USER")))
|
||||
if (!username)
|
||||
{
|
||||
if ((envvar= getenv("MYSQL_TEST_USER")))
|
||||
username= envvar;
|
||||
else
|
||||
username= (char *)"root";
|
||||
}
|
||||
if (!password && (envvar= getenv("MYSQL_TEST_PASSWD")))
|
||||
password= envvar;
|
||||
if (!schema && (envvar= getenv("MYSQL_TEST_DB")))
|
||||
|
Reference in New Issue
Block a user