Skip to content

Commit

Permalink
Fix for MDEV-12578: Connector/C doesn't read .my.cnf file in home dir…
Browse files Browse the repository at this point in the history
…ectory.

After lookup in standard directories C/C now also checks in home directory for
configuration file .my.cnf
  • Loading branch information
9EOR9 committed May 7, 2017
1 parent 44a740c commit 99d054e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
15 changes: 14 additions & 1 deletion libmariadb/ma_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@
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);

char *_mariadb_get_default_file(char *filename, size_t length)
{
int dirs; int exts;
char *env;

for (dirs= 0; ini_dirs[dirs]; dirs++)
{
Expand All @@ -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;
}

Expand Down
11 changes: 7 additions & 4 deletions unittest/libmariadb/my_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,13 @@ void get_envvars() {

if (!hostname && (envvar= getenv("MYSQL_TEST_HOST")))
hostname= envvar;
if (!username && (envvar= getenv("MYSQL_TEST_USER")))
username= envvar;
else
username= (char *)"root";
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")))
Expand Down

0 comments on commit 99d054e

Please sign in to comment.