@@ -102,35 +102,35 @@ int main(int argc,char *argv[])
102
102
MY_INIT (argv [0 ]);
103
103
sf_leaking_memory = 1 ; /* don't report memory leaks on early exits */
104
104
plugin_data .name = 0 ; /* initialize name */
105
-
105
+
106
106
/*
107
107
The following operations comprise the method for enabling or disabling
108
108
a plugin. We begin by processing the command options then check the
109
109
directories specified for --datadir, --basedir, --plugin-dir, and
110
110
--plugin-ini (if specified). If the directories are Ok, we then look
111
111
for the mysqld executable and the plugin soname. Finally, we build a
112
112
bootstrap command file for use in bootstraping the server.
113
-
113
+
114
114
If any step fails, the method issues an error message and the tool exits.
115
-
115
+
116
116
1) Parse, execute, and verify command options.
117
117
2) Check access to directories.
118
118
3) Look for mysqld executable.
119
119
4) Look for the plugin.
120
120
5) Build a bootstrap file with commands to enable or disable plugin.
121
-
121
+
122
122
*/
123
123
if ((error = process_options (argc , argv , operation )) ||
124
124
(error = check_access ()) ||
125
125
(error = find_tool ("mysqld" FN_EXEEXT , server_path )) ||
126
126
(error = find_plugin (tp_path )) ||
127
127
(error = build_bootstrap_file (operation , bootstrap )))
128
128
goto exit ;
129
-
129
+
130
130
/* Dump the bootstrap file if --verbose specified. */
131
131
if (opt_verbose && ((error = dump_bootstrap_file (bootstrap ))))
132
132
goto exit ;
133
-
133
+
134
134
/* Start the server in bootstrap mode and execute bootstrap commands */
135
135
error = bootstrap_server (server_path , bootstrap );
136
136
@@ -238,7 +238,7 @@ static int run_command(char* cmd, const char *mode)
238
238
#ifdef __WIN__
239
239
/**
240
240
Check to see if there are spaces in a path.
241
-
241
+
242
242
@param[in] path The Windows path to examine.
243
243
244
244
@retval int spaces found = 1, no spaces = 0
@@ -253,7 +253,7 @@ static int has_spaces(const char *path)
253
253
254
254
/**
255
255
Convert a Unix path to a Windows path.
256
-
256
+
257
257
@param[in] path The Windows path to examine.
258
258
259
259
@returns string containing path with / changed to \\
@@ -335,12 +335,12 @@ static int get_default_values()
335
335
#ifdef __WIN__
336
336
{
337
337
char * format_str = 0 ;
338
-
338
+
339
339
if (has_spaces (tool_path ) || has_spaces (defaults_file ))
340
340
format_str = "\"%s --mysqld > %s\"" ;
341
341
else
342
342
format_str = "%s --mysqld > %s" ;
343
-
343
+
344
344
snprintf (defaults_cmd , sizeof (defaults_cmd ), format_str ,
345
345
add_quotes (tool_path ), add_quotes (defaults_file ));
346
346
if (opt_verbose )
@@ -675,7 +675,7 @@ static int load_plugin_data(char *plugin_name, char *config_file)
675
675
{
676
676
reason = "Bad format in plugin configuration file." ;
677
677
fclose (file_ptr );
678
- goto error ;
678
+ goto error ;
679
679
}
680
680
break ;
681
681
}
@@ -709,7 +709,7 @@ static int load_plugin_data(char *plugin_name, char *config_file)
709
709
}
710
710
}
711
711
}
712
-
712
+
713
713
fclose (file_ptr );
714
714
return 0 ;
715
715
@@ -740,7 +740,7 @@ static int check_options(int argc, char **argv, char *operation)
740
740
int num_found = 0 ; /* number of options found (shortcut loop) */
741
741
char config_file [FN_REFLEN ]; /* configuration file name */
742
742
char plugin_name [FN_REFLEN ]; /* plugin name */
743
-
743
+
744
744
/* Form prefix strings for the options. */
745
745
const char * basedir_prefix = "--basedir=" ;
746
746
size_t basedir_len = strlen (basedir_prefix );
@@ -815,7 +815,7 @@ static int check_options(int argc, char **argv, char *operation)
815
815
return 1 ;
816
816
}
817
817
/* If a plugin was specified, read the config file. */
818
- else if (strlen (plugin_name ) > 0 )
818
+ else if (strlen (plugin_name ) > 0 )
819
819
{
820
820
if (load_plugin_data (plugin_name , config_file ))
821
821
{
@@ -847,22 +847,22 @@ static int check_options(int argc, char **argv, char *operation)
847
847
848
848
/**
849
849
Parse, execute, and verify command options.
850
-
850
+
851
851
This method handles all of the option processing including the optional
852
852
features for displaying data (--print-defaults, --help ,etc.) that do not
853
853
result in an attempt to ENABLE or DISABLE of a plugin.
854
-
854
+
855
855
@param[in] arc Count of arguments
856
856
@param[in] argv Array of arguments
857
857
@param[out] operation Operation (ENABLE or DISABLE)
858
-
858
+
859
859
@retval int error = 1, success = 0, exit program = -1
860
860
*/
861
861
862
862
static int process_options (int argc , char * argv [], char * operation )
863
863
{
864
864
int error = 0 ;
865
-
865
+
866
866
/* Parse and execute command-line options */
867
867
if ((error = handle_options (& argc , & argv , my_long_options , get_one_option )))
868
868
return error ;
@@ -881,7 +881,7 @@ static int process_options(int argc, char *argv[], char *operation)
881
881
char buff [FN_REFLEN ];
882
882
if (basedir_len + 2 > FN_REFLEN )
883
883
return -1 ;
884
-
884
+
885
885
memcpy (buff , opt_basedir , basedir_len );
886
886
buff [basedir_len ]= '/' ;
887
887
buff [basedir_len + 1 ]= '\0' ;
@@ -890,7 +890,7 @@ static int process_options(int argc, char *argv[], char *operation)
890
890
opt_basedir = my_strdup (PSI_NOT_INSTRUMENTED , buff , MYF (MY_FAE ));
891
891
}
892
892
}
893
-
893
+
894
894
/*
895
895
If the user did not specify the option to skip loading defaults from a
896
896
config file and the required options are not present or there was an error
@@ -925,18 +925,18 @@ static int process_options(int argc, char *argv[], char *operation)
925
925
926
926
/**
927
927
Check access
928
-
928
+
929
929
This method checks to ensure all of the directories (opt_basedir,
930
930
opt_plugin_dir, opt_datadir, and opt_plugin_ini) are accessible by
931
931
the user.
932
-
932
+
933
933
@retval int error = 1, success = 0
934
934
*/
935
935
936
936
static int check_access ()
937
937
{
938
938
int error = 0 ;
939
-
939
+
940
940
if ((error = my_access (opt_basedir , F_OK )))
941
941
{
942
942
fprintf (stderr , "ERROR: Cannot access basedir at '%s'.\n" ,
@@ -1048,21 +1048,21 @@ static int find_plugin(char *tp_path)
1048
1048
1049
1049
/**
1050
1050
Build the bootstrap file.
1051
-
1051
+
1052
1052
Create a new file and populate it with SQL commands to ENABLE or DISABLE
1053
1053
the plugin via REPLACE and DELETE operations on the mysql.plugin table.
1054
1054
1055
1055
param[in] operation The type of operation (ENABLE or DISABLE)
1056
1056
param[out] bootstrap A FILE* pointer
1057
-
1057
+
1058
1058
@retval int error = 1, success = 0
1059
1059
*/
1060
1060
1061
1061
static int build_bootstrap_file (char * operation , char * bootstrap )
1062
1062
{
1063
1063
int error = 0 ;
1064
1064
FILE * file = 0 ;
1065
-
1065
+
1066
1066
/*
1067
1067
Perform plugin operation : ENABLE or DISABLE
1068
1068
@@ -1073,10 +1073,10 @@ static int build_bootstrap_file(char *operation, char *bootstrap)
1073
1073
<plugin_name>.ini configuration file. Once the file is built, a call to
1074
1074
mysqld is made in read only, bootstrap modes to read the SQL statements
1075
1075
and execute them.
1076
-
1076
+
1077
1077
Note: Replace was used so that if a user loads a newer version of a
1078
1078
library with a different library name, the new library name is
1079
- used for symbols that match.
1079
+ used for symbols that match.
1080
1080
*/
1081
1081
if ((error = make_tempfile (bootstrap , "sql" )))
1082
1082
{
@@ -1123,7 +1123,7 @@ static int build_bootstrap_file(char *operation, char *bootstrap)
1123
1123
printf ("# Disabling %s...\n" , plugin_data .name );
1124
1124
}
1125
1125
}
1126
-
1126
+
1127
1127
exit :
1128
1128
fclose (file );
1129
1129
return error ;
@@ -1132,11 +1132,11 @@ static int build_bootstrap_file(char *operation, char *bootstrap)
1132
1132
1133
1133
/**
1134
1134
Dump bootstrap file.
1135
-
1135
+
1136
1136
Read the contents of the bootstrap file and print it out.
1137
-
1137
+
1138
1138
@param[in] bootstrap_file Name of bootstrap file to read
1139
-
1139
+
1140
1140
@retval int error = 1, success = 0
1141
1141
*/
1142
1142
@@ -1173,7 +1173,7 @@ static int dump_bootstrap_file(char *bootstrap_file)
1173
1173
1174
1174
/**
1175
1175
Bootstrap the server
1176
-
1176
+
1177
1177
Create a command line sequence to launch mysqld in bootstrap mode. This
1178
1178
will allow mysqld to launch a minimal server instance to read and
1179
1179
execute SQL commands from a file piped in (the bootstrap file). We use
@@ -1194,47 +1194,39 @@ static int dump_bootstrap_file(char *bootstrap_file)
1194
1194
1195
1195
static int bootstrap_server (char * server_path , char * bootstrap_file )
1196
1196
{
1197
- char bootstrap_cmd [FN_REFLEN ];
1197
+ char bootstrap_cmd [FN_REFLEN ]= {0 };
1198
+ char lc_messages_dir_str [FN_REFLEN ]= {0 };
1198
1199
int error = 0 ;
1199
1200
1200
1201
#ifdef __WIN__
1201
1202
char * format_str = 0 ;
1202
1203
const char * verbose_str = NULL ;
1203
-
1204
-
1204
+ #endif
1205
+
1206
+ if (opt_lc_messages_dir != NULL )
1207
+ snprintf (lc_messages_dir_str , sizeof (lc_messages_dir_str ), "--lc-messages-dir=%s" ,
1208
+ opt_lc_messages_dir );
1209
+
1210
+ #ifdef __WIN__
1205
1211
if (opt_verbose )
1206
1212
verbose_str = "--console" ;
1207
1213
else
1208
1214
verbose_str = "" ;
1215
+
1209
1216
if (has_spaces (opt_datadir ) || has_spaces (opt_basedir ) ||
1210
- has_spaces (bootstrap_file ))
1211
- {
1212
- if (opt_lc_messages_dir != NULL )
1213
- format_str = "\"%s %s --bootstrap --datadir=%s --basedir=%s --lc-messages-dir=%s <%s\"" ;
1214
- else
1215
- format_str = "\"%s %s --bootstrap --datadir=%s --basedir=%s <%s\"" ;
1216
- }
1217
+ has_spaces (bootstrap_file ) || has_spaces (lc_messages_dir_str ))
1218
+ format_str = "\"%s %s --bootstrap --datadir=%s --basedir=%s %s <%s\"" ;
1217
1219
else
1218
- {
1219
- if (opt_lc_messages_dir != NULL )
1220
- format_str = "\"%s %s --bootstrap --datadir=%s --basedir=%s --lc-messages-dir=%s <%s\"" ;
1221
- else
1222
- format_str = "%s %s --bootstrap --datadir=%s --basedir=%s <%s" ;
1223
- }
1220
+ format_str = "%s %s --bootstrap --datadir=%s --basedir=%s %s <%s" ;
1221
+
1224
1222
snprintf (bootstrap_cmd , sizeof (bootstrap_cmd ), format_str ,
1225
1223
add_quotes (convert_path (server_path )), verbose_str ,
1226
1224
add_quotes (opt_datadir ), add_quotes (opt_basedir ),
1227
- add_quotes (bootstrap_file ));
1225
+ add_quotes (lc_messages_dir_str ), add_quotes ( bootstrap_file ));
1228
1226
#else
1229
- if (opt_lc_messages_dir != NULL )
1230
- snprintf (bootstrap_cmd , sizeof (bootstrap_cmd ),
1231
- "%s --no-defaults --bootstrap --datadir=%s --basedir=%s --lc-messages-dir=%s"
1232
- " <%s" , server_path , opt_datadir , opt_basedir , opt_lc_messages_dir , bootstrap_file );
1233
- else
1234
- snprintf (bootstrap_cmd , sizeof (bootstrap_cmd ),
1235
- "%s --no-defaults --bootstrap --datadir=%s --basedir=%s"
1236
- " <%s" , server_path , opt_datadir , opt_basedir , bootstrap_file );
1237
-
1227
+ snprintf (bootstrap_cmd , sizeof (bootstrap_cmd ),
1228
+ "%s --no-defaults --bootstrap --datadir=%s --basedir=%s %s"
1229
+ " <%s" , server_path , opt_datadir , opt_basedir , lc_messages_dir_str , bootstrap_file );
1238
1230
#endif
1239
1231
1240
1232
/* Execute the command */
@@ -1247,6 +1239,6 @@ static int bootstrap_server(char *server_path, char *bootstrap_file)
1247
1239
fprintf (stderr ,
1248
1240
"ERROR: Unexpected result from bootstrap. Error code: %d.\n" ,
1249
1241
error );
1250
-
1242
+
1251
1243
return error ;
1252
1244
}
0 commit comments