Added a warning to my_print_defaults if --verbose is given

and --defaults-file is a non-existing or non-regular file.
Bug#755
parent 215935d6
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <my_getopt.h> #include <my_getopt.h>
const char *config_file="my"; /* Default config file */ const char *config_file="my"; /* Default config file */
uint verbose= 0, opt_defaults_file_used= 0;
static struct my_option my_long_options[] = static struct my_option my_long_options[] =
{ {
...@@ -47,6 +48,8 @@ static struct my_option my_long_options[] = ...@@ -47,6 +48,8 @@ static struct my_option my_long_options[] =
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"help", '?', "Display this help message and exit.", {"help", '?', "Display this help message and exit.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Increase the output level",
0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Output version information and exit.", {"version", 'V', "Output version information and exit.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
...@@ -55,7 +58,7 @@ static struct my_option my_long_options[] = ...@@ -55,7 +58,7 @@ static struct my_option my_long_options[] =
static void usage(my_bool version) static void usage(my_bool version)
{ {
printf("%s Ver 1.5 for %s at %s\n",my_progname,SYSTEM_TYPE, printf("%s Ver 1.6 for %s at %s\n",my_progname,SYSTEM_TYPE,
MACHINE_TYPE); MACHINE_TYPE);
if (version) if (version)
return; return;
...@@ -73,12 +76,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -73,12 +76,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument __attribute__((unused))) char *argument __attribute__((unused)))
{ {
switch (optid) { switch (optid) {
case 'c':
opt_defaults_file_used= 1;
break;
case 'n': case 'n':
exit(0); exit(0);
case 'I': case 'I':
case '?': case '?':
usage(0); usage(0);
exit(0); exit(0);
case 'v':
verbose++;
break;
case 'V': case 'V':
usage(1); usage(1);
exit(0); exit(0);
...@@ -104,7 +113,7 @@ static int get_options(int *argc,char ***argv) ...@@ -104,7 +113,7 @@ static int get_options(int *argc,char ***argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int count; int count, error;
char **load_default_groups, *tmp_arguments[2], char **load_default_groups, *tmp_arguments[2],
**argument, **arguments; **argument, **arguments;
MY_INIT(argv[0]); MY_INIT(argv[0]);
...@@ -126,8 +135,20 @@ int main(int argc, char **argv) ...@@ -126,8 +135,20 @@ int main(int argc, char **argv)
arguments=tmp_arguments; arguments=tmp_arguments;
arguments[0]=my_progname; arguments[0]=my_progname;
arguments[1]=0; arguments[1]=0;
load_defaults(config_file, (const char **) load_default_groups, if ((error= load_defaults(config_file, (const char **) load_default_groups,
&count, &arguments); &count, &arguments)) > 1)
{
if (verbose && opt_defaults_file_used)
{
if (error == 2)
fprintf(stderr, "WARNING: Defaults file (%s) not found!\n",
config_file);
if (error == 3)
fprintf(stderr, "WARNING: Defaults file (%s) is not a regular file!\n",
config_file);
}
exit(2); // Non-fatal error
}
for (argument= arguments+1 ; *argument ; argument++) for (argument= arguments+1 ; *argument ; argument++)
puts(*argument); puts(*argument);
......
...@@ -742,7 +742,7 @@ extern void set_prealloc_root(MEM_ROOT *root, char *ptr); ...@@ -742,7 +742,7 @@ extern void set_prealloc_root(MEM_ROOT *root, char *ptr);
extern char *strdup_root(MEM_ROOT *root,const char *str); extern char *strdup_root(MEM_ROOT *root,const char *str);
extern char *strmake_root(MEM_ROOT *root,const char *str,uint len); 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 char *memdup_root(MEM_ROOT *root,const char *str,uint len);
extern void load_defaults(const char *conf_file, const char **groups, extern int load_defaults(const char *conf_file, const char **groups,
int *argc, char ***argv); int *argc, char ***argv);
extern void free_defaults(char **argv); extern void free_defaults(char **argv);
extern void print_defaults(const char *conf_file, const char **groups); extern void print_defaults(const char *conf_file, const char **groups);
......
...@@ -242,7 +242,7 @@ void hash_password(unsigned long *result, const char *password); ...@@ -242,7 +242,7 @@ void hash_password(unsigned long *result, const char *password);
/* Some other useful functions */ /* Some other useful functions */
void my_init(void); void my_init(void);
void load_defaults(const char *conf_file, const char **groups, int load_defaults(const char *conf_file, const char **groups,
int *argc, char ***argv); int *argc, char ***argv);
my_bool my_thread_init(void); my_bool my_thread_init(void);
void my_thread_end(void); void my_thread_end(void);
......
...@@ -66,13 +66,13 @@ NullS, ...@@ -66,13 +66,13 @@ NullS,
#define windows_ext ".ini" #define windows_ext ".ini"
#endif #endif
static my_bool search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, static int search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc,
const char *dir, const char *config_file, const char *dir, const char *config_file,
const char *ext, TYPELIB *group); const char *ext, TYPELIB *group);
static char *remove_end_comment(char *ptr); static char *remove_end_comment(char *ptr);
void load_defaults(const char *conf_file, const char **groups, int load_defaults(const char *conf_file, const char **groups,
int *argc, char ***argv) int *argc, char ***argv)
{ {
DYNAMIC_ARRAY args; DYNAMIC_ARRAY args;
...@@ -80,6 +80,7 @@ void load_defaults(const char *conf_file, const char **groups, ...@@ -80,6 +80,7 @@ void load_defaults(const char *conf_file, const char **groups,
TYPELIB group; TYPELIB group;
my_bool found_print_defaults=0; my_bool found_print_defaults=0;
uint args_used=0; uint args_used=0;
int error= 0;
MEM_ROOT alloc; MEM_ROOT alloc;
char *ptr,**res; char *ptr,**res;
DBUG_ENTER("load_defaults"); DBUG_ENTER("load_defaults");
...@@ -100,7 +101,7 @@ void load_defaults(const char *conf_file, const char **groups, ...@@ -100,7 +101,7 @@ void load_defaults(const char *conf_file, const char **groups,
(*argc)--; (*argc)--;
*argv=res; *argv=res;
*(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */
DBUG_VOID_RETURN; return 0;
} }
/* Check if we want to force the use a specific default file */ /* Check if we want to force the use a specific default file */
...@@ -129,14 +130,14 @@ void load_defaults(const char *conf_file, const char **groups, ...@@ -129,14 +130,14 @@ void load_defaults(const char *conf_file, const char **groups,
goto err; goto err;
if (forced_default_file) if (forced_default_file)
{ {
if (search_default_file(&args, &alloc, "", forced_default_file, "", if ((error= search_default_file(&args, &alloc, "",
&group)) forced_default_file, "", &group)) == 1)
goto err; goto err;
} }
else if (dirname_length(conf_file)) else if (dirname_length(conf_file))
{ {
if (search_default_file(&args, &alloc, NullS, conf_file, default_ext, if ((error= search_default_file(&args, &alloc, NullS, conf_file,
&group)) default_ext, &group)) == 1)
goto err; goto err;
} }
else else
...@@ -144,26 +145,25 @@ void load_defaults(const char *conf_file, const char **groups, ...@@ -144,26 +145,25 @@ void load_defaults(const char *conf_file, const char **groups,
#ifdef __WIN__ #ifdef __WIN__
char system_dir[FN_REFLEN]; char system_dir[FN_REFLEN];
GetWindowsDirectory(system_dir,sizeof(system_dir)); GetWindowsDirectory(system_dir,sizeof(system_dir));
if (search_default_file(&args, &alloc, system_dir, conf_file, windows_ext, if ((error= search_default_file(&args, &alloc, system_dir, conf_file,
&group)) windows_ext, &group)) == 1)
goto err; goto err;
#endif #endif
#if defined(__EMX__) || defined(OS2) #if defined(__EMX__) || defined(OS2)
if (getenv("ETC") && if (getenv("ETC") &&
search_default_file(&args, &alloc, getenv("ETC"), conf_file, (error= search_default_file(&args, &alloc, getenv("ETC"), conf_file,
default_ext, &group)) default_ext, &group)) == 1)
goto err; goto err;
#endif #endif
for (dirs=default_directories ; *dirs; dirs++) for (dirs=default_directories ; *dirs; dirs++)
{ {
int error=0;
if (**dirs) if (**dirs)
error=search_default_file(&args, &alloc, *dirs, conf_file, error= search_default_file(&args, &alloc, *dirs, conf_file,
default_ext, &group); default_ext, &group);
else if (defaults_extra_file) else if (defaults_extra_file)
error=search_default_file(&args, &alloc, NullS, defaults_extra_file, error= search_default_file(&args, &alloc, NullS, defaults_extra_file,
default_ext, &group); default_ext, &group);
if (error) if (error == 1)
goto err; goto err;
} }
} }
...@@ -204,11 +204,11 @@ void load_defaults(const char *conf_file, const char **groups, ...@@ -204,11 +204,11 @@ void load_defaults(const char *conf_file, const char **groups,
puts(""); puts("");
exit(1); exit(1);
} }
DBUG_VOID_RETURN; return error;
err: err:
fprintf(stderr,"Program aborted\n"); fprintf(stderr,"Program aborted\n");
exit(1); return(error);
} }
...@@ -220,7 +220,14 @@ void free_defaults(char **argv) ...@@ -220,7 +220,14 @@ void free_defaults(char **argv)
} }
static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, /*
Return values: 0 Success
1 Fatal error, abort
2 File not found, continue
3 File is not a regular file, continue
*/
static int search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
const char *dir, const char *config_file, const char *dir, const char *config_file,
const char *ext, TYPELIB *group) const char *ext, TYPELIB *group)
{ {
...@@ -247,7 +254,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, ...@@ -247,7 +254,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
{ {
MY_STAT stat_info; MY_STAT stat_info;
if (!my_stat(name,&stat_info,MYF(0))) if (!my_stat(name,&stat_info,MYF(0)))
return 0; return 2;
/* /*
Ignore world-writable regular files. Ignore world-writable regular files.
This is mainly done to protect us to not read a file created by This is mainly done to protect us to not read a file created by
...@@ -260,6 +267,8 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, ...@@ -260,6 +267,8 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
name); name);
return 0; return 0;
} }
else if ((stat_info.st_mode & S_IFMT) != S_IFREG)
return 3;
} }
#endif #endif
if (!(fp = my_fopen(fn_format(name,name,"","",4),O_RDONLY,MYF(0)))) if (!(fp = my_fopen(fn_format(name,name,"","",4),O_RDONLY,MYF(0))))
......
...@@ -148,7 +148,7 @@ else ...@@ -148,7 +148,7 @@ else
fi fi
args= args=
parse_arguments `$print_defaults $defaults mysqld server mysqld_safe safe_mysqld` parse_arguments `$print_defaults --loose-verbose $defaults mysqld server mysqld_safe safe_mysqld`
parse_arguments PICK-ARGS-FROM-ARGV "$@" parse_arguments PICK-ARGS-FROM-ARGV "$@"
if test ! -x $ledir/$MYSQLD if test ! -x $ledir/$MYSQLD
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment