From 01156894dba3fc08b9a8696f68e72d929bd64211 Mon Sep 17 00:00:00 2001 From: Manuel Ung Date: Fri, 8 Mar 2019 10:36:39 -0800 Subject: [PATCH] FB8-186: Extend mysqld_safe to LD_PRELOAD shared libraries (#979) Summary: Jira issue: https://jira.percona.com/browse/FB8-186 Reference Patch: https://github.com/facebook/mysql-5.6/commit/16b02494411 This will allow us to override some glibc functions like localtime_r. Originally Reviewed By: hermanlee Pull Request resolved: https://github.com/facebook/mysql-5.6/pull/979 Reviewed By: lth Differential Revision: D14335103 Pulled By: lth fbshipit-source-id: b604e021394 --- scripts/mysqld_safe.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 5ad1d6dba379..3e87f0b8c6c7 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -80,6 +80,7 @@ Usage: $0 [OPTIONS] --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 + --ld-preload-lib=LIB Preload shared library LIB --mysqld=FILE Use the specified file as mysqld --mysqld-version=VERSION Use "mysqld-VERSION" as mysqld --nice=NICE Set the scheduling priority of mysqld @@ -253,6 +254,12 @@ parse_arguments() { ledir="$val" ;; --malloc-lib=*) set_malloc_lib "$val" ;; + --ld-preload-lib=*) + if [ -z "$pick_args" ]; then + log_error "--ld-preload-lib option can only be used as command line option, found in config file" + exit 1 + fi + add_mysqld_ld_preload "$val" ;; --mysqld=*) if [ -z "$pick_args" ]; then log_error "--mysqld option can only be used as command line option, found in config file" @@ -324,6 +331,12 @@ add_mysqld_ld_preload() { ;; esac + # Do not add if file does not exist. + if [ ! -f "$lib_to_add" ]; then + log_error "no shared library found for $lib_to_add" + return + fi + # 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" @@ -883,8 +896,11 @@ fi # ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems #fi -cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS" +cmd="$NOHUP_NICENESS" +if [ ! -z "`mysqld_ld_preload_text`" ]; then + cmd="$cmd env `mysqld_ld_preload_text`" +fi for i in "$ledir/$MYSQLD" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \ "--datadir=$DATADIR" "--plugin-dir=$plugin_dir" "$USER_OPTION" do