From fe05c16c8d6d9ff90186578cdc3db460469e4fe1 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 30 Jun 2020 12:45:37 +0200 Subject: [PATCH 1/4] MDEV-23052 mysql_install_db.exe can run on existing non-empty directory, and remove it on error Disable existing non-empty datadir for mysql_install_db.exe --- sql/mysql_install_db.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index c6912e41f6e..022ba18a3e3 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -399,8 +399,8 @@ static int register_service() static void clean_directory(const char *dir) { - char dir2[MAX_PATH+2]; - *(strmake_buf(dir2, dir)+1)= 0; + char dir2[MAX_PATH + 4]= {}; + snprintf(dir2, MAX_PATH+2, "%s\\*", dir); SHFILEOPSTRUCT fileop; fileop.hwnd= NULL; /* no status display */ @@ -551,7 +551,7 @@ static int create_db_instance() DWORD cwd_len= MAX_PATH; char cmdline[3*MAX_PATH]; FILE *in; - bool cleanup_datadir= true; + bool created_datadir= false; DWORD last_error; verbose("Running bootstrap"); @@ -560,7 +560,11 @@ static int create_db_instance() /* Create datadir and datadir/mysql, if they do not already exist. */ - if (!CreateDirectory(opt_datadir, NULL) && (GetLastError() != ERROR_ALREADY_EXISTS)) + if (CreateDirectory(opt_datadir, NULL)) + { + created_datadir= true; + } + else if (GetLastError() != ERROR_ALREADY_EXISTS) { last_error = GetLastError(); switch(last_error) @@ -597,9 +601,11 @@ static int create_db_instance() } } - if (PathIsDirectoryEmpty(opt_datadir)) + if (!PathIsDirectoryEmpty(opt_datadir)) { - cleanup_datadir= false; + fprintf(stderr,"ERROR : Data directory %s is not empty." + " Only new or empty existing directories are accepted for --datadir\n",opt_datadir); + exit(1); } if (!CreateDirectory("mysql",NULL)) @@ -735,10 +741,12 @@ static int create_db_instance() } end: - if (ret && cleanup_datadir) + if (ret) { SetCurrentDirectory(cwd); clean_directory(opt_datadir); + if (created_datadir) + RemoveDirectory(opt_datadir); } return ret; } From 41b0d98e69740f6d894a369a83efbbe5f7bffdfd Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 1 Jul 2020 18:43:21 +0200 Subject: [PATCH 2/4] MDEV-23067 Windows : manually registered services rejected mysql_upgrade_service - service not using "--defaults-file" can have any name not just "MySQL" - service with "--defaults-file", without datadir in them use default datadir (install_root\data) --- sql/winservice.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/sql/winservice.c b/sql/winservice.c index d9605f3a6c4..fe1fb0cb2bb 100644 --- a/sql/winservice.c +++ b/sql/winservice.c @@ -150,10 +150,7 @@ int get_mysql_service_properties(const wchar_t *bin_path, There are rare cases where service config does not have --defaults-filein the binary parth . There services were registered with plain mysqld --install, the data directory is next to "bin" in this case. - Service name (second parameter) must be MySQL. */ - if(wcscmp(args[1], L"MySQL") != 0) - goto end; have_inifile= FALSE; } else if(numargs == 3) @@ -211,7 +208,7 @@ int get_mysql_service_properties(const wchar_t *bin_path, } } - if(!have_inifile) + if(!have_inifile || props->datadir[0] == 0) { /* Hard, although a rare case, we're guessing datadir and defaults-file. @@ -235,22 +232,25 @@ int get_mysql_service_properties(const wchar_t *bin_path, *p= 0; } - /* Look for my.ini, my.cnf in the install root */ - sprintf_s(props->inifile, MAX_PATH, "%s\\my.ini", install_root); - if (GetFileAttributes(props->inifile) == INVALID_FILE_ATTRIBUTES) + if (!have_inifile) { - sprintf_s(props->inifile, MAX_PATH, "%s\\my.cnf", install_root); - } - if (GetFileAttributes(props->inifile) != INVALID_FILE_ATTRIBUTES) - { - /* Ini file found, get datadir from there */ - GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir, - MAX_PATH, props->inifile); - } - else - { - /* No ini file */ - props->inifile[0]= 0; + /* Look for my.ini, my.cnf in the install root */ + sprintf_s(props->inifile, MAX_PATH, "%s\\my.ini", install_root); + if (GetFileAttributes(props->inifile) == INVALID_FILE_ATTRIBUTES) + { + sprintf_s(props->inifile, MAX_PATH, "%s\\my.cnf", install_root); + } + if (GetFileAttributes(props->inifile) != INVALID_FILE_ATTRIBUTES) + { + /* Ini file found, get datadir from there */ + GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir, + MAX_PATH, props->inifile); + } + else + { + /* No ini file */ + props->inifile[0]= 0; + } } /* Try datadir in install directory.*/ From 90d1e58ed0a148cf850f187e948e9ca24ab3a88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 2 Jul 2020 06:04:31 +0300 Subject: [PATCH 3/4] MDEV-22941: Fix the DBUG_ENTER name --- sql/sql_show.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 70cab968f43..8eba6ef6027 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2015, Oracle and/or its affiliates. - Copyright (c) 2009, 2017, MariaDB + Copyright (c) 2009, 2020, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -4962,16 +4962,16 @@ bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name, */ static bool verify_database_directory_exists(const LEX_STRING &dbname) { - DBUG_ENTER("verity_database_exists"); + DBUG_ENTER("verify_database_directory_exists"); char path[FN_REFLEN + 16]; uint path_len; MY_STAT stat_info; if (!dbname.str[0]) - DBUG_RETURN(true); // Empty database name: does not exits. + DBUG_RETURN(true); // Empty database name: does not exist. path_len= build_table_filename(path, sizeof(path) - 1, dbname.str, "", "", 0); path[path_len - 1]= 0; if (!mysql_file_stat(key_file_misc, path, &stat_info, MYF(0))) - DBUG_RETURN(true); // The database directory was not found: does not exists. + DBUG_RETURN(true); // The database directory was not found: does not exist. DBUG_RETURN(false); // The database directory was found. } From c43a666662ac71e70bde83e6673ebcb2811887af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 2 Jul 2020 06:04:42 +0300 Subject: [PATCH 4/4] Revert "Fix result of merge." This reverts commit e0793d386517f4ff9c0267830d558f91c75263aa. In idiomatic C++, accessor functions should not discard qualifiers. --- sql/sql_class.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sql/sql_class.h b/sql/sql_class.h index 4d14b42b065..7ca3896a69d 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3408,7 +3408,11 @@ public: inline bool is_error() const { return m_stmt_da->is_error(); } /// Returns Diagnostics-area for the current statement. - Diagnostics_area *get_stmt_da() const + Diagnostics_area *get_stmt_da() + { return m_stmt_da; } + + /// Returns Diagnostics-area for the current statement. + const Diagnostics_area *get_stmt_da() const { return m_stmt_da; } /// Sets Diagnostics-area for the current statement.