You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB

Bug #20748: Configuration files should not be read more than once A user could not override system-wide settings in their ~/.my.cnf, because the DEFAULT_SYSCONFDIR was being searched last. Also, in some configurations (especially when the --sysconfdir compile-time option is set to /etc or /etc/mysql), the system-wide my.cnf file was read multiple times, causing confusion and potential problems. Rearrange default directories to conform to the manual and logic. Move --sysconfdir=<path> (DEFAULT_SYSCONFDIR) from the last default directory to the middle of the list. $HOME/.my.cnf should be last, so the user is able to override the system-wide settings. Change init_default_directories() to remove duplicates from the list. include/my_sys.h: Add array_append_string_unique(), from mf_arr_appstr.c libmysql/Makefile.shared: Add new mf_arr_appstr.lo object mysys/CMakeLists.txt: Add new mf_arr_appstr.c source. mysys/Makefile.am: Add new mf_arr_appstr.c source. mysys/default.c: Change order in which defaults files are added to default_directories, in order to conform to the manual (and to common sense). This fixes a particularly bad problem on Unix, where ~/.my.cnf was read before /usr/local/etc/my.cnf. Also, don't add duplicate entries; move the existing entry to the end of the list instead. Here is a comparison of the order of defaults files, BEFORE and AFTER this patch. On Windows: BEFORE: C:\, GetWindowsDirectory(), GetSystemWindowsDirectory(), $MYSQL_HOME, defaults-extra-file, INSTALLDIR AFTER: GetSystemWindowsDirectory(), GetWindowsDirectory(), C:\, INSTALLDIR, $MYSQL_HOME, defaults-extra-file GetSystemWindowsDirectory() is moved before GetWindowsDirectory() because the former is shared by all Terminal Services users, while the latter is private for each user. On Netware (no change): BEFORE: sys:/etc/, $MYSQL_HOME, defaults-extra-file AFTER: sys:/etc, $MYSQL_HOME, defaults-extra-file On OS/2: BEFORE: $ETC, /etc, $MYSQL_HOME, defaults-extra-file AFTER: /etc, $ETC, $MYSQL_HOME, defaults-extra-file On everything else (general Unix): BEFORE: /etc, $MYSQL_HOME, defaults-extra-file, ~/, --sysconfdir AFTER: /etc/, --sysconfdir, $MYSQL_HOME, defaults-extra-file, ~/ The BEFORE code added --sysconfdir on all systems, but only the Unix build system actually defined a value for it. mysys/mf_arr_appstr.c: BitKeeper file /home/tsmith/m/bk/build/50-b20748/mysys/mf_arr_appstr.c
18 years ago
  1. /* Copyright (C) 2007 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. #include "mysys_priv.h"
  13. #include <m_string.h> /* strcmp() */
  14. /**
  15. Append str to array, or move to the end if it already exists
  16. @param str String to be appended
  17. @param array The array, terminated by a NULL element, all unused elements
  18. pre-initialized to NULL
  19. @param size Size of the array; array must be terminated by a NULL
  20. pointer, so can hold size - 1 elements
  21. @retval FALSE Success
  22. @retval TRUE Failure, array is full
  23. */
  24. my_bool array_append_string_unique(const char *str,
  25. const char **array, size_t size)
  26. {
  27. const char **p;
  28. /* end points at the terminating NULL element */
  29. const char **end= array + size - 1;
  30. DBUG_ASSERT(*end == NULL);
  31. for (p= array; *p; ++p)
  32. {
  33. if (strcmp(*p, str) == 0)
  34. break;
  35. }
  36. if (p >= end)
  37. return TRUE; /* Array is full */
  38. DBUG_ASSERT(*p == NULL || strcmp(*p, str) == 0);
  39. while (*(p + 1))
  40. {
  41. *p= *(p + 1);
  42. ++p;
  43. }
  44. DBUG_ASSERT(p < end);
  45. *p= str;
  46. return FALSE; /* Success */
  47. }