summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2019-09-29 14:48:11 +0200
committerSergei Golubchik <serg@mariadb.org>2019-10-14 10:29:30 +0200
commit927521a2c18954f03869e91281b90af79b719166 (patch)
treec7c0fed839777e15645dccf930fc06841445680c
parentf7b8d1449046a9f36618435c972d7ca8b961b540 (diff)
downloadmariadb-git-927521a2c18954f03869e91281b90af79b719166.tar.gz
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.
-rw-r--r--include/my_default.h2
-rw-r--r--mysys/my_default.c52
-rw-r--r--mysys/my_getopt.c40
-rw-r--r--sql/mysqld.cc2
4 files changed, 39 insertions, 57 deletions
diff --git a/include/my_default.h b/include/my_default.h
index 71de52a40fc..541dd10b3ab 100644
--- a/include/my_default.h
+++ b/include/my_default.h
@@ -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,
diff --git a/mysys/my_default.c b/mysys/my_default.c
index b27ae9670a8..d7e935d578b 100644
--- a/mysys/my_default.c
+++ b/mysys/my_default.c
@@ -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++;
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index fa870405f70..ab85e231c0f 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -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 */
{
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index bea31975866..4fc24c3a7d5 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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;