From 5f8ef50b3561961c436d683c776f2254b7477346 Mon Sep 17 00:00:00 2001 From: "jani@rhols221.adsl.netsonic.fi" <> Date: Wed, 27 Aug 2003 19:22:14 +0300 Subject: [PATCH] Added a warning to my_print_defaults if --verbose is given and --defaults-file is a non-existing or non-regular file. Bug#755 --- extra/my_print_defaults.c | 29 ++++++++++++++++--- include/my_sys.h | 4 +-- include/mysql_com.h | 4 +-- mysys/default.c | 59 ++++++++++++++++++++++----------------- scripts/mysqld_safe.sh | 2 +- 5 files changed, 64 insertions(+), 34 deletions(-) diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c index c0f8a54f43..549b2124b5 100644 --- a/extra/my_print_defaults.c +++ b/extra/my_print_defaults.c @@ -26,6 +26,7 @@ #include <my_getopt.h> const char *config_file="my"; /* Default config file */ +uint verbose= 0, opt_defaults_file_used= 0; 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}, {"help", '?', "Display this help message and exit.", 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.", 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[] = 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); if (version) return; @@ -73,12 +76,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument __attribute__((unused))) { switch (optid) { + case 'c': + opt_defaults_file_used= 1; + break; case 'n': exit(0); case 'I': case '?': usage(0); exit(0); + case 'v': + verbose++; + break; case 'V': usage(1); exit(0); @@ -104,7 +113,7 @@ static int get_options(int *argc,char ***argv) int main(int argc, char **argv) { - int count; + int count, error; char **load_default_groups, *tmp_arguments[2], **argument, **arguments; MY_INIT(argv[0]); @@ -126,8 +135,20 @@ int main(int argc, char **argv) arguments=tmp_arguments; arguments[0]=my_progname; arguments[1]=0; - load_defaults(config_file, (const char **) load_default_groups, - &count, &arguments); + if ((error= load_defaults(config_file, (const char **) load_default_groups, + &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++) puts(*argument); diff --git a/include/my_sys.h b/include/my_sys.h index 9f4b91c8bf..7a3d22f330 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -742,8 +742,8 @@ extern void set_prealloc_root(MEM_ROOT *root, char *ptr); 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 load_defaults(const char *conf_file, const char **groups, - int *argc, char ***argv); +extern int load_defaults(const char *conf_file, const char **groups, + int *argc, char ***argv); extern void free_defaults(char **argv); extern void print_defaults(const char *conf_file, const char **groups); extern my_bool my_compress(byte *, ulong *, ulong *); diff --git a/include/mysql_com.h b/include/mysql_com.h index 945372563b..6daf26bc2a 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -242,8 +242,8 @@ void hash_password(unsigned long *result, const char *password); /* Some other useful functions */ void my_init(void); -void load_defaults(const char *conf_file, const char **groups, - int *argc, char ***argv); +int load_defaults(const char *conf_file, const char **groups, + int *argc, char ***argv); my_bool my_thread_init(void); void my_thread_end(void); diff --git a/mysys/default.c b/mysys/default.c index cdacc8bee2..716be6fc2b 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -66,13 +66,13 @@ NullS, #define windows_ext ".ini" #endif -static my_bool search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, - const char *dir, const char *config_file, - const char *ext, TYPELIB *group); +static int search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, + const char *dir, const char *config_file, + const char *ext, TYPELIB *group); 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) { DYNAMIC_ARRAY args; @@ -80,6 +80,7 @@ void load_defaults(const char *conf_file, const char **groups, TYPELIB group; my_bool found_print_defaults=0; uint args_used=0; + int error= 0; MEM_ROOT alloc; char *ptr,**res; DBUG_ENTER("load_defaults"); @@ -100,7 +101,7 @@ void load_defaults(const char *conf_file, const char **groups, (*argc)--; *argv=res; *(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 */ @@ -129,14 +130,14 @@ void load_defaults(const char *conf_file, const char **groups, goto err; if (forced_default_file) { - if (search_default_file(&args, &alloc, "", forced_default_file, "", - &group)) + if ((error= search_default_file(&args, &alloc, "", + forced_default_file, "", &group)) == 1) goto err; } else if (dirname_length(conf_file)) { - if (search_default_file(&args, &alloc, NullS, conf_file, default_ext, - &group)) + if ((error= search_default_file(&args, &alloc, NullS, conf_file, + default_ext, &group)) == 1) goto err; } else @@ -144,26 +145,25 @@ void load_defaults(const char *conf_file, const char **groups, #ifdef __WIN__ char system_dir[FN_REFLEN]; GetWindowsDirectory(system_dir,sizeof(system_dir)); - if (search_default_file(&args, &alloc, system_dir, conf_file, windows_ext, - &group)) + if ((error= search_default_file(&args, &alloc, system_dir, conf_file, + windows_ext, &group)) == 1) goto err; #endif #if defined(__EMX__) || defined(OS2) if (getenv("ETC") && - search_default_file(&args, &alloc, getenv("ETC"), conf_file, - default_ext, &group)) + (error= search_default_file(&args, &alloc, getenv("ETC"), conf_file, + default_ext, &group)) == 1) goto err; #endif for (dirs=default_directories ; *dirs; dirs++) { - int error=0; if (**dirs) - error=search_default_file(&args, &alloc, *dirs, conf_file, - default_ext, &group); + error= search_default_file(&args, &alloc, *dirs, conf_file, + default_ext, &group); else if (defaults_extra_file) - error=search_default_file(&args, &alloc, NullS, defaults_extra_file, - default_ext, &group); - if (error) + error= search_default_file(&args, &alloc, NullS, defaults_extra_file, + default_ext, &group); + if (error == 1) goto err; } } @@ -204,11 +204,11 @@ void load_defaults(const char *conf_file, const char **groups, puts(""); exit(1); } - DBUG_VOID_RETURN; + return error; err: fprintf(stderr,"Program aborted\n"); - exit(1); + return(error); } @@ -220,9 +220,16 @@ void free_defaults(char **argv) } -static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, - const char *dir, const char *config_file, - const char *ext, TYPELIB *group) +/* + 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 *ext, TYPELIB *group) { char name[FN_REFLEN+10],buff[4096],*ptr,*end,*value,*tmp; FILE *fp; @@ -247,7 +254,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, { MY_STAT stat_info; if (!my_stat(name,&stat_info,MYF(0))) - return 0; + return 2; /* Ignore world-writable regular files. 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, name); return 0; } + else if ((stat_info.st_mode & S_IFMT) != S_IFREG) + return 3; } #endif if (!(fp = my_fopen(fn_format(name,name,"","",4),O_RDONLY,MYF(0)))) diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index d7e3eedb84..1c056e963c 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -148,7 +148,7 @@ else fi 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 "$@" if test ! -x $ledir/$MYSQLD -- 2.30.9