17
17
#include <sslopt-vars.h>
18
18
#include "../scripts/mysql_fix_privilege_tables_sql.c"
19
19
20
+ #ifdef HAVE_SYS_WAIT_H
21
+ #include <sys/wait.h>
22
+ #endif
23
+
24
+ #ifndef WEXITSTATUS
25
+ # ifdef __WIN__
26
+ # define WEXITSTATUS (stat_val ) (stat_val)
27
+ # else
28
+ # define WEXITSTATUS (stat_val ) ((unsigned)(stat_val) >> 8)
29
+ # endif
30
+ #endif
31
+
20
32
static char mysql_path [FN_REFLEN ];
21
33
static char mysqlcheck_path [FN_REFLEN ];
22
- static char defaults_file_option [32 + FN_REFLEN ];
23
34
24
35
static my_bool opt_force , opt_verbose ;
25
36
static char * opt_user = (char * )"root" ;
26
37
27
- static DYNAMIC_STRING ds_options ;
38
+ static DYNAMIC_STRING ds_args ;
28
39
29
40
static char * opt_password = 0 ;
30
41
static my_bool tty_password = 0 ;
@@ -35,8 +46,6 @@ static char *default_dbug_option= (char*) "d:t:O,/tmp/mysql_upgrade.trace";
35
46
36
47
static char * * defaults_argv ;
37
48
38
- static File defaults_fd = -1 ;
39
-
40
49
static my_bool not_used ; /* Can't use GET_BOOL without a value pointer */
41
50
42
51
#include <help_start.h>
@@ -105,14 +114,10 @@ static struct my_option my_long_options[]=
105
114
106
115
static void free_used_memory (void )
107
116
{
108
- /* Close the defaults file */
109
- if (defaults_fd != -1 )
110
- my_close (defaults_fd , MYF (0 ));
111
-
112
117
/* Free memory allocated by 'load_defaults' */
113
118
free_defaults (defaults_argv );
114
119
115
- dynstr_free (& ds_options );
120
+ dynstr_free (& ds_args );
116
121
}
117
122
118
123
@@ -159,30 +164,30 @@ static void verbose(const char *fmt, ...)
159
164
160
165
/*
161
166
Add one option - passed to mysql_upgrade on command line
162
- or by defaults file(my.cnf) - to a dynamic string that later
163
- can be written to a temporary file. In this way we pass the
164
- same arguments on to mysql and mysql_check
167
+ or by defaults file(my.cnf) - to a dynamic string, in
168
+ this way we pass the same arguments on to mysql and mysql_check
165
169
*/
166
170
167
171
static void add_one_option (DYNAMIC_STRING * ds ,
168
172
const struct my_option * opt ,
169
173
const char * argument )
170
- {
171
- dynstr_append (ds , opt -> name );
172
174
175
+ {
176
+ const char * eq = NullS ;
177
+ const char * arg = NullS ;
173
178
if (opt -> arg_type != NO_ARG )
174
179
{
175
- dynstr_append ( ds , "=" ) ;
180
+ eq = "=" ;
176
181
switch (opt -> var_type & GET_TYPE_MASK ) {
177
182
case GET_STR :
178
- case GET_STR_ALLOC :
179
- dynstr_append (ds , argument );
183
+ arg = argument ;
180
184
break ;
181
185
default :
182
186
die ("internal error at %s: %d" ,__FILE__ , __LINE__ );
183
187
}
184
188
}
185
- dynstr_append (ds , "\n" );
189
+ dynstr_append_os_quoted (ds , "--" , opt -> name , eq , arg , NullS );
190
+ dynstr_append (& ds_args , " " );
186
191
}
187
192
188
193
@@ -211,8 +216,8 @@ get_one_option(int optid, const struct my_option *opt,
211
216
add_option = FALSE;
212
217
if (argument )
213
218
{
214
- /* Add password to ds_options before overwriting the arg with x's */
215
- add_one_option (& ds_options , opt , argument );
219
+ /* Add password to ds_args before overwriting the arg with x's */
220
+ add_one_option (& ds_args , opt , argument );
216
221
while (* argument )
217
222
* argument ++ = 'x' ; /* Destroy argument */
218
223
tty_password = 0 ;
@@ -232,51 +237,14 @@ get_one_option(int optid, const struct my_option *opt,
232
237
/*
233
238
This is an option that is accpted by mysql_upgrade just so
234
239
it can be passed on to "mysql" and "mysqlcheck"
235
- Save it in the ds_options string
240
+ Save it in the ds_args string
236
241
*/
237
- add_one_option (& ds_options , opt , argument );
242
+ add_one_option (& ds_args , opt , argument );
238
243
}
239
244
return 0 ;
240
245
}
241
246
242
247
243
- /*
244
- Write the options that should be passed on to
245
- mysql and mysqlcheck to a temporary file
246
- */
247
-
248
- static void create_defaults_file (void )
249
- {
250
- static char defaults_file_path [FN_REFLEN ];
251
- DBUG_ENTER ("create_defaults_file" );
252
-
253
- if ((defaults_fd = create_temp_file (defaults_file_path , NULL ,
254
- "cnf" , O_CREAT | O_SHARE ,
255
- MYF (MY_WME ))) < 0 )
256
- die ("Failed to create temporary file for defaults" );
257
-
258
- DBUG_PRINT ("info" , ("Writing options: %s" , ds_options .str ));
259
- if (my_write (defaults_fd , ds_options .str , ds_options .length ,
260
- MYF (MY_FNABP | MY_WME )))
261
- die ("Failed to write to '%s'" , defaults_file_path );
262
-
263
- /*
264
- Dont close the temporary file yet, it will be used
265
- by mysql and mysqlcheck
266
- */
267
-
268
- /*
269
- Create the option that should be added to
270
- tools in order to use this file
271
- */
272
- my_snprintf (defaults_file_option , sizeof (defaults_file_option ),
273
- "--defaults-file=%s" , defaults_file_path );
274
- DBUG_PRINT ("info" , ("defaults_file_option: %s" , defaults_file_option ));
275
-
276
- DBUG_VOID_RETURN ;
277
- }
278
-
279
-
280
248
static int run_command (char * cmd ,
281
249
DYNAMIC_STRING * ds_res )
282
250
{
@@ -466,7 +434,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
466
434
DBUG_ENTER ("run_query" );
467
435
DBUG_PRINT ("enter" , ("query: %s" , query ));
468
436
if ((fd = create_temp_file (query_file_path , NULL ,
469
- "sql" , O_CREAT | O_SHARE ,
437
+ "sql" , O_CREAT | O_SHARE | O_RDWR ,
470
438
MYF (MY_WME ))) < 0 )
471
439
die ("Failed to create temporary file for defaults" );
472
440
@@ -476,7 +444,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
476
444
477
445
ret = run_tool (mysql_path ,
478
446
ds_res ,
479
- defaults_file_option ,
447
+ ds_args . str , // MASV... quoted?
480
448
"--database=mysql" ,
481
449
"--batch" , /* Turns off pager etc. */
482
450
force ? "--force" : "--skip-force" ,
@@ -631,7 +599,7 @@ static int run_mysqlcheck_upgrade(void)
631
599
verbose ("Running 'mysqlcheck'..." );
632
600
return run_tool (mysqlcheck_path ,
633
601
NULL , /* Send output from mysqlcheck directly to screen */
634
- defaults_file_option ,
602
+ ds_args . str ,
635
603
"--check-upgrade" ,
636
604
"--all-databases" ,
637
605
"--auto-repair" ,
@@ -747,7 +715,7 @@ int main(int argc, char **argv)
747
715
setscreenmode (SCR_AUTOCLOSE_ON_EXIT );
748
716
#endif
749
717
750
- if (init_dynamic_string (& ds_options , "[client]\n " , 512 , 256 ))
718
+ if (init_dynamic_string (& ds_args , "" , 512 , 256 ))
751
719
die ("Out of memory" );
752
720
753
721
load_defaults ("my" , load_default_groups , & argc , & argv );
@@ -760,28 +728,19 @@ int main(int argc, char **argv)
760
728
{
761
729
opt_password = get_tty_password (NullS );
762
730
/* add password to defaults file */
763
- dynstr_append (& ds_options , "password=" );
764
- dynstr_append (& ds_options , opt_password );
765
- dynstr_append (& ds_options , "\n" );
731
+ dynstr_append_os_quoted (& ds_args , "--password=" , opt_password , NullS );
732
+ dynstr_append (& ds_args , " " );
766
733
}
767
734
/* add user to defaults file */
768
- dynstr_append (& ds_options , "user=" );
769
- dynstr_append (& ds_options , opt_user );
770
- dynstr_append (& ds_options , "\n" );
735
+ dynstr_append_os_quoted (& ds_args , "--user=" , opt_user , NullS );
736
+ dynstr_append (& ds_args , " " );
771
737
772
738
/* Find mysql */
773
739
find_tool (mysql_path , IF_WIN ("mysql.exe" , "mysql" ));
774
740
775
741
/* Find mysqlcheck */
776
742
find_tool (mysqlcheck_path , IF_WIN ("mysqlcheck.exe" , "mysqlcheck" ));
777
743
778
- /*
779
- Create the defaults file(a small my.cnf) which will pass
780
- all arguments accepted by mysql_upgrade on to mysqlcheck
781
- and mysql command line client
782
- */
783
- create_defaults_file ();
784
-
785
744
/*
786
745
Read the mysql_upgrade_info file to check if mysql_upgrade
787
746
already has been run for this installation of MySQL
0 commit comments