From 6254fcf84a1722803dc5781901cdcb7df906f2ca Mon Sep 17 00:00:00 2001 From: Monty Date: Sun, 21 Apr 2024 14:29:31 +0300 Subject: [PATCH] Fix that one cannot change value for deleted variables This enasures that the 'variables that only exists for compatibility' are always kept as its default value. Based on an idea from Sergei Golubchik --- include/my_getopt.h | 1 + mysys/my_getopt.c | 11 +++++------ sql/mysqld.cc | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/my_getopt.h b/include/my_getopt.h index 95de005087d..b839baa68ce 100644 --- a/include/my_getopt.h +++ b/include/my_getopt.h @@ -133,6 +133,7 @@ double getopt_double_limit_value(double num, const struct my_option *optp, ulonglong getopt_double2ulonglong(double); double getopt_ulonglong2double(ulonglong); +void my_getopt_init_one_value(const struct my_option *, void *, longlong); static inline void convert_underscore_to_dash(char *str, size_t len) { diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 3fb81b7cad4..7c5648e36d7 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -36,7 +36,6 @@ static longlong getopt_ll(char *arg, const struct my_option *optp, int *err); static ulonglong getopt_ull(char *, const struct my_option *, int *); static double getopt_double(char *arg, const struct my_option *optp, int *err); static void init_variables(const struct my_option *, init_func_p); -static void init_one_value(const struct my_option *, void *, longlong); static void fini_one_value(const struct my_option *, void *, longlong); static int setval(const struct my_option *, void *, char *, my_bool, const char *); static char *check_struct_option(char *cur_arg, char *key_name); @@ -278,7 +277,7 @@ int handle_options(int *argc, char ***argv, const struct my_option *longopts, (*argc)--; /* Skip the program name */ (*argv)++; /* --- || ---- */ if (my_handle_options_init_variables) - init_variables(longopts, init_one_value); + init_variables(longopts, my_getopt_init_one_value); is_cmdline_arg= !is_file_marker(**argv); @@ -1381,13 +1380,13 @@ static double getopt_double(char *arg, const struct my_option *optp, int *err) Init one value to it's default values SYNOPSIS - init_one_value() + my_getopt_init_one_value() option Option to initialize value Pointer to variable */ -static void init_one_value(const struct my_option *option, void *variable, - longlong value) +void my_getopt_init_one_value(const struct my_option *option, void *variable, + longlong value) { DBUG_ENTER("init_one_value"); switch ((option->var_type & GET_TYPE_MASK)) { @@ -1470,7 +1469,7 @@ static void init_one_value(const struct my_option *option, void *variable, Init one value to it's default values SYNOPSIS - init_one_value() + fini_one_value() option Option to initialize value Pointer to variable */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 8e5e9f0e630..f89b512689d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8059,6 +8059,8 @@ mysqld_get_one_option(const struct my_option *opt, const char *argument, case OPT_REMOVED_OPTION: sql_print_warning("'%s' was removed. It does nothing now and exists only " "for compatibility with old my.cnf files.", opt->name); + /* Restore default value (to show that the option cannot be used) */ + my_getopt_init_one_value(opt, opt->value, opt->def_value); break; case OPT_MYSQL_COMPATIBILITY: sql_print_warning("'%s' is MySQL 5.6 / 5.7 compatible option. Not used or "