Skip to content

Commit a49e394

Browse files
committed
Merge 10.5 into 10.6
2 parents 260649d + be803f0 commit a49e394

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+819
-600
lines changed

client/mysqltest.cc

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ static my_bool non_blocking_api_enabled= 0;
7171
#include "../tests/nonblock-wrappers.h"
7272
#endif
7373

74-
/* Use cygwin for --exec and --system before 5.0 */
75-
#if MYSQL_VERSION_ID < 50000
76-
#define USE_CYGWIN
77-
#endif
7874

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

621617
#ifdef _WIN32
622-
void free_tmp_sh_file();
623618
void free_win_path_patterns();
624619
#endif
625620

@@ -1457,7 +1452,6 @@ void free_used_memory()
14571452
free_re();
14581453
my_free(read_command_buf);
14591454
#ifdef _WIN32
1460-
free_tmp_sh_file();
14611455
free_win_path_patterns();
14621456
#endif
14631457
DBUG_VOID_RETURN;
@@ -3199,33 +3193,6 @@ void do_source(struct st_command *command)
31993193
}
32003194

32013195

3202-
#if defined _WIN32
3203-
3204-
#ifdef USE_CYGWIN
3205-
/* Variables used for temporary sh files used for emulating Unix on Windows */
3206-
char tmp_sh_name[64], tmp_sh_cmd[70];
3207-
#endif
3208-
3209-
void init_tmp_sh_file()
3210-
{
3211-
#ifdef USE_CYGWIN
3212-
/* Format a name for the tmp sh file that is unique for this process */
3213-
my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid());
3214-
/* Format the command to execute in order to run the script */
3215-
my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name);
3216-
#endif
3217-
}
3218-
3219-
3220-
void free_tmp_sh_file()
3221-
{
3222-
#ifdef USE_CYGWIN
3223-
my_delete(tmp_sh_name, MYF(0));
3224-
#endif
3225-
}
3226-
#endif
3227-
3228-
32293196
static void init_builtin_echo(void)
32303197
{
32313198
#ifdef _WIN32
@@ -3341,14 +3308,12 @@ void do_exec(struct st_command *command)
33413308
}
33423309

33433310
#ifdef _WIN32
3344-
#ifndef USE_CYGWIN
33453311
/* Replace /dev/null with NUL */
33463312
while(replace(&ds_cmd, "/dev/null", 9, "NUL", 3) == 0)
33473313
;
33483314
/* Replace "closed stdout" with non existing output fd */
33493315
while(replace(&ds_cmd, ">&-", 3, ">&4", 3) == 0)
33503316
;
3351-
#endif
33523317
#endif
33533318

33543319
if (disable_result_log)
@@ -3507,13 +3472,7 @@ int do_modify_var(struct st_command *command,
35073472

35083473
int my_system(DYNAMIC_STRING* ds_cmd)
35093474
{
3510-
#if defined _WIN32 && defined USE_CYGWIN
3511-
/* Dump the command into a sh script file and execute with system */
3512-
str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length);
3513-
return system(tmp_sh_cmd);
3514-
#else
35153475
return system(ds_cmd->str);
3516-
#endif
35173476
}
35183477

35193478

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

35493508
#ifdef _WIN32
3550-
#ifndef USE_CYGWIN
35513509
/* Replace /dev/null with NUL */
35523510
while(replace(&ds_cmd, "/dev/null", 9, "NUL", 3) == 0)
35533511
;
35543512
#endif
3555-
#endif
35563513

35573514

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

50244981

4982+
#ifdef _WIN32
4983+
#define SIGKILL 9
4984+
#include <my_minidump.h>
50254985
static int my_kill(int pid, int sig)
50264986
{
5027-
DBUG_PRINT("info", ("Killing server, pid: %d", pid));
5028-
#ifdef _WIN32
5029-
#define SIGKILL 9 /* ignored anyway, see below */
50304987
HANDLE proc;
5031-
if ((proc= OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid)) == NULL)
4988+
if (sig == SIGABRT)
4989+
{
4990+
/*
4991+
Create a minidump. If process is being debugged, debug break
4992+
Otherwise, terminate.
4993+
*/
4994+
verbose_msg("Aborting %d",pid);
4995+
my_create_minidump(pid,TRUE);
4996+
proc= OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
4997+
if(!proc)
4998+
return -1;
4999+
BOOL debugger_present;
5000+
if (CheckRemoteDebuggerPresent(proc,&debugger_present) && debugger_present)
5001+
{
5002+
if (DebugBreakProcess(proc))
5003+
{
5004+
CloseHandle(proc);
5005+
return 0;
5006+
}
5007+
}
5008+
}
5009+
else if ((proc= OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid)) == NULL)
50325010
return -1;
50335011
if (sig == 0)
50345012
{
@@ -5039,12 +5017,30 @@ static int my_kill(int pid, int sig)
50395017
(void)TerminateProcess(proc, 201);
50405018
CloseHandle(proc);
50415019
return 1;
5042-
#else
5043-
return kill(pid, sig);
5044-
#endif
50455020
}
50465021

50475022

5023+
/* Wait until process is gone, with timeout */
5024+
static int wait_until_dead(int pid, int timeout)
5025+
{
5026+
HANDLE proc= OpenProcess(SYNCHRONIZE, FALSE, pid);
5027+
if (!proc)
5028+
return 0; /* already dead */
5029+
DBUG_ASSERT(timeout >= 0);
5030+
DBUG_ASSERT(timeout <= UINT_MAX/1000);
5031+
DWORD wait_result= WaitForSingleObject(proc, (DWORD)timeout*1000);
5032+
CloseHandle(proc);
5033+
return (int)wait_result;
5034+
}
5035+
5036+
#else /* !_WIN32 */
5037+
5038+
5039+
static int my_kill(int pid, int sig)
5040+
{
5041+
DBUG_PRINT("info", ("Killing server, pid: %d", pid));
5042+
return kill(pid, sig);
5043+
}
50485044

50495045
/*
50505046
Shutdown the server of current connection and
@@ -5079,6 +5075,7 @@ static int wait_until_dead(int pid, int timeout)
50795075
}
50805076
DBUG_RETURN(1); // Did not die
50815077
}
5078+
#endif /* _WIN32 */
50825079

50835080

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

92329229
init_builtin_echo();
92339230
#ifdef _WIN32
9234-
#ifndef USE_CYGWIN
92359231
is_windows= 1;
9236-
#endif
9237-
init_tmp_sh_file();
92389232
init_win_path_patterns();
92399233
#endif
92409234

include/my_minidump.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Copyright (c) 2021, MariaDB Corporation
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
15+
16+
#include <windows.h>
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
BOOL my_create_minidump(DWORD pid, BOOL verbose);
22+
23+
#ifdef __cplusplus
24+
}
25+
#endif

libmysqld/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
145145
ADD_CONVENIENCE_LIBRARY(sql_embedded ${SQL_EMBEDDED_SOURCES})
146146
DTRACE_INSTRUMENT(sql_embedded)
147147
ADD_DEPENDENCIES(sql_embedded GenError GenServerSource)
148+
IF(TARGET pcre2)
149+
ADD_DEPENDENCIES(sql_embedded pcre2)
150+
ENDIF()
148151

149152
# On Windows, static embedded server library is called mysqlserver.lib
150153
# On Unix, it is libmysqld.a

mysql-test/lib/My/SafeProcess/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
1919
IF (WIN32)
2020
ADD_EXECUTABLE(my_safe_process safe_process_win.cc)
2121
ADD_EXECUTABLE(my_safe_kill safe_kill_win.cc)
22-
TARGET_LINK_LIBRARIES(my_safe_kill dbghelp psapi)
22+
TARGET_INCLUDE_DIRECTORIES(my_safe_kill PRIVATE ${CMAKE_SOURCE_DIR}/include)
23+
TARGET_LINK_LIBRARIES(my_safe_kill mysys psapi)
2324
ELSE()
2425
ADD_EXECUTABLE(my_safe_process safe_process.cc)
2526
ENDIF()

mysql-test/lib/My/SafeProcess/safe_kill_win.cc

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,7 @@
2626
#include <signal.h>
2727
#include <stdlib.h>
2828
#include <psapi.h>
29-
30-
#ifdef _MSC_VER
31-
/* Silence warning in OS header dbghelp.h */
32-
#pragma warning(push)
33-
#pragma warning(disable : 4091)
34-
#endif
35-
36-
#include <dbghelp.h>
37-
38-
#ifdef _MSC_VER
39-
/* Silence warning in OS header dbghelp.h */
40-
#pragma warning(pop)
41-
#endif
29+
#include <my_minidump.h>
4230

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

