Skip to content

Commit

Permalink
Merge 10.5 into 10.6
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Sep 30, 2021
2 parents 260649d + be803f0 commit a49e394
Show file tree
Hide file tree
Showing 49 changed files with 819 additions and 600 deletions.
100 changes: 47 additions & 53 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ static my_bool non_blocking_api_enabled= 0;
#include "../tests/nonblock-wrappers.h"
#endif

/* Use cygwin for --exec and --system before 5.0 */
#if MYSQL_VERSION_ID < 50000
#define USE_CYGWIN
#endif

#define MAX_VAR_NAME_LENGTH 256
#define MAX_COLUMNS 256
Expand Down Expand Up @@ -619,7 +615,6 @@ const char *get_errname_from_code (uint error_code);
int multi_reg_replace(struct st_replace_regex* r,char* val);

#ifdef _WIN32
void free_tmp_sh_file();
void free_win_path_patterns();
#endif

Expand Down Expand Up @@ -1457,7 +1452,6 @@ void free_used_memory()
free_re();
my_free(read_command_buf);
#ifdef _WIN32
free_tmp_sh_file();
free_win_path_patterns();
#endif
DBUG_VOID_RETURN;
Expand Down Expand Up @@ -3199,33 +3193,6 @@ void do_source(struct st_command *command)
}


#if defined _WIN32

#ifdef USE_CYGWIN
/* Variables used for temporary sh files used for emulating Unix on Windows */
char tmp_sh_name[64], tmp_sh_cmd[70];
#endif

void init_tmp_sh_file()
{
#ifdef USE_CYGWIN
/* Format a name for the tmp sh file that is unique for this process */
my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid());
/* Format the command to execute in order to run the script */
my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name);
#endif
}


void free_tmp_sh_file()
{
#ifdef USE_CYGWIN
my_delete(tmp_sh_name, MYF(0));
#endif
}
#endif


static void init_builtin_echo(void)
{
#ifdef _WIN32
Expand Down Expand Up @@ -3341,14 +3308,12 @@ void do_exec(struct st_command *command)
}

#ifdef _WIN32
#ifndef USE_CYGWIN
/* Replace /dev/null with NUL */
while(replace(&ds_cmd, "/dev/null", 9, "NUL", 3) == 0)
;
/* Replace "closed stdout" with non existing output fd */
while(replace(&ds_cmd, ">&-", 3, ">&4", 3) == 0)
;
#endif
#endif

if (disable_result_log)
Expand Down Expand Up @@ -3507,13 +3472,7 @@ int do_modify_var(struct st_command *command,

int my_system(DYNAMIC_STRING* ds_cmd)
{
#if defined _WIN32 && defined USE_CYGWIN
/* Dump the command into a sh script file and execute with system */
str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length);
return system(tmp_sh_cmd);
#else
return system(ds_cmd->str);
#endif
}


Expand Down Expand Up @@ -3547,12 +3506,10 @@ void do_system(struct st_command *command)
do_eval(&ds_cmd, command->first_argument, command->end, !is_windows);

#ifdef _WIN32
#ifndef USE_CYGWIN
/* Replace /dev/null with NUL */
while(replace(&ds_cmd, "/dev/null", 9, "NUL", 3) == 0)
;
#endif
#endif


