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
extern const char *my_defaults_extra_file;
extern const char *my_defaults_group_suffix;
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 my_load_defaults(const char *conf_file, const char **groups,
......
......@@ -43,38 +43,16 @@
#include <winbase.h>
#endif
/**
arguments separator
load_defaults() loads arguments from config file and put them
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
/*
Mark file names in argv[]. File marker is *always* followed by a file name
All options after it come from that file.
Empty file name ("") means command line.
*/
static char *args_separator= (char*)"----args-separator----";
my_bool my_getopt_use_args_separator= FALSE;
my_bool my_getopt_is_args_separator(const char* arg)
static char *file_marker= (char*)"----file-marker----";
my_bool my_defaults_mark_files= FALSE;
my_bool is_file_marker(const char* arg)
{
return (arg == args_separator);
return arg == file_marker;
}
my_bool my_no_defaults=FALSE, my_print_defaults= FALSE;
......@@ -335,7 +313,7 @@ int get_defaults_options(char **argv)
if (*argv && !strcmp(*argv, "--print-defaults"))
{
my_print_defaults= 1;
my_getopt_use_args_separator= FALSE;
my_defaults_mark_files= FALSE;
argv++;
}
......@@ -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 */
memcpy(res, args.buffer, args.elements * sizeof(char*));
if (my_getopt_use_args_separator)
res[args.elements++]= args_separator;
if (my_defaults_mark_files)
{
res[args.elements++]= file_marker;
res[args.elements++]= (char*)"";
}
if (*argc)
memcpy(res + args.elements, *argv, *argc * sizeof(char*));
......@@ -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))))
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))
{
line++;
......
......@@ -24,7 +24,7 @@
#include <my_getopt.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,
longlong value);
......@@ -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,
option_is_loose, option_is_autoset;
char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN];
char *filename= (char*)"";
const char *UNINIT_VAR(prev_found);
const struct my_option *optp;
void *value;
......@@ -207,34 +208,29 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts,
(*argv)++; /* --- || ---- */
init_variables(longopts, init_one_value);
/*
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;
}
}
is_cmdline_arg= !is_file_marker(**argv);
for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
{
char **first= pos;
char *cur_arg= *pos;
opt_found= 0;
if (!is_cmdline_arg && (my_getopt_is_args_separator(cur_arg)))
if (!is_cmdline_arg)
{
is_cmdline_arg= 1;
/* save the separator too if skip unknown options */
if (my_getopt_skip_unknown)
(*argv)[argvpos++]= cur_arg;
else
(*argc)--;
continue;
if (is_file_marker(cur_arg))
{
pos++;
filename= *pos;
is_cmdline_arg= *filename == 0; /* empty file name = command line */
if (my_getopt_skip_unknown)
{
(*argv)[argvpos++]= cur_arg;
(*argv)[argvpos++]= filename;
}
else
(*argc)-= 2;
continue;
}
}
if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */
{
......
......@@ -5348,7 +5348,7 @@ int mysqld_main(int argc, char **argv)
orig_argc= argc;
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);
defaults_argc= argc;
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