67-
void dump_single_process(DWORD pid)
68-
{
69-
HANDLE file = 0;
70-
HANDLE process= 0;
71-
DWORD size= MAX_PATH;
72-
char path[MAX_PATH];
73-
char working_dir[MAX_PATH];
74-
char tmpname[MAX_PATH];
75-
char *filename= 0;
76-
77-
process= OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
78-
if (!process)
79-
{
80-
fprintf(stderr, "safe_kill : cannot open process pid=%lu to create dump, last error %lu\n",
81-
pid, GetLastError());
82-
goto exit;
83-
}
84-
85-
if (QueryFullProcessImageName(process, 0, path, &size) == 0)
86-
{
87-
fprintf(stderr, "safe_kill : cannot read process path for pid %lu, last error %lu\n",
88-
pid, GetLastError());
89-
goto exit;
90-
}
91-
92-
filename= strrchr(path, '\\');
93-
if (filename)
94-
{
95-
filename++;
96-
// We are not interested in dump of some proceses (my_safe_process.exe,cmd.exe)
97-
// since they are only used to start up other programs.
98-
// We're interested however in their children;
99-
const char *exclude_programs[] = {"my_safe_process.exe","cmd.exe", 0};
100-
for(size_t i=0; exclude_programs[i]; i++)
101-
if (_stricmp(filename, exclude_programs[i]) == 0)
102-
goto exit;
103-
}
104-
else
105-
filename= path;
106-
107-
// Add .dmp extension
108-
char *p;
109-
if ((p= strrchr(filename, '.')) == 0)
110-
p= filename + strlen(filename);
111-
112-
strncpy(p, ".dmp", path + MAX_PATH - p);
113-
114-
// Íf file with this name exist, generate unique name with .dmp extension
115-
if (GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES)
116-
{
117-
if (!GetTempFileName(".", filename, 0, tmpname))
118-
{
119-
fprintf(stderr, "GetTempFileName failed, last error %lu", GetLastError());
120-
goto exit;
121-
}
122-
strncat_s(tmpname, ".dmp", sizeof(tmpname));
123-
filename= tmpname;
124-
}
125-
126-
127-
if (!GetCurrentDirectory(MAX_PATH, working_dir))
128-
{
129-
fprintf(stderr, "GetCurrentDirectory failed, last error %lu", GetLastError());
130-
goto exit;
131-
}
132-
133-
file= CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
134-
0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
135-
136-
if (file == INVALID_HANDLE_VALUE)
137-
{
138-
fprintf(stderr, "safe_kill : CreateFile() failed for file %s, working dir %s, last error = %lu\n",
139-
filename, working_dir, GetLastError());
140-
goto exit;
141-
}
142-
143-
if (!MiniDumpWriteDump(process, pid, file, MiniDumpNormal, 0, 0, 0))
144-
{
145-
fprintf(stderr, "Failed to write minidump to %s, working dir %s, last error %lu\n",
146-
filename, working_dir, GetLastError());
147-
goto exit;
148-
}
149-
150-
fprintf(stderr, "Minidump written to %s, directory %s\n", filename, working_dir);
151-
152-
exit:
153-
if (process != 0 && process != INVALID_HANDLE_VALUE)
154-
CloseHandle(process);
155-
156-
if (file != 0 && file != INVALID_HANDLE_VALUE)
157-
CloseHandle(file);
158-
}
159-
16055

16156
static int create_dump(DWORD pid, int recursion_depth= 5)
16257
{
16358
if (recursion_depth < 0)
16459
return 0;
16560

166-
dump_single_process(pid);
61+
my_create_minidump(pid, TRUE);
16762
std::vector<DWORD> children= find_children(pid);
16863
for(size_t i=0; i < children.size(); i++)
16964
create_dump(children[i], recursion_depth -1);

mysql-test/main/errors.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ SELECT 4;
224224
END IF ;
225225
END"where name = "P1";
226226
show create procedure P1;
227-
ERROR HY000: Failed to load routine test.P1 (internal code -6). For more details, run SHOW WARNINGS
227+
ERROR 42000: Undeclared variable: foo
228228
show warnings;
229229
Level Code Message
230230
Error 1327 Undeclared variable: foo
231-
Error 1457 Failed to load routine test.P1 (internal code -6). For more details, run SHOW WARNINGS
231+
Error 1305 PROCEDURE P1 does not exist
232232
drop procedure P1;
233233
# End of 10.4 tests

mysql-test/main/errors.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ SELECT 4;
275275
END IF ;
276276
END"where name = "P1";
277277

278-
--error ER_SP_PROC_TABLE_CORRUPT
278+
--error ER_SP_UNDECLARED_VAR
279279
show create procedure P1;
280280
show warnings;
281281

0 commit comments

Comments
 (0)