#At file:///net/helheim/store/bteam/bzr/mysql-5.4.3-tsmith/
2880 timothy.smith@stripped 2009-09-23
Add --malloc-lib=LIB option to mysqld_safe to LD_PRELOAD a shared library for mysqld
modified:
scripts/mysql_config.sh
scripts/mysqld_safe.sh
=== modified file 'scripts/mysql_config.sh'
--- a/scripts/mysql_config.sh 2009-09-08 13:35:01 +0000
+++ b/scripts/mysql_config.sh 2009-09-22 23:26:08 +0000
@@ -167,6 +167,10 @@ Options:
--port [$port]
--version [$version]
--libmysqld-libs [$embedded_libs]
+ --variable=VAR VAR is one of:
+ pkgincludedir [$pkgincludedir]
+ pkglibdir [$pkglibdir]
+ plugindir [$plugindir]
EOF
exit 1
}
@@ -184,6 +188,15 @@ while test $# -gt 0; do
--port) echo "$port" ;;
--version) echo "$version" ;;
--embedded-libs | --embedded | --libmysqld-libs) echo "$embedded_libs" ;;
+ --variable=*)
+ var=`echo "$1" | sed 's,^[^=]*=,,'`
+ case "$var" in
+ pkgincludedir) echo "$pkgincludedir" ;;
+ pkglibdir) echo "$pkglibdir" ;;
+ plugindir) echo "$plugindir" ;;
+ *) usage ;;
+ esac
+ ;;
*) usage ;;
esac
=== modified file 'scripts/mysqld_safe.sh'
--- a/scripts/mysqld_safe.sh 2009-08-19 15:16:30 +0000
+++ b/scripts/mysqld_safe.sh 2009-09-22 23:26:08 +0000
@@ -11,9 +11,13 @@
# mysql.server works by first doing a cd to the base directory and from there
# executing mysqld_safe
+# Initialize script globals
KILL_MYSQLD=1;
MYSQLD=
niceness=0
+mysqld_ld_preload=
+mysqld_ld_library_path=
+
# Initial logging status: error log is not open, and not using syslog
logging=init
want_syslog=0
@@ -46,6 +50,7 @@ Usage: $0 [OPTIONS]
--open-files-limit=LIMIT Limit the number of open files
--core-file-size=LIMIT Limit core files to the specified size
--timezone=TZ Set the system timezone
+ --malloc-lib=LIB Preload shared library LIB if available
--mysqld=FILE Use the specified file as mysqld
--mysqld-version=VERSION Use "mysqld-VERSION" as mysqld
--nice=NICE Set the scheduling priority of mysqld
@@ -172,6 +177,7 @@ parse_arguments() {
# mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
--core-file-size=*) core_file_size="$val" ;;
--ledir=*) ledir="$val" ;;
+ --malloc-lib=*) set_malloc_lib "$val" ;;
--mysqld=*) MYSQLD="$val" ;;
--mysqld-version=*)
if test -n "$val"
@@ -202,6 +208,131 @@ parse_arguments() {
}
+# Add a single shared library to the list of libraries which will be added to
+# LD_PRELOAD for mysqld
+#
+# Since LD_PRELOAD is a space-separated value (for historical reasons), if a
+# shared lib's path contains spaces, that path will be prepended to
+# LD_LIBRARY_PATH and stripped from the lib value.
+add_mysqld_ld_preload() {
+ lib_to_add="$1"
+ log_notice "Adding '$lib_to_add' to LD_PRELOAD for mysqld"
+
+ case "$lib_to_add" in
+ *' '*)
+ # Must strip path from lib, and add it to LD_LIBRARY_PATH
+ lib_file=`basename "$lib_to_add"`
+ case "$lib_file" in
+ *' '*)
+ # The lib file itself has a space in its name, and can't
+ # be used in LD_PRELOAD
+ log_error "library name '$lib_to_add' contains spaces and can not be used with LD_PRELOAD"
+ exit 1
+ ;;
+ esac
+ lib_path=`dirname "$lib_to_add"`
+ lib_to_add="$lib_file"
+ [ -n "$mysqld_ld_library_path" ] && mysqld_ld_library_path="$mysqld_ld_library_path:"
+ mysqld_ld_library_path="$mysqld_ld_library_path$lib_path"
+ ;;
+ esac
+
+ # LD_PRELOAD is a space-separated
+ [ -n "$mysqld_ld_preload" ] && mysqld_ld_preload="$mysqld_ld_preload "
+ mysqld_ld_preload="${mysqld_ld_preload}$lib_to_add"
+}
+
+
+# Returns LD_PRELOAD (and LD_LIBRARY_PATH, if needed) text, quoted to be
+# suitable for use in the eval that calls mysqld.
+#
+# All values in mysqld_ld_preload are prepended to LD_PRELOAD.
+mysqld_ld_preload_text() {
+ text=
+
+ if [ -n "$mysqld_ld_preload" ]; then
+ new_text="$mysqld_ld_preload"
+ [ -n "$LD_PRELOAD" ] && new_text="$new_text $LD_PRELOAD"
+ text="${text}LD_PRELOAD="`shell_quote_string "$new_text"`' '
+ fi
+
+ if [ -n "$mysqld_ld_library_path" ]; then
+ new_text="$mysqld_ld_library_path"
+ [ -n "$LD_LIBRARY_PATH" ] && new_text="$new_text:$LD_LIBRARY_PATH"
+ text="${text}LD_LIBRARY_PATH="`shell_quote_string "$new_text"`' '
+ fi
+
+ echo "$text"
+}
+
+
+mysql_config=
+get_mysql_config() {
+ if [ -z "$mysql_config" ]; then
+ mysql_config=`echo "$0" | sed 's,/[^/][^/]*$,/mysql_config,'`
+ if [ ! -x "$mysql_config" ]; then
+ log_error "Can not run mysql_config $@ from '$mysql_config'"
+ exit 1
+ fi
+ fi
+
+ "$mysql_config" "$@"
+}
+
+
+# set_malloc_lib LIB
+# - If LIB is empty, do nothing and return
+# - If LIB is 'tcmalloc', look for tcmalloc shared library in /usr/lib
+# then pkglibdir. tcmalloc is part of the Google perftools project.
+# - If LIB is an absolute path, assume it is a malloc shared library
+#
+# Put LIB in mysqld_ld_preload, which will be added to LD_PRELOAD when
+# running mysqld. See ld.so for details.
+set_malloc_lib() {
+ malloc_lib="$1"
+
+ if [ "$malloc_lib" = tcmalloc ]; then
+ pkglibdir=`get_mysql_config --variable=pkglibdir`
+ malloc_lib=
+ # This list is kept intentionally simple. Simply set --malloc-lib
+ # to a full path if another location is desired.
+ for libdir in /usr/lib "$pkglibdir"; do
+ for flavor in _minimal '' _and_profiler _debug; do
+ tmp="$libdir/libtcmalloc$flavor.so"
+ #log_notice "DEBUG: Checking for malloc lib '$tmp'"
+ [ -r "$tmp" ] || continue
+ malloc_lib="$tmp"
+ break 2
+ done
+ done
+
+ if [ -z "$malloc_lib" ]; then
+ log_error "no shared library for --malloc-lib=tcmalloc found in /usr/lib or $pkglibdir"
+ exit 1
+ fi
+ fi
+
+ # Allow --malloc-lib='' to override other settings
+ [ -z "$malloc_lib" ] && return
+
+ case "$malloc_lib" in
+ /*)
+ if [ ! -r "$malloc_lib" ]; then
+ log_error "--malloc-lib '$malloc_lib' can not be read and will not be used"
+ exit 1
+ fi
+ ;;
+ *)
+ log_error "--malloc-lib must be an absolute path or 'tcmalloc'; " \
+ "ignoring value '$malloc_lib'"
+ exit 1
+ ;;
+ esac
+
+ add_mysqld_ld_preload "$malloc_lib"
+}
+
+
#
# First, try to find BASEDIR and ledir (where mysqld is)
#
@@ -549,7 +680,7 @@ fi
# ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems
#fi
-cmd="$NOHUP_NICENESS"
+cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS"
for i in "$ledir/$MYSQLD" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
"--datadir=$DATADIR" "$USER_OPTION"
| Thread |
|---|
| • bzr commit into mysql-5.4.3-trunk branch (build:2880) | MySQL Build Team | 23 Sep |