From: Date: October 17 2007 9:04am Subject: bk commit into 5.1 tree (tsmith:1.2581) BUG#20748 List-Archive: http://lists.mysql.com/commits/35732 X-Bug: 20748 Message-Id: <20071017070438.87C997B03@ramayana.hindu.god> Below is the list of changes that have just been committed into a local 5.1 repository of tsmith. When tsmith does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-10-17 01:04:34-06:00, tsmith@stripped +1 -0 Bug #20748: Configuration files should not be read more than once Change init_default_directories() to remove duplicates from the list. Also, move --sysconfdir= (DEFAULT_SYSCONFDIR) from the end to the middle of the list. $HOME/.my.cnf should be last, so the user is able to override the system-wide settings. mysys/default.c@stripped, 2007-10-17 01:04:32-06:00, tsmith@stripped +74 -35 Change order in which defaults files are searched. Move DEFAULT_SYSCONFDIR from the end to the middle (after the hard- coded "/etc/" or "C:/", etc.; and before the run-time directories (DEFAULT_HOME_ENV, --defaults-extra-file). Also, don't add duplicate entries in the defaults_directories list. Instead of adding a new duplicate entry, move the existing entry to the end of the list. diff -Nrup a/mysys/default.c b/mysys/default.c --- a/mysys/default.c 2007-05-10 03:59:25 -06:00 +++ b/mysys/default.c 2007-10-17 01:04:32 -06:00 @@ -960,66 +960,110 @@ static size_t my_get_system_windows_dire /* - Create the list of default directories. + @brief Add a single directory to the global default_directories list + @details Add the directory to the end of default_directories; if it is + already present in the list, move it to the end. + + @param dir Directory to add + + @return void +*/ + +static void add_one_default_directory(const char *dir) +{ + const char **p; + for (p= default_directories; *p; ++p) + { + if (strcmp(*p, dir) == 0) + break; + } + DBUG_ASSERT(p < default_directories + + array_elements(default_directories) - 1); + DBUG_ASSERT(*p == NULL || strcmp(*p, dir) == 0); + + while (*(p + 1)) + { + *p= *(p + 1); + ++p; + } + + *p= dir; +} + + +/* + @brief Create the list of default directories. + + @details On Microsoft Windows, this is: 1. C:/ 2. GetWindowsDirectory() 3. GetSystemWindowsDirectory() - 4. getenv(DEFAULT_HOME_ENV) - 5. Directory above where the executable is located - 6. "" - 7. --sysconfdir= + 4. --sysconfdir= (compile-time option) + 5. getenv(DEFAULT_HOME_ENV) + 6. Directory above where the executable is located + 7. --defaults-extra-file= (run-time option) On Novell NetWare, this is: 1. sys:/etc/ - 2. getenv(DEFAULT_HOME_ENV) - 3. "" - 4. --sysconfdir= + 2. --sysconfdir= (compile-time option) + 3. getenv(DEFAULT_HOME_ENV) + 4. --defaults-extra-file= (run-time option) On OS/2, this is: 1. getenv(ETC) 2. /etc/ - 3. getenv(DEFAULT_HOME_ENV) - 4. "" - 5. "~/" - 6. --sysconfdir= + 3. --sysconfdir= (compile-time option) + 4. getenv(DEFAULT_HOME_ENV) + 5. --defaults-extra-file= (run-time option) + 6. "~/" Everywhere else, this is: 1. /etc/ 2. /etc/mysql/ - 3. getenv(DEFAULT_HOME_ENV) - 4. "" - 5. "~/" - 6. --sysconfdir= + 3. --sysconfdir= (compile-time option) + 4. getenv(DEFAULT_HOME_ENV) + 5. --defaults-extra-file= (run-time option) + 6. "~/" + + On all systems, if a directory is already in the list, it will be moved + to the end of the list. This avoids reading defaults files multiple times, + while ensuring the correct precedence. - */ + @return void +*/ static void init_default_directories() { - const char *env, **ptr= default_directories; + const char *env; + + bzero(default_directories, sizeof(default_directories)); #ifdef __WIN__ - *ptr++= "C:/"; + add_one_default_directory("C:/"); if (GetWindowsDirectory(system_dir,sizeof(system_dir))) - *ptr++= (char*)&system_dir; + add_one_default_directory((char *)&system_dir); if (my_get_system_windows_directory(shared_system_dir, - sizeof(shared_system_dir)) && - strcmp(system_dir, shared_system_dir)) - *ptr++= (char *)&shared_system_dir; + sizeof(shared_system_dir))) + add_one_default_directory((char *)&shared_system_dir); #elif defined(__NETWARE__) - *ptr++= "sys:/etc/"; + add_one_default_directory("sys:/etc/"); #else - *ptr++= "/etc/"; - *ptr++= "/etc/mysql/"; + add_one_default_directory("/etc/"); + add_one_default_directory("/etc/mysql/"); +#endif +#ifdef DEFAULT_SYSCONFDIR + if (DEFAULT_SYSCONFDIR != "") + add_one_default_directory(DEFAULT_SYSCONFDIR); #endif if ((env= getenv(STRINGIFY_ARG(DEFAULT_HOME_ENV)))) - *ptr++= env; - *ptr++= ""; /* Place for defaults_extra_file */ + add_one_default_directory(env); + add_one_default_directory(""); /* Place for defaults_extra_file */ #if !defined(__WIN__) && !defined(__NETWARE__) - *ptr++= "~/";; + add_one_default_directory("~/"); #elif defined(__WIN__) if (GetModuleFileName(NULL, config_dir, sizeof(config_dir))) { @@ -1050,12 +1094,7 @@ static void init_default_directories() last= end; } } - *ptr++= (char *)&config_dir; + add_one_default_directory((char *)&config_dir); } #endif -#ifdef DEFAULT_SYSCONFDIR - if (DEFAULT_SYSCONFDIR != "") - *ptr++= DEFAULT_SYSCONFDIR; -#endif - *ptr= 0; /* end marker */ }