Skip to content

Commit edb1221

Browse files
author
Marc Alff
committed
Bug#50337 --defaults-file=~/something doesn't work anymore
Before this fix, opening a configuration file located under "~" failed. To evaluate the "~" path, home_dir needs to be initialized. The 'home_dir' variable was initialized too late in my_init(). This fix: - moved the home_dir initialization from my_init() to my_basic_init(), using getenv("HOME")) - moved the initialization of my_umask / my_umask_dir also to my_basic_init(), to have all the my_umask / my_umask_dir init code in the same place. The second part is not strictly required, but makes the code more maintainable. Tested the fix manually. No MTR tests added, because MTR should not access or modify the $HOME directory of the user running tests.
1 parent 4428409 commit edb1221

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

mysys/my_init.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static MYSQL_FILE instrumented_stdin;
7474
*/
7575
my_bool my_basic_init(void)
7676
{
77+
char * str;
78+
7779
if (my_basic_init_done)
7880
return 0;
7981
my_basic_init_done= 1;
@@ -82,6 +84,19 @@ my_bool my_basic_init(void)
8284
my_umask= 0660; /* Default umask for new files */
8385
my_umask_dir= 0700; /* Default umask for new directories */
8486

87+
#ifndef VMS
88+
/* Default creation of new files */
89+
if ((str= getenv("UMASK")) != 0)
90+
my_umask= (int) (atoi_octal(str) | 0600);
91+
/* Default creation of new dir's */
92+
if ((str= getenv("UMASK_DIR")) != 0)
93+
my_umask_dir= (int) (atoi_octal(str) | 0700);
94+
#endif
95+
96+
/* $HOME is needed early to parse configuration files located in ~/ */
97+
if ((home_dir= getenv("HOME")) != 0)
98+
home_dir= intern_filename(home_dir_buff, home_dir);
99+
85100
init_glob_errs();
86101

87102
instrumented_stdin.m_file= stdin;
@@ -124,7 +139,6 @@ my_bool my_basic_init(void)
124139

125140
my_bool my_init(void)
126141
{
127-
char * str;
128142
if (my_init_done)
129143
return 0;
130144
my_init_done= 1;
@@ -142,24 +156,11 @@ my_bool my_init(void)
142156
{
143157
DBUG_ENTER("my_init");
144158
DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
145-
if (!home_dir)
146-
{ /* Don't initialize twice */
147-
my_win_init();
148-
if ((home_dir=getenv("HOME")) != 0)
149-
home_dir=intern_filename(home_dir_buff,home_dir);
150-
#ifndef VMS
151-
/* Default creation of new files */
152-
if ((str=getenv("UMASK")) != 0)
153-
my_umask=(int) (atoi_octal(str) | 0600);
154-
/* Default creation of new dir's */
155-
if ((str=getenv("UMASK_DIR")) != 0)
156-
my_umask_dir=(int) (atoi_octal(str) | 0700);
157-
#endif
159+
my_win_init();
158160
#ifdef VMS
159-
init_ctype(); /* Stupid linker don't link _ctype.c */
161+
init_ctype(); /* Stupid linker don't link _ctype.c */
160162
#endif
161-
DBUG_PRINT("exit",("home: '%s'",home_dir));
162-
}
163+
DBUG_PRINT("exit", ("home: '%s'", home_dir));
163164
#ifdef __WIN__
164165
win32_init_tcp_ip();
165166
#endif

0 commit comments

Comments
 (0)