diff options
author | Alexey Botchkov <holyfoot@mysql.com> | 2008-10-27 13:57:59 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@mysql.com> | 2008-10-27 13:57:59 +0400 |
commit | be66e43dabe2681705a9adfe3d385496dc827882 (patch) | |
tree | aa7b899c121b6572fb65f716fb71cddc27f7136c /mysys | |
parent | b6704027d681a80be03d416e9c9c344d86a562dd (diff) | |
download | mariadb-git-be66e43dabe2681705a9adfe3d385496dc827882.tar.gz |
Bug#39289 libmysqld.a calls exit() upon error
Several functions (mostly in mysqld.cc) directly call
exit() function in case of errors, which is not a desired
behaviour expecially in the embedded-server library.
Fixed by making these functions return error sign instead
of exiting.
per-file comments:
include/my_getopt.h
Bug#39289 libmysqld.a calls exit() upon error
added 'error' retvalue for my_getopt_register_get_addr
libmysqld/lib_sql.cc
Bug#39289 libmysqld.a calls exit() upon error
unireg_clear() function implemented
mysys/default.c
Bug#39289 libmysqld.a calls exit() upon error
error returned instead of exit() call
mysys/mf_tempdir.c
Bug#39289 libmysqld.a calls exit() upon error
free_tmpdir() - fixed so it's not produce crash on uninitialized
tmpdir structure
mysys/my_getopt.c
Bug#39289 libmysqld.a calls exit() upon error
error returned instead of exit() call
sql/mysql_priv.h
Bug#39289 libmysqld.a calls exit() upon error
unireg_abort definition fixed for the embedded server
sql/mysqld.cc
Bug#39289 libmysqld.a calls exit() upon error
various functions fixed
error returned instead of exit() call
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/default.c | 10 | ||||
-rw-r--r-- | mysys/mf_tempdir.c | 7 | ||||
-rw-r--r-- | mysys/my_getopt.c | 33 |
3 files changed, 31 insertions, 19 deletions
diff --git a/mysys/default.c b/mysys/default.c index 6b2b31d43ec..c7e1e513e1e 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -144,6 +144,7 @@ static char *remove_end_comment(char *ptr); RETURN 0 ok 1 given cinf_file doesn't exist + 2 out of memory The global variable 'my_defaults_group_suffix' is updated with value for --defaults_group_suffix @@ -190,7 +191,7 @@ int my_search_option_files(const char *conf_file, int *argc, char ***argv, if (!(extra_groups= (const char**)alloc_root(ctx->alloc, (2*group->count+1)*sizeof(char*)))) - goto err; + DBUG_RETURN(2); for (i= 0; i < group->count; i++) { @@ -199,7 +200,7 @@ int my_search_option_files(const char *conf_file, int *argc, char ***argv, len= strlen(extra_groups[i]); if (!(ptr= alloc_root(ctx->alloc, len+instance_len+1))) - goto err; + DBUG_RETURN(2); extra_groups[i+group->count]= ptr; @@ -254,12 +255,11 @@ int my_search_option_files(const char *conf_file, int *argc, char ***argv, } } - DBUG_RETURN(error); + DBUG_RETURN(0); err: fprintf(stderr,"Fatal error in defaults handling. Program aborted\n"); - exit(1); - return 0; /* Keep compiler happy */ + DBUG_RETURN(1); } diff --git a/mysys/mf_tempdir.c b/mysys/mf_tempdir.c index b2c18c74347..6ad0f95a342 100644 --- a/mysys/mf_tempdir.c +++ b/mysys/mf_tempdir.c @@ -85,8 +85,11 @@ char *my_tmpdir(MY_TMPDIR *tmpdir) void free_tmpdir(MY_TMPDIR *tmpdir) { uint i; - for (i=0; i<=tmpdir->max; i++) - my_free(tmpdir->list[i], MYF(0)); + if (tmpdir->full_list.elements) + { + for (i=0; i<=tmpdir->max; i++) + my_free(tmpdir->list[i], MYF(0)); + } delete_dynamic(&tmpdir->full_list); pthread_mutex_destroy(&tmpdir->mutex); } diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 6a7ee748930..5c7e3ecef34 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -100,10 +100,10 @@ static void default_reporter(enum loglevel level, one. Call function 'get_one_option()' once for each option. */ -static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *); +static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *, int *); void my_getopt_register_get_addr(uchar** (*func_addr)(const char *, uint, - const struct my_option *)) + const struct my_option *, int *)) { getopt_get_addr= func_addr; } @@ -362,8 +362,12 @@ int handle_options(int *argc, char ***argv, my_progname, optp->name); return EXIT_NO_ARGUMENT_ALLOWED; } + error= 0; value= optp->var_type & GET_ASK_ADDR ? - (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp) : optp->value; + (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp, &error) : + optp->value; + if (error) + return error; if (optp->arg_type == NO_ARG) { @@ -397,9 +401,10 @@ invalid value '%s'", my_progname, optp->name, optend); continue; } - get_one_option(optp->id, optp, - *((my_bool*) value) ? - (char*) "1" : disabled_my_option); + if (get_one_option(optp->id, optp, + *((my_bool*) value) ? + (char*) "1" : disabled_my_option)) + return EXIT_UNSPECIFIED_ERROR; continue; } argument= optend; @@ -457,7 +462,8 @@ invalid value '%s'", optp->arg_type == NO_ARG) { *((my_bool*) optp->value)= (my_bool) 1; - get_one_option(optp->id, optp, argument); + if (get_one_option(optp->id, optp, argument)) + return EXIT_UNSPECIFIED_ERROR; continue; } else if (optp->arg_type == REQUIRED_ARG || @@ -476,7 +482,8 @@ invalid value '%s'", { if (optp->var_type == GET_BOOL) *((my_bool*) optp->value)= (my_bool) 1; - get_one_option(optp->id, optp, argument); + if (get_one_option(optp->id, optp, argument)) + return EXIT_UNSPECIFIED_ERROR; continue; } /* Check if there are more arguments after this one */ @@ -501,7 +508,8 @@ invalid value '%s'", my_progname, argument, optp->name); return error; } - get_one_option(optp->id, optp, argument); + if (get_one_option(optp->id, optp, argument)) + return EXIT_UNSPECIFIED_ERROR; break; } } @@ -524,7 +532,8 @@ invalid value '%s'", my_progname, argument, optp->name); return error; } - get_one_option(optp->id, optp, argument); + if (get_one_option(optp->id, optp, argument)) + return EXIT_UNSPECIFIED_ERROR; (*argc)--; /* option handled (short or long), decrease argument count */ } @@ -1085,7 +1094,7 @@ static void init_variables(const struct my_option *options, if (options->value) init_one_value(options, options->value, options->def_value); if (options->var_type & GET_ASK_ADDR && - (variable= (*getopt_get_addr)("", 0, options))) + (variable= (*getopt_get_addr)("", 0, options, 0))) init_one_value(options, variable, options->def_value); } DBUG_VOID_RETURN; @@ -1189,7 +1198,7 @@ void my_print_variables(const struct my_option *options) for (optp= options; optp->id; optp++) { uchar* *value= (optp->var_type & GET_ASK_ADDR ? - (*getopt_get_addr)("", 0, optp) : optp->value); + (*getopt_get_addr)("", 0, optp, 0) : optp->value); if (value) { printf("%s ", optp->name); |