mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
fix for bug #5920 (embedded-server mysql doesn't handle --defaults-file)
This commit is contained in:
parent
e8e6d0577f
commit
5eb5fd12be
4 changed files with 55 additions and 17 deletions
|
@ -330,6 +330,16 @@ static sig_handler mysql_end(int sig);
|
|||
int main(int argc,char *argv[])
|
||||
{
|
||||
char buff[80];
|
||||
char *defaults, *extra_defaults;
|
||||
char *emb_argv[3];
|
||||
int emb_argc= 1;
|
||||
|
||||
emb_argv[0]= argv[0];
|
||||
get_defaults_files(argc, argv, &defaults, &extra_defaults);
|
||||
if (defaults)
|
||||
emb_argv[emb_argc++]= defaults;
|
||||
if (extra_defaults)
|
||||
emb_argv[emb_argc++]= extra_defaults;
|
||||
|
||||
MY_INIT(argv[0]);
|
||||
DBUG_ENTER("main");
|
||||
|
@ -375,7 +385,7 @@ int main(int argc,char *argv[])
|
|||
my_end(0);
|
||||
exit(1);
|
||||
}
|
||||
if (mysql_server_init(0, NULL, (char**) server_default_groups))
|
||||
if (mysql_server_init(emb_argc, emb_argv, (char**) server_default_groups))
|
||||
{
|
||||
free_defaults(defaults_argv);
|
||||
my_end(0);
|
||||
|
|
|
@ -738,6 +738,8 @@ extern void reset_root_defaults(MEM_ROOT *mem_root, uint block_size,
|
|||
extern char *strdup_root(MEM_ROOT *root,const char *str);
|
||||
extern char *strmake_root(MEM_ROOT *root,const char *str,uint len);
|
||||
extern char *memdup_root(MEM_ROOT *root,const char *str,uint len);
|
||||
extern void get_defaults_files(int argc, char **argv,
|
||||
char **defaults, char **extra_defaults);
|
||||
extern int load_defaults(const char *conf_file, const char **groups,
|
||||
int *argc, char ***argv);
|
||||
extern void free_defaults(char **argv);
|
||||
|
|
|
@ -143,6 +143,9 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
|
|||
db ? db : "(Null)",
|
||||
user ? user : "(Null)"));
|
||||
|
||||
if (!host || !host[0])
|
||||
host= mysql->options.host;
|
||||
|
||||
if (mysql->options.methods_to_use == MYSQL_OPT_USE_REMOTE_CONNECTION ||
|
||||
(mysql->options.methods_to_use == MYSQL_OPT_GUESS_CONNECTION &&
|
||||
host && *host && strcmp(host,LOCAL_HOST)))
|
||||
|
|
|
@ -78,6 +78,36 @@ static int search_default_file_with_ext(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
|
|||
static char *remove_end_comment(char *ptr);
|
||||
|
||||
|
||||
/*
|
||||
Gets --defaults-file and --defaults-extra-file options from command line.
|
||||
|
||||
SYNOPSIS
|
||||
get_defaults_files()
|
||||
argc Pointer to argc of original program
|
||||
argv Pointer to argv of original program
|
||||
defaults --defaults-file option
|
||||
extra_defaults --defaults-extra-file option
|
||||
|
||||
RETURN
|
||||
defaults and extra_defaults will be set to appropriate items
|
||||
of argv array, or to NULL if there are no such options
|
||||
*/
|
||||
|
||||
void get_defaults_files(int argc, char **argv,
|
||||
char **defaults, char **extra_defaults)
|
||||
{
|
||||
*defaults=0;
|
||||
*extra_defaults=0;
|
||||
if (argc >= 2)
|
||||
{
|
||||
if (is_prefix(argv[1],"--defaults-file="))
|
||||
*defaults= argv[1];
|
||||
else if (is_prefix(argv[1],"--defaults-extra-file="))
|
||||
*extra_defaults= argv[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Read options from configurations files
|
||||
|
||||
|
@ -111,7 +141,7 @@ static char *remove_end_comment(char *ptr);
|
|||
|
||||
|
||||
int load_defaults(const char *conf_file, const char **groups,
|
||||
int *argc, char ***argv)
|
||||
int *argc, char ***argv)
|
||||
{
|
||||
DYNAMIC_ARRAY args;
|
||||
const char **dirs, *forced_default_file;
|
||||
|
@ -143,21 +173,14 @@ int load_defaults(const char *conf_file, const char **groups,
|
|||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
/* Check if we want to force the use a specific default file */
|
||||
forced_default_file=0;
|
||||
if (*argc >= 2)
|
||||
{
|
||||
if (is_prefix(argv[0][1],"--defaults-file="))
|
||||
{
|
||||
forced_default_file=strchr(argv[0][1],'=')+1;
|
||||
args_used++;
|
||||
}
|
||||
else if (is_prefix(argv[0][1],"--defaults-extra-file="))
|
||||
{
|
||||
defaults_extra_file=strchr(argv[0][1],'=')+1;
|
||||
args_used++;
|
||||
}
|
||||
}
|
||||
get_defaults_files(*argc, *argv,
|
||||
(char **)&forced_default_file, &defaults_extra_file);
|
||||
if (forced_default_file)
|
||||
forced_default_file= strchr(forced_default_file,'=')+1;
|
||||
if (defaults_extra_file)
|
||||
defaults_extra_file= strchr(defaults_extra_file,'=')+1;
|
||||
|
||||
args_used+= (forced_default_file ? 1 : 0) + (defaults_extra_file ? 1 : 0);
|
||||
|
||||
group.count=0;
|
||||
group.name= "defaults";
|
||||
|
|
Loading…
Reference in a new issue