DBUG_PRINT("info", ("running system command '%s' as '%s'",
Expand Down Expand Up @@ -5022,13 +4979,34 @@ int query_get_string(MYSQL* mysql, const char* query,
}


#ifdef _WIN32
#define SIGKILL 9
#include <my_minidump.h>
static int my_kill(int pid, int sig)
{
DBUG_PRINT("info", ("Killing server, pid: %d", pid));
#ifdef _WIN32
#define SIGKILL 9 /* ignored anyway, see below */
HANDLE proc;
if ((proc= OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid)) == NULL)
if (sig == SIGABRT)
{
/*
Create a minidump. If process is being debugged, debug break
Otherwise, terminate.
*/
verbose_msg("Aborting %d",pid);
my_create_minidump(pid,TRUE);
proc= OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if(!proc)
return -1;
BOOL debugger_present;
if (CheckRemoteDebuggerPresent(proc,&debugger_present) && debugger_present)
{
if (DebugBreakProcess(proc))
{
CloseHandle(proc);
return 0;
}
}
}
else if ((proc= OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid)) == NULL)
return -1;
if (sig == 0)
{
Expand All @@ -5039,12 +5017,30 @@ static int my_kill(int pid, int sig)
(void)TerminateProcess(proc, 201);
CloseHandle(proc);
return 1;
#else
return kill(pid, sig);
#endif
}


/* Wait until process is gone, with timeout */
static int wait_until_dead(int pid, int timeout)
{
HANDLE proc= OpenProcess(SYNCHRONIZE, FALSE, pid);
if (!proc)
return 0; /* already dead */
DBUG_ASSERT(timeout >= 0);
DBUG_ASSERT(timeout <= UINT_MAX/1000);
DWORD wait_result= WaitForSingleObject(proc, (DWORD)timeout*1000);
CloseHandle(proc);
return (int)wait_result;
}

#else /* !_WIN32 */


static int my_kill(int pid, int sig)
{
DBUG_PRINT("info", ("Killing server, pid: %d", pid));
return kill(pid, sig);
}

/*
Shutdown the server of current connection and
Expand Down Expand Up @@ -5079,6 +5075,7 @@ static int wait_until_dead(int pid, int timeout)
}
DBUG_RETURN(1); // Did not die
}
#endif /* _WIN32 */


void do_shutdown_server(struct st_command *command)
Expand Down Expand Up @@ -9231,10 +9228,7 @@ int main(int argc, char **argv)

init_builtin_echo();
#ifdef _WIN32
#ifndef USE_CYGWIN
is_windows= 1;
#endif
init_tmp_sh_file();
init_win_path_patterns();
#endif

Expand Down
25 changes: 25 additions & 0 deletions include/my_minidump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright (c) 2021, MariaDB Corporation
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
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */

#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif

BOOL my_create_minidump(DWORD pid, BOOL verbose);

#ifdef __cplusplus
}
#endif
3 changes: 3 additions & 0 deletions libmysqld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
ADD_CONVENIENCE_LIBRARY(sql_embedded ${SQL_EMBEDDED_SOURCES})
DTRACE_INSTRUMENT(sql_embedded)
ADD_DEPENDENCIES(sql_embedded GenError GenServerSource)
IF(TARGET pcre2)
ADD_DEPENDENCIES(sql_embedded pcre2)
ENDIF()

# On Windows, static embedded server library is called mysqlserver.lib
# On Unix, it is libmysqld.a
Expand Down
3 changes: 2 additions & 1 deletion mysql-test/lib/My/SafeProcess/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
IF (WIN32)
ADD_EXECUTABLE(my_safe_process safe_process_win.cc)
ADD_EXECUTABLE(my_safe_kill safe_kill_win.cc)
TARGET_LINK_LIBRARIES(my_safe_kill dbghelp psapi)
TARGET_INCLUDE_DIRECTORIES(my_safe_kill PRIVATE ${CMAKE_SOURCE_DIR}/include)
TARGET_LINK_LIBRARIES(my_safe_kill mysys psapi)
ELSE()
ADD_EXECUTABLE(my_safe_process safe_process.cc)
ENDIF()
Expand Down
109 changes: 2 additions & 107 deletions mysql-test/lib/My/SafeProcess/safe_kill_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,7 @@
#include <signal.h>
#include <stdlib.h>
#include <psapi.h>

#ifdef _MSC_VER
/* Silence warning in OS header dbghelp.h */
#pragma warning(push)
#pragma warning(disable : 4091)
#endif

#include <dbghelp.h>

#ifdef _MSC_VER
/* Silence warning in OS header dbghelp.h */
#pragma warning(pop)
#endif
#include <my_minidump.h>

