From 805b94068d34b9cd591b7c3baca5b0102ae44f81 Mon Sep 17 00:00:00 2001 From: Siva Kommuri Date: Thu, 16 Jan 2020 16:05:26 -0800 Subject: [PATCH 1/2] Fix git signoff pre-commit hook The confirmation for the signoff prompt wasn't being processed. Signed-off-by: Siva Kommuri --- misc/git/commit-msg.signoff | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/misc/git/commit-msg.signoff b/misc/git/commit-msg.signoff index 82dc688a545..cf9e4dc097c 100755 --- a/misc/git/commit-msg.signoff +++ b/misc/git/commit-msg.signoff @@ -52,9 +52,10 @@ echo "Alternatively, you can acknowledge your signoff and continue below:" echo echo " ${signoff}" echo -read -r -p "Do you want to add the above signoff and continue? [y/N] " +echo -n "Do you want to add the above signoff and continue? [y/N] " +read reply -if [[ "${REPLY,,}" != "y" ]]; then +if [[ "${reply}" != "y" ]]; then exit 1 fi From 180f7ae336862c36a17160a95da463798059ab9c Mon Sep 17 00:00:00 2001 From: Siva Kommuri Date: Thu, 16 Jan 2020 16:18:19 -0800 Subject: [PATCH 2/2] Add LD_PRELOAD env var when starting mysql related scripts * Build the LD_LIBRARY_PATH environment variable in a new function * Inherit LD_PRELOAD as an environment variable for all mysql* commands Signed-off-by: Siva Kommuri --- go.mod | 2 -- go/vt/mysqlctl/mysqld.go | 76 +++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 50a70afd81e..69df93ab293 100644 --- a/go.mod +++ b/go.mod @@ -50,8 +50,6 @@ require ( github.com/mattn/go-runewidth v0.0.1 // indirect github.com/minio/minio-go v0.0.0-20190131015406-c8a261de75c1 github.com/mitchellh/go-testing-interface v1.0.0 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.1 // indirect github.com/olekukonko/tablewriter v0.0.0-20160115111002-cca8bbc07984 github.com/opentracing-contrib/go-grpc v0.0.0-20180928155321-4b5a12d3ff02 github.com/opentracing/opentracing-go v1.1.0 diff --git a/go/vt/mysqlctl/mysqld.go b/go/vt/mysqlctl/mysqld.go index afc40ae5268..6b6161be0b4 100644 --- a/go/vt/mysqlctl/mysqld.go +++ b/go/vt/mysqlctl/mysqld.go @@ -267,18 +267,6 @@ func (mysqld *Mysqld) RunMysqlUpgrade() error { return nil } - // Find mysql_upgrade. If not there, we do nothing. - vtMysqlRoot, err := vtenv.VtMysqlRoot() - if err != nil { - log.Warningf("VT_MYSQL_ROOT not set, skipping mysql_upgrade step: %v", err) - return nil - } - name, err := binaryPath(vtMysqlRoot, "mysql_upgrade") - if err != nil { - log.Warningf("mysql_upgrade binary not present, skipping it: %v", err) - return nil - } - // Since we started mysql with --skip-grant-tables, we should // be able to run mysql_upgrade without any valid user or // password. However, mysql_upgrade executes a 'flush @@ -303,11 +291,26 @@ func (mysqld *Mysqld) RunMysqlUpgrade() error { "--defaults-file=" + defaultsFile, "--force", // Don't complain if it's already been upgraded. } - cmd := exec.Command(name, args...) - libPath := fmt.Sprintf("LD_LIBRARY_PATH=%s/lib/mysql", vtMysqlRoot) - cmd.Env = []string{libPath} - out, err := cmd.CombinedOutput() - log.Infof("mysql_upgrade output: %s", out) + + // Find mysql_upgrade. If not there, we do nothing. + vtMysqlRoot, err := vtenv.VtMysqlRoot() + if err != nil { + log.Warningf("VT_MYSQL_ROOT not set, skipping mysql_upgrade step: %v", err) + return nil + } + name, err := binaryPath(vtMysqlRoot, "mysql_upgrade") + if err != nil { + log.Warningf("mysql_upgrade binary not present, skipping it: %v", err) + return nil + } + + env, err := buildLdPaths() + if err != nil { + log.Warningf("skipping mysql_upgrade step: %v", err) + return nil + } + + _, _, err = execCmd(name, args, env, "", nil) return err } @@ -367,15 +370,17 @@ func (mysqld *Mysqld) startNoWait(ctx context.Context, cnf *Mycnf, mysqldArgs .. if err != nil { return err } - arg := []string{ + args := []string{ "--defaults-file=" + cnf.path, "--basedir=" + mysqlBaseDir, } - arg = append(arg, mysqldArgs...) - libPath := fmt.Sprintf("LD_LIBRARY_PATH=%s/lib/mysql", vtMysqlRoot) - env := []string{libPath} + args = append(args, mysqldArgs...) + env, err := buildLdPaths() + if err != nil { + return err + } - cmd := exec.Command(name, arg...) + cmd := exec.Command(name, args...) cmd.Dir = vtMysqlRoot cmd.Env = env log.Infof("%v %#v", ts, cmd) @@ -541,13 +546,13 @@ func (mysqld *Mysqld) Shutdown(ctx context.Context, cnf *Mycnf, waitForMysqld bo "--wait=10", "shutdown", } - env := []string{ - os.ExpandEnv("LD_LIBRARY_PATH=$VT_MYSQL_ROOT/lib/mysql"), - } - _, _, err = execCmd(name, args, env, dir, nil) + env, err := buildLdPaths() if err != nil { return err } + if _, _, err = execCmd(name, args, env, dir, nil); err != nil { + return err + } default: // hook failed, we report error return fmt.Errorf("mysqld_shutdown hook failed: %v", hr.String()) @@ -1027,8 +1032,9 @@ func (mysqld *Mysqld) executeMysqlScript(connParams *mysql.ConnParams, sql io.Re "--defaults-extra-file=" + cnf, "--batch", } - env := []string{ - "LD_LIBRARY_PATH=" + path.Join(dir, "lib/mysql"), + env, err := buildLdPaths() + if err != nil { + return err } _, _, err = execCmd(name, args, env, dir, sql) if err != nil { @@ -1115,3 +1121,17 @@ func (mysqld *Mysqld) OnTerm(f func()) { defer mysqld.mutex.Unlock() mysqld.onTermFuncs = append(mysqld.onTermFuncs, f) } + +func buildLdPaths() ([]string, error) { + vtMysqlRoot, err := vtenv.VtMysqlRoot() + if err != nil { + return []string{}, err + } + + ldPaths := []string{ + fmt.Sprintf("LD_LIBRARY_PATH=%s/lib/mysql", vtMysqlRoot), + os.ExpandEnv("LD_PRELOAD=$LD_PRELOAD"), + } + + return ldPaths, nil +}