summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/mysql.cc6
-rw-r--r--client/mysql_upgrade.c6
-rw-r--r--client/mysqladmin.cc7
-rw-r--r--client/mysqlbinlog.cc4
-rw-r--r--client/mysqlcheck.c5
-rw-r--r--client/mysqldump.c3
-rw-r--r--client/mysqlimport.c3
-rw-r--r--client/mysqlshow.c3
-rw-r--r--client/mysqlslap.c6
-rw-r--r--client/mysqltest.cc4
-rw-r--r--extra/mariabackup/xbcloud.cc4
-rw-r--r--extra/mariabackup/xtrabackup.cc12
-rw-r--r--extra/my_print_defaults.c6
-rw-r--r--include/my_default.h7
-rw-r--r--mysys/my_default.c4
-rw-r--r--sql/mysqld.cc3
-rw-r--r--sql/tztime.cc4
-rw-r--r--storage/archive/archive_reader.c3
-rw-r--r--storage/maria/maria_chk.c2
-rw-r--r--storage/maria/maria_dump_log.c2
-rw-r--r--storage/maria/maria_pack.c2
-rw-r--r--storage/maria/maria_read_log.c2
-rw-r--r--storage/maria/unittest/ma_test_loghandler_multigroup-t.c2
-rw-r--r--storage/myisam/myisamchk.c4
-rw-r--r--storage/myisam/myisampack.c4
-rw-r--r--tests/mysql_client_fw.c3
-rw-r--r--tests/mysql_client_test.c13
-rw-r--r--tests/thread_test.c4
28 files changed, 45 insertions, 83 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 7973c3c7fc3..0b8be00c542 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -1175,11 +1175,7 @@ int main(int argc,char *argv[])
close(stdout_fileno_copy); /* Clean up dup(). */
}
- if (load_defaults("my",load_default_groups,&argc,&argv))
- {
- my_end(0);
- exit(1);
- }
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
defaults_argv=argv;
if ((status.exit_status= get_options(argc, (char **) argv)))
mysql_end(-1);
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
index cbdd398c1e1..5eb495774ce 100644
--- a/client/mysql_upgrade.c
+++ b/client/mysql_upgrade.c
@@ -1133,6 +1133,8 @@ int main(int argc, char **argv)
char self_name[FN_REFLEN + 1];
MY_INIT(argv[0]);
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
+ defaults_argv= argv; /* Must be freed by 'free_defaults' */
#if __WIN__
if (GetModuleFileName(NULL, self_name, FN_REFLEN) == 0)
@@ -1145,10 +1147,6 @@ int main(int argc, char **argv)
init_dynamic_string(&conn_args, "", 512, 256))
die("Out of memory");
- if (load_defaults("my", load_default_groups, &argc, &argv))
- die(NULL);
- defaults_argv= argv; /* Must be freed by 'free_defaults' */
-
if (handle_options(&argc, &argv, my_long_options, get_one_option))
die(NULL);
if (debug_info_flag)
diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc
index 897c2eb41c3..d4d40b0a0f2 100644
--- a/client/mysqladmin.cc
+++ b/client/mysqladmin.cc
@@ -319,8 +319,7 @@ int main(int argc,char *argv[])
MY_INIT(argv[0]);
mysql_init(&mysql);
sf_leaking_memory=1; /* don't report memory leaks on early exits */
- if ((error= load_defaults("my",load_default_groups,&argc,&argv)))
- goto err1;
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
save_argv = argv; /* Save for free_defaults */
if ((error=handle_options(&argc, &argv, my_long_options, get_one_option)))
@@ -500,10 +499,8 @@ err2:
my_free(shared_memory_base_name);
#endif
free_defaults(save_argv);
-err1:
my_end(my_end_arg);
- exit(error);
- return 0;
+ return error;
}
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index b871a70ef01..9753125dd67 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -2666,9 +2666,7 @@ int main(int argc, char** argv)
tzset(); // set tzname
init_alloc_root(&s_mem_root, 16384, 0, MYF(0));
- if (load_defaults("my", load_groups, &argc, &argv))
- exit(1);
-
+ load_defaults_or_exit("my", load_groups, &argc, &argv);
defaults_argv= argv;
if (!(binlog_filter= new Rpl_filter))
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index 47cb38751eb..a4410eba8aa 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -1165,9 +1165,7 @@ int main(int argc, char **argv)
/*
** Check out the args
*/
- if (load_defaults("my", load_default_groups, &argc, &argv))
- goto end2;
-
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
defaults_argv= argv;
if (get_options(&argc, &argv))
goto end1;
@@ -1243,7 +1241,6 @@ int main(int argc, char **argv)
my_free(shared_memory_base_name);
mysql_library_end();
free_defaults(defaults_argv);
- end2:
my_end(my_end_arg);
return ret;
} /* main */
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 5c0ec2a5510..d2348284e31 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -976,8 +976,7 @@ static int get_options(int *argc, char ***argv)
opt_net_buffer_length= *mysql_params->p_net_buffer_length;
md_result_file= stdout;
- if (load_defaults("my",load_default_groups,argc,argv))
- return 1;
+ load_defaults_or_exit("my", load_default_groups, argc, argv);
defaults_argv= *argv;
if (my_hash_init(&ignore_table, charset_info, 16, 0, 0,
diff --git a/client/mysqlimport.c b/client/mysqlimport.c
index 9c84d4a62a6..a9c24e20b0a 100644
--- a/client/mysqlimport.c
+++ b/client/mysqlimport.c
@@ -641,8 +641,7 @@ int main(int argc, char **argv)
MY_INIT(argv[0]);
sf_leaking_memory=1; /* don't report memory leaks on early exits */
- if (load_defaults("my",load_default_groups,&argc,&argv))
- return 1;
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
/* argv is changed in the program */
argv_to_free= argv;
if (get_options(&argc, &argv))
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index f851c15106e..95ee8d697f3 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -71,8 +71,7 @@ int main(int argc, char **argv)
static char **defaults_argv;
MY_INIT(argv[0]);
sf_leaking_memory=1; /* don't report memory leaks on early exits */
- if (load_defaults("my",load_default_groups,&argc,&argv))
- exit(1);
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
defaults_argv=argv;
get_options(&argc,&argv);
diff --git a/client/mysqlslap.c b/client/mysqlslap.c
index 6a0b214305c..0b88a969bc5 100644
--- a/client/mysqlslap.c
+++ b/client/mysqlslap.c
@@ -325,11 +325,7 @@ int main(int argc, char **argv)
MY_INIT(argv[0]);
sf_leaking_memory=1; /* don't report memory leaks on early exits */
- if (load_defaults("my",load_default_groups,&argc,&argv))
- {
- my_end(0);
- exit(1);
- }
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
defaults_argv=argv;
if (get_options(&argc,&argv))
{
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 2897555da3f..895c837f68b 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -7299,9 +7299,7 @@ get_one_option(int optid, const struct my_option *opt, char *argument)
int parse_args(int argc, char **argv)
{
- if (load_defaults("my",load_default_groups,&argc,&argv))
- exit(1);
-
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
default_argv= argv;
if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
diff --git a/extra/mariabackup/xbcloud.cc b/extra/mariabackup/xbcloud.cc
index 56661b03dd0..878b4c81023 100644
--- a/extra/mariabackup/xbcloud.cc
+++ b/extra/mariabackup/xbcloud.cc
@@ -443,9 +443,7 @@ int parse_args(int argc, char **argv)
exit(EXIT_FAILURE);
}
- if (load_defaults("my", load_default_groups, &argc, &argv)) {
- exit(EXIT_FAILURE);
- }
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
if (handle_options(&argc, &argv, my_long_options, get_one_option)) {
exit(EXIT_FAILURE);
diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc
index 2228e542dc7..44214b0c207 100644
--- a/extra/mariabackup/xtrabackup.cc
+++ b/extra/mariabackup/xtrabackup.cc
@@ -6350,10 +6350,8 @@ handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
*argv_client = argv;
*argv_server = argv;
- if (load_defaults(conf_file, xb_server_default_groups,
- &argc_server, argv_server)) {
- exit(EXIT_FAILURE);
- }
+ load_defaults_or_exit(conf_file, xb_server_default_groups,
+ &argc_server, argv_server);
int n;
for (n = 0; (*argv_server)[n]; n++) {};
@@ -6403,10 +6401,8 @@ handle_options(int argc, char **argv, char ***argv_client, char ***argv_server)
xb_server_options, xb_get_one_option)))
exit(ho_error);
- if (load_defaults(conf_file, xb_client_default_groups,
- &argc_client, argv_client)) {
- exit(EXIT_FAILURE);
- }
+ load_defaults_or_exit(conf_file, xb_client_default_groups,
+ &argc_client, argv_client);
for (n = 0; (*argv_client)[n]; n++) {};
argc_client = n;
diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c
index 78940e02ca4..07c95a79ddc 100644
--- a/extra/my_print_defaults.c
+++ b/extra/my_print_defaults.c
@@ -206,6 +206,9 @@ int main(int argc, char **argv)
if ((error= load_defaults(config_file, (const char **) load_default_groups,
&count, &arguments)))
{
+ my_end(0);
+ if (error == 4)
+ return 0;
if (verbose && opt_defaults_file_used)
{
if (error == 1)
@@ -216,8 +219,7 @@ int main(int argc, char **argv)
fprintf(stderr, "WARNING: Defaults file '%s' is not a regular file!\n",
config_file);
}
- error= 2;
- exit(error);
+ return 2;
}
for (argument= arguments+1 ; *argument ; argument++)
diff --git a/include/my_default.h b/include/my_default.h
index 0ed94b09492..bd3a21f03a8 100644
--- a/include/my_default.h
+++ b/include/my_default.h
@@ -45,6 +45,13 @@ extern void free_defaults(char **argv);
extern void my_print_default_files(const char *conf_file);
extern void print_defaults(const char *conf_file, const char **groups);
+
+/** Simplify load_defaults() common use */
+#define load_defaults_or_exit(A, B, C, D) switch (load_defaults(A, B, C, D)) { \
+ case 0: break; \
+ case 4: my_end(0); exit(0); \
+ default: my_end(0); exit(1); }
+
C_MODE_END
#endif /* MY_DEFAULT_INCLUDED */
diff --git a/mysys/my_default.c b/mysys/my_default.c
index 2358aed8f3b..9209c6869fc 100644
--- a/mysys/my_default.c
+++ b/mysys/my_default.c
@@ -631,7 +631,7 @@ int my_load_defaults(const char *conf_file, const char **groups,
if (!my_getopt_is_args_separator((*argv)[i])) /* skip arguments separator */
printf("%s ", (*argv)[i]);
puts("");
- exit(0);
+ DBUG_RETURN(4);
}
if (default_directories)
@@ -641,7 +641,7 @@ int my_load_defaults(const char *conf_file, const char **groups,
err:
fprintf(stderr,"Fatal error in defaults handling. Program aborted\n");
- return 2;
+ DBUG_RETURN(2);
}
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 3cb8e41f94e..4f57d6d1910 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -5511,8 +5511,7 @@ int mysqld_main(int argc, char **argv)
orig_argc= argc;
orig_argv= argv;
my_getopt_use_args_separator= TRUE;
- if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv))
- return 1;
+ load_defaults_or_exit(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv);
my_getopt_use_args_separator= FALSE;
defaults_argc= argc;
defaults_argv= argv;
diff --git a/sql/tztime.cc b/sql/tztime.cc
index bed5f416f13..7df2ad7d0e8 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -2689,9 +2689,7 @@ main(int argc, char **argv)
char **default_argv;
MY_INIT(argv[0]);
- if (load_defaults("my",load_default_groups,&argc,&argv))
- exit(1);
-
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
default_argv= argv;
if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
diff --git a/storage/archive/archive_reader.c b/storage/archive/archive_reader.c
index 1b15fa16ce4..e87bc70ade4 100644
--- a/storage/archive/archive_reader.c
+++ b/storage/archive/archive_reader.c
@@ -408,8 +408,7 @@ static void print_version(void)
static void get_options(int *argc, char ***argv)
{
- if (load_defaults("my", load_default_groups, argc, argv))
- exit(1);
+ load_defaults_or_exit("my", load_default_groups, argc, argv);
default_argv= *argv;
handle_options(argc, argv, my_long_options, get_one_option);
diff --git a/storage/maria/maria_chk.c b/storage/maria/maria_chk.c
index aa01f4cd895..b47f1b8c824 100644
--- a/storage/maria/maria_chk.c
+++ b/storage/maria/maria_chk.c
@@ -895,7 +895,7 @@ static void get_options(register int *argc,register char ***argv)
{
int ho_error;
- load_defaults("my", load_default_groups, argc, argv);
+ load_defaults_or_exit("my", load_default_groups, argc, argv);
default_argv= *argv;
check_param.testflag= T_UPDATE_STATE;
if (isatty(fileno(stdout)))
diff --git a/storage/maria/maria_dump_log.c b/storage/maria/maria_dump_log.c
index 42c694bf1bf..3570dede80e 100644
--- a/storage/maria/maria_dump_log.c
+++ b/storage/maria/maria_dump_log.c
@@ -133,7 +133,7 @@ int main(int argc, char **argv)
uchar buffer[TRANSLOG_PAGE_SIZE];
MY_INIT(argv[0]);
- load_defaults("my", load_default_groups, &argc, &argv);
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
default_argv= argv;
get_options(&argc, &argv);
diff --git a/storage/maria/maria_pack.c b/storage/maria/maria_pack.c
index 814c50e1db8..28b4ff4cfc7 100644
--- a/storage/maria/maria_pack.c
+++ b/storage/maria/maria_pack.c
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
char **default_argv;
MY_INIT(argv[0]);
- load_defaults("my",load_default_groups,&argc,&argv);
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
default_argv= argv;
get_options(&argc,&argv);
maria_init();
diff --git a/storage/maria/maria_read_log.c b/storage/maria/maria_read_log.c
index a0724b2199b..d0cf7521e9b 100644
--- a/storage/maria/maria_read_log.c
+++ b/storage/maria/maria_read_log.c
@@ -47,7 +47,7 @@ int main(int argc, char **argv)
maria_data_root= (char *)".";
sf_leaking_memory=1; /* don't report memory leaks on early exits */
- load_defaults("my", load_default_groups, &argc, &argv);
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
default_argv= argv;
get_options(&argc, &argv);
diff --git a/storage/maria/unittest/ma_test_loghandler_multigroup-t.c b/storage/maria/unittest/ma_test_loghandler_multigroup-t.c
index 1ea31d228e1..dc7e0c79f87 100644
--- a/storage/maria/unittest/ma_test_loghandler_multigroup-t.c
+++ b/storage/maria/unittest/ma_test_loghandler_multigroup-t.c
@@ -256,7 +256,7 @@ int main(int argc __attribute__((unused)), char *argv[])
#endif
long_buffer= malloc(LONG_BUFFER_SIZE + LSN_STORE_SIZE * 2 + 2);
- load_defaults("my", load_default_groups, &argc, &argv);
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
default_argv= argv;
get_options(&argc, &argv);
diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c
index edbe235e190..dfff5720847 100644
--- a/storage/myisam/myisamchk.c
+++ b/storage/myisam/myisamchk.c
@@ -753,9 +753,7 @@ static void get_options(register int *argc,register char ***argv)
{
int ho_error;
- if (load_defaults("my", load_default_groups, argc, argv))
- exit(1);
-
+ load_defaults_or_exit("my", load_default_groups, argc, argv);
default_argv= *argv;
if (isatty(fileno(stdout)))
check_param.testflag|=T_WRITE_LOOP;
diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c
index 966edc877cd..bb9f59f86f7 100644
--- a/storage/myisam/myisampack.c
+++ b/storage/myisam/myisampack.c
@@ -209,9 +209,7 @@ int main(int argc, char **argv)
char **default_argv;
MY_INIT(argv[0]);
- if (load_defaults("my",load_default_groups,&argc,&argv))
- exit(1);
-
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
default_argv= argv;
get_options(&argc,&argv);
diff --git a/tests/mysql_client_fw.c b/tests/mysql_client_fw.c
index b7211989f1f..71fb3894b3c 100644
--- a/tests/mysql_client_fw.c
+++ b/tests/mysql_client_fw.c
@@ -1409,8 +1409,7 @@ int main(int argc, char **argv)
for (i= 0; i < argc; i++)
original_argv[i]= strdup(argv[i]);
- if (load_defaults("my", client_test_load_default_groups, &argc, &argv))
- exit(1);
+ load_defaults_or_exit("my", client_test_load_default_groups, &argc, &argv);
get_options(&argc, &argv);
/* Set main opt_count. */
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index c367e7ca35d..b63bcbaa037 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -7095,11 +7095,7 @@ static void test_embedded_start_stop()
MY_INIT(argv[0]);
/* Load the client defaults from the .cnf file[s]. */
- if (load_defaults("my", client_test_load_default_groups, &argc, &argv))
- {
- myerror("load_defaults failed");
- exit(1);
- }
+ load_defaults_or_exit("my", client_test_load_default_groups, &argc, &argv);
/* Parse the options (including the ones given from defaults files). */
get_options(&argc, &argv);
@@ -7147,12 +7143,7 @@ static void test_embedded_start_stop()
MY_INIT(argv[0]);
- if (load_defaults("my", client_test_load_default_groups, &argc, &argv))
- {
- myerror("load_defaults failed \n ");
- exit(1);
- }
-
+ load_defaults_or_exit("my", client_test_load_default_groups, &argc, &argv);
get_options(&argc, &argv);
/* Must start the main embedded server again after the test. */
diff --git a/tests/thread_test.c b/tests/thread_test.c
index bf0fb8ea2c0..38e453e9cb8 100644
--- a/tests/thread_test.c
+++ b/tests/thread_test.c
@@ -168,8 +168,8 @@ static void get_options(int argc, char **argv)
{
int ho_error;
- if ((ho_error= load_defaults("my",load_default_groups,&argc,&argv)) ||
- (ho_error= handle_options(&argc, &argv, my_long_options, get_one_option)))
+ load_defaults_or_exit("my", load_default_groups, &argc, &argv);
+ if ((ho_error= handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
free_defaults(argv);