@@ -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);
619615int multi_reg_replace (struct st_replace_regex * r,char * val);
620616
621617#ifdef _WIN32
622- void free_tmp_sh_file ();
623618void 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-
32293196static 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
35083473int 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>
50254985static 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
50845081void 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
0 commit comments