diff options
author | Alexander Nozdrin <alik@sun.com> | 2009-10-28 10:55:44 +0300 |
---|---|---|
committer | Alexander Nozdrin <alik@sun.com> | 2009-10-28 10:55:44 +0300 |
commit | ac7ba1bcaac891b046ad028e035487da44448eeb (patch) | |
tree | 76a0977cebe3775f61ae3281cc608601eb883243 /mysys | |
parent | f89b2496ffdf96d1d4b32099d38ce0565ac1d93a (diff) | |
parent | 273a0a4f97ea07620675cba1f61e84dd83c21a2f (diff) | |
download | mariadb-git-ac7ba1bcaac891b046ad028e035487da44448eeb.tar.gz |
Merge from mysql-next-mr.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/default.c | 45 | ||||
-rw-r--r-- | mysys/my_getopt.c | 33 | ||||
-rw-r--r-- | mysys/my_handler_errors.h | 3 | ||||
-rw-r--r-- | mysys/my_static.h | 5 |
4 files changed, 76 insertions, 10 deletions
diff --git a/mysys/default.c b/mysys/default.c index 1c021b4584f..6468cf2b35d 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -41,6 +41,29 @@ #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. + + See BUG#25192 +*/ +const char *args_separator= "----args-separator----"; const char *my_defaults_file=0; const char *my_defaults_group_suffix=0; char *my_defaults_extra_file=0; @@ -454,10 +477,11 @@ int my_load_defaults(const char *conf_file, const char **groups, goto err; res= (char**) (ptr+sizeof(alloc)); res[0]= **argv; /* Copy program name */ + /* set arguments separator */ + res[1]= (char *)args_separator; for (i=2 ; i < (uint) *argc ; i++) - res[i-1]=argv[0][i]; - res[i-1]=0; /* End pointer */ - (*argc)--; + res[i]=argv[0][i]; + res[i]=0; /* End pointer */ *argv=res; *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ if (default_directories) @@ -487,7 +511,7 @@ int my_load_defaults(const char *conf_file, const char **groups, or a forced default file */ if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+ - (args.elements + *argc +1) *sizeof(char*)))) + (args.elements + *argc + 1 + 1) *sizeof(char*)))) goto err; res= (char**) (ptr+sizeof(alloc)); @@ -508,12 +532,16 @@ int my_load_defaults(const char *conf_file, const char **groups, --*argc; ++*argv; /* skip argument */ } + /* set arguments separator for arguments from config file and + command line */ + res[args.elements+1]= (char *)args_separator; + if (*argc) - memcpy((uchar*) (res+1+args.elements), (char*) ((*argv)+1), + memcpy((uchar*) (res+1+args.elements+1), (char*) ((*argv)+1), (*argc-1)*sizeof(char*)); - res[args.elements+ *argc]=0; /* last null */ + res[args.elements+ *argc+1]=0; /* last null */ - (*argc)+=args.elements; + (*argc)+=args.elements+1; *argv= (char**) res; *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ delete_dynamic(&args); @@ -523,7 +551,8 @@ int my_load_defaults(const char *conf_file, const char **groups, printf("%s would have been started with the following arguments:\n", **argv); for (i=1 ; i < *argc ; i++) - printf("%s ", (*argv)[i]); + if ((*argv)[i] != args_separator) /* skip arguments separator */ + printf("%s ", (*argv)[i]); puts(""); exit(0); } diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index b6eb6dac54f..22b1216f99c 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -121,6 +121,7 @@ int handle_options(int *argc, char ***argv, const struct my_option *optp; uchar* *value; int error, i; + my_bool is_cmdline_arg= 1; LINT_INIT(opt_found); /* handle_options() assumes arg0 (program name) always exists */ @@ -130,10 +131,34 @@ int handle_options(int *argc, char ***argv, (*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 (*pos == args_separator) + { + is_cmdline_arg= 0; + break; + } + } + for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++) { char **first= pos; char *cur_arg= *pos; + if (!is_cmdline_arg && (cur_arg == args_separator)) + { + is_cmdline_arg= 1; + + /* save the separator too if skip unkown options */ + if (my_getopt_skip_unknown) + (*argv)[argvpos++]= cur_arg; + else + (*argc)--; + continue; + } if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */ { char *argument= 0; @@ -426,8 +451,12 @@ invalid value '%s'", } else if (optp->arg_type == REQUIRED_ARG && !optend) { - /* Check if there are more arguments after this one */ - if (!*++pos) + /* Check if there are more arguments after this one, + + Note: options loaded from config file that requires value + should always be in the form '--option=value'. + */ + if (!is_cmdline_arg || !*++pos) { if (my_getopt_print_errors) my_getopt_error_reporter(ERROR_LEVEL, diff --git a/mysys/my_handler_errors.h b/mysys/my_handler_errors.h index c239cabb168..e4e62f47fed 100644 --- a/mysys/my_handler_errors.h +++ b/mysys/my_handler_errors.h @@ -1,3 +1,5 @@ +#ifndef MYSYS_MY_HANDLER_ERRORS_INCLUDED +#define MYSYS_MY_HANDLER_ERRORS_INCLUDED /* Errors a handler can give you @@ -66,3 +68,4 @@ static const char *handler_error_messages[]= "Too many active concurrent transactions" }; +#endif /* MYSYS_MY_HANDLER_ERRORS_INCLUDED */ diff --git a/mysys/my_static.h b/mysys/my_static.h index 90168b099a8..c336115bc35 100644 --- a/mysys/my_static.h +++ b/mysys/my_static.h @@ -1,3 +1,6 @@ +#ifndef MYSYS_MY_STATIC_INCLUDED +#define MYSYS_MY_STATIC_INCLUDED + /* Copyright (C) 2000 MySQL AB This program is free software; you can redistribute it and/or modify @@ -72,3 +75,5 @@ extern ulonglong query_performance_frequency, query_performance_offset; extern sigset_t my_signals; /* signals blocked by mf_brkhant */ #endif C_MODE_END + +#endif /* MYSYS_MY_STATIC_INCLUDED */ |