Commit 927521a2 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-12684 Show what config file a sysvar got a value from

make load_defaults() store the file name in the generated option list
using a special marker ---file-marker--- option.

Pick up this filename in handle_options().

Remove ---args-separator---, use ---file-marker--- with an empty file
name instead - this simplifies checks on the caller, only one special
option to recognize.
parent f7b8d144
...@@ -23,7 +23,7 @@ C_MODE_START ...@@ -23,7 +23,7 @@ C_MODE_START
extern const char *my_defaults_extra_file; extern const char *my_defaults_extra_file;
extern const char *my_defaults_group_suffix; extern const char *my_defaults_group_suffix;
extern const char *my_defaults_file; extern const char *my_defaults_file;
extern my_bool my_getopt_use_args_separator; extern my_bool my_defaults_mark_files;
extern int get_defaults_options(char **argv); extern int get_defaults_options(char **argv);
extern int my_load_defaults(const char *conf_file, const char **groups, extern int my_load_defaults(const char *conf_file, const char **groups,
......
...@@ -43,38 +43,16 @@ ...@@ -43,38 +43,16 @@
#include <winbase.h> #include <winbase.h>
#endif #endif
/** /*
arguments separator Mark file names in argv[]. File marker is *always* followed by a file name
All options after it come from that file.
load_defaults() loads arguments from config file and put them Empty file name ("") means command line.
before the arguments from command line, this separator is used to
separate the arguments loaded from config file and arguments user
provided on command line.
Options with value loaded from config file are always in the form
'--option=value', while for command line options, the value can be
given as the next argument. Thus we used a separator so that
handle_options() can distinguish them.
Note: any other places that does not need to distinguish them
should skip the separator.
The content of arguments separator does not matter, one should only
check the pointer, use "----args-separator----" here to ease debug
if someone misused it.
The args separator will only be added when
my_getopt_use_args_seprator is set to TRUE before calling
load_defaults();
See BUG#25192
*/ */
static char *file_marker= (char*)"----file-marker----";
static char *args_separator= (char*)"----args-separator----"; my_bool my_defaults_mark_files= FALSE;
my_bool my_getopt_use_args_separator= FALSE; my_bool is_file_marker(const char* arg)
my_bool my_getopt_is_args_separator(const char* arg)
{ {
return (arg == args_separator); return arg == file_marker;
} }
my_bool my_no_defaults=FALSE, my_print_defaults= FALSE; my_bool my_no_defaults=FALSE, my_print_defaults= FALSE;
...@@ -335,7 +313,7 @@ int get_defaults_options(char **argv) ...@@ -335,7 +313,7 @@ int get_defaults_options(char **argv)
if (*argv && !strcmp(*argv, "--print-defaults")) if (*argv && !strcmp(*argv, "--print-defaults"))
{ {
my_print_defaults= 1; my_print_defaults= 1;
my_getopt_use_args_separator= FALSE; my_defaults_mark_files= FALSE;
argv++; argv++;
} }
...@@ -483,8 +461,11 @@ int my_load_defaults(const char *conf_file, const char **groups, int *argc, ...@@ -483,8 +461,11 @@ int my_load_defaults(const char *conf_file, const char **groups, int *argc,
/* found arguments + command line arguments to new array */ /* found arguments + command line arguments to new array */
memcpy(res, args.buffer, args.elements * sizeof(char*)); memcpy(res, args.buffer, args.elements * sizeof(char*));
if (my_getopt_use_args_separator) if (my_defaults_mark_files)
res[args.elements++]= args_separator; {
res[args.elements++]= file_marker;
res[args.elements++]= (char*)"";
}
if (*argc) if (*argc)
memcpy(res + args.elements, *argv, *argc * sizeof(char*)); memcpy(res + args.elements, *argv, *argc * sizeof(char*));
...@@ -665,6 +646,11 @@ static int search_default_file_with_ext(struct handle_option_ctx *ctx, ...@@ -665,6 +646,11 @@ static int search_default_file_with_ext(struct handle_option_ctx *ctx,
if (!(fp= mysql_file_fopen(key_file_cnf, name, O_RDONLY, MYF(0)))) if (!(fp= mysql_file_fopen(key_file_cnf, name, O_RDONLY, MYF(0))))
return 1; /* Ignore wrong files */ return 1; /* Ignore wrong files */
if (my_defaults_mark_files)
if (insert_dynamic(ctx->args, (uchar*) &file_marker) ||
add_option(ctx, name))
goto err;
while (mysql_file_fgets(buff, sizeof(buff) - 1, fp)) while (mysql_file_fgets(buff, sizeof(buff) - 1, fp))
{ {
line++; line++;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <my_getopt.h> #include <my_getopt.h>
#include <errno.h> #include <errno.h>
my_bool my_getopt_is_args_separator(const char* arg); my_bool is_file_marker(const char* arg);
typedef void (*init_func_p)(const struct my_option *option, void *variable, typedef void (*init_func_p)(const struct my_option *option, void *variable,
longlong value); longlong value);
...@@ -193,6 +193,7 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts, ...@@ -193,6 +193,7 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts,
my_bool end_of_options= 0, must_be_var, set_maximum_value, my_bool end_of_options= 0, must_be_var, set_maximum_value,
option_is_loose, option_is_autoset; option_is_loose, option_is_autoset;
char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN]; char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN];
char *filename= (char*)"";
const char *UNINIT_VAR(prev_found); const char *UNINIT_VAR(prev_found);
const struct my_option *optp; const struct my_option *optp;
void *value; void *value;
...@@ -207,34 +208,29 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts, ...@@ -207,34 +208,29 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts,
(*argv)++; /* --- || ---- */ (*argv)++; /* --- || ---- */
init_variables(longopts, init_one_value); init_variables(longopts, init_one_value);
/* is_cmdline_arg= !is_file_marker(**argv);
Search for args_separator, if found, then the first part of the
arguments are loaded from configs
*/
for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
{
if (my_getopt_is_args_separator(*pos))
{
is_cmdline_arg= 0;
break;
}
}
for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++) for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
{ {
char **first= pos; char **first= pos;
char *cur_arg= *pos; char *cur_arg= *pos;
opt_found= 0; opt_found= 0;
if (!is_cmdline_arg && (my_getopt_is_args_separator(cur_arg))) if (!is_cmdline_arg)
{ {
is_cmdline_arg= 1; if (is_file_marker(cur_arg))
{
/* save the separator too if skip unknown options */ pos++;
if (my_getopt_skip_unknown) filename= *pos;
(*argv)[argvpos++]= cur_arg; is_cmdline_arg= *filename == 0; /* empty file name = command line */
else if (my_getopt_skip_unknown)
(*argc)--; {
continue; (*argv)[argvpos++]= cur_arg;
(*argv)[argvpos++]= filename;
}
else
(*argc)-= 2;
continue;
}
} }
if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */ if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */
{ {
......
...@@ -5348,7 +5348,7 @@ int mysqld_main(int argc, char **argv) ...@@ -5348,7 +5348,7 @@ int mysqld_main(int argc, char **argv)
orig_argc= argc; orig_argc= argc;
orig_argv= argv; orig_argv= argv;
my_getopt_use_args_separator= TRUE; my_defaults_mark_files= TRUE;
load_defaults_or_exit(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv); load_defaults_or_exit(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv);
defaults_argc= argc; defaults_argc= argc;
defaults_argv= argv; defaults_argv= argv;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment