summaryrefslogtreecommitdiff
path: root/mysql-test/lib/My/SafeProcess
diff options
context:
space:
mode:
authorunknown <msvensson@pilot.mysql.com>2008-03-10 12:54:46 +0100
committerunknown <msvensson@pilot.mysql.com>2008-03-10 12:54:46 +0100
commit4aced3b84d92482bdd1958493391a1bdcd76a879 (patch)
tree1f9a22a9a1b240a038e8db107e86d6d4ede5f489 /mysql-test/lib/My/SafeProcess
parent79bd441fd806ea55de7883bcff9b5327ef8e6ced (diff)
downloadmariadb-git-4aced3b84d92482bdd1958493391a1bdcd76a879.tar.gz
Add retry logic for OpenEvent to avoid problems when the
process to kill hasn't yet created the event
Diffstat (limited to 'mysql-test/lib/My/SafeProcess')
-rwxr-xr-xmysql-test/lib/My/SafeProcess/safe_kill_win.cc28
1 files changed, 24 insertions, 4 deletions
diff --git a/mysql-test/lib/My/SafeProcess/safe_kill_win.cc b/mysql-test/lib/My/SafeProcess/safe_kill_win.cc
index 74bb573eacb..a9a4b08b9e5 100755
--- a/mysql-test/lib/My/SafeProcess/safe_kill_win.cc
+++ b/mysql-test/lib/My/SafeProcess/safe_kill_win.cc
@@ -29,6 +29,7 @@ int main(int argc, const char** argv )
DWORD pid= -1;
HANDLE shutdown_event;
char safe_process_name[32]= {0};
+ int retry_open_event= 100;
if (argc != 2) {
fprintf(stderr, "safe_kill <pid>\n");
@@ -39,14 +40,33 @@ int main(int argc, const char** argv )
_snprintf(safe_process_name, sizeof(safe_process_name), "safe_process[%d]", pid);
/* Open the event to signal */
- if ((shutdown_event=
- OpenEvent(EVENT_MODIFY_STATE, FALSE, safe_process_name)) == NULL){
+ while ((shutdown_event=
+ OpenEvent(EVENT_MODIFY_STATE, FALSE, safe_process_name)) == NULL)
+ {
fprintf(stderr, "Failed to open shutdown_event '%s', error: %d\n",
safe_process_name, GetLastError());
- exit(1);
+
+ /* Just check to see if pid exists */
+ HANDLE pid_handle= OpenProcess(SYNCHRONIZE, FALSE, pid);
+ if (pid_handle == NULL)
+ fprintf(stderr, "Could not open process with pid %d, error: %d\n", pid);
+ else
+ CloseHandle(pid_handle);
+
+ if (retry_open_event--)
+ {
+ fprintf(stderr, "retrying...\n");
+ Sleep(100); /* In milli seconds */
+ }
+ else
+ {
+ fprintf(stderr, "No more retries, exiting");
+ exit(1);
+ }
}
- if(SetEvent(shutdown_event) == 0) {
+ if(SetEvent(shutdown_event) == 0)
+ {
fprintf(stderr, "Failed to signal shutdown_event '%s', error: %d\n",
safe_process_name, GetLastError());
CloseHandle(shutdown_event);