#include <tlhelp32.h>
#include <vector>
Expand All @@ -64,106 +52,13 @@ static std::vector<DWORD> find_children(DWORD pid)
return children;
}

void dump_single_process(DWORD pid)
{
HANDLE file = 0;
HANDLE process= 0;
DWORD size= MAX_PATH;
char path[MAX_PATH];
char working_dir[MAX_PATH];
char tmpname[MAX_PATH];
char *filename= 0;

process= OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (!process)
{
fprintf(stderr, "safe_kill : cannot open process pid=%lu to create dump, last error %lu\n",
pid, GetLastError());
goto exit;
}

if (QueryFullProcessImageName(process, 0, path, &size) == 0)
{
fprintf(stderr, "safe_kill : cannot read process path for pid %lu, last error %lu\n",
pid, GetLastError());
goto exit;
}

filename= strrchr(path, '\\');
if (filename)
{
filename++;
// We are not interested in dump of some proceses (my_safe_process.exe,cmd.exe)
// since they are only used to start up other programs.
// We're interested however in their children;
const char *exclude_programs[] = {"my_safe_process.exe","cmd.exe", 0};
for(size_t i=0; exclude_programs[i]; i++)
if (_stricmp(filename, exclude_programs[i]) == 0)
goto exit;
}
else
filename= path;

// Add .dmp extension
char *p;
if ((p= strrchr(filename, '.')) == 0)
p= filename + strlen(filename);

strncpy(p, ".dmp", path + MAX_PATH - p);

// Íf file with this name exist, generate unique name with .dmp extension
if (GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES)
{
if (!GetTempFileName(".", filename, 0, tmpname))
{
fprintf(stderr, "GetTempFileName failed, last error %lu", GetLastError());
goto exit;
}
strncat_s(tmpname, ".dmp", sizeof(tmpname));
filename= tmpname;
}


if (!GetCurrentDirectory(MAX_PATH, working_dir))
{
fprintf(stderr, "GetCurrentDirectory failed, last error %lu", GetLastError());
goto exit;
}

file= CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

if (file == INVALID_HANDLE_VALUE)
{
fprintf(stderr, "safe_kill : CreateFile() failed for file %s, working dir %s, last error = %lu\n",
filename, working_dir, GetLastError());
goto exit;
}

if (!MiniDumpWriteDump(process, pid, file, MiniDumpNormal, 0, 0, 0))
{
fprintf(stderr, "Failed to write minidump to %s, working dir %s, last error %lu\n",
filename, working_dir, GetLastError());
goto exit;
}

fprintf(stderr, "Minidump written to %s, directory %s\n", filename, working_dir);

exit:
if (process != 0 && process != INVALID_HANDLE_VALUE)
CloseHandle(process);

if (file != 0 && file != INVALID_HANDLE_VALUE)
CloseHandle(file);
}


static int create_dump(DWORD pid, int recursion_depth= 5)
{
if (recursion_depth < 0)
return 0;

dump_single_process(pid);
my_create_minidump(pid, TRUE);
std::vector<DWORD> children= find_children(pid);
for(size_t i=0; i < children.size(); i++)
create_dump(children[i], recursion_depth -1);
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/main/errors.result
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ SELECT 4;
END IF ;
END"where name = "P1";
show create procedure P1;
ERROR HY000: Failed to load routine test.P1 (internal code -6). For more details, run SHOW WARNINGS
ERROR 42000: Undeclared variable: foo
show warnings;
Level Code Message
Error 1327 Undeclared variable: foo
Error 1457 Failed to load routine test.P1 (internal code -6). For more details, run SHOW WARNINGS
Error 1305 PROCEDURE P1 does not exist
drop procedure P1;
# End of 10.4 tests
2 changes: 1 addition & 1 deletion mysql-test/main/errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ SELECT 4;
END IF ;
END"where name = "P1";

--error ER_SP_PROC_TABLE_CORRUPT
--error ER_SP_UNDECLARED_VAR
show create procedure P1;
show warnings;

Expand Down
Loading

0 comments on commit a49e394

Please sign in to comment.