1
/* Copyright (C) 2004 MySQL AB
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
Utility program used to signal a safe_process it's time to shutdown
28
int main(int argc, const char** argv )
31
HANDLE shutdown_event;
32
char safe_process_name[32]= {0};
33
int retry_open_event= 2;
34
/* Ignore any signals */
35
signal(SIGINT, SIG_IGN);
36
signal(SIGBREAK, SIG_IGN);
37
signal(SIGTERM, SIG_IGN);
40
fprintf(stderr, "safe_kill <pid>\n");
45
_snprintf(safe_process_name, sizeof(safe_process_name),
46
"safe_process[%d]", pid);
48
/* Open the event to signal */
49
while ((shutdown_event=
50
OpenEvent(EVENT_MODIFY_STATE, FALSE, safe_process_name)) == NULL)
53
Check if the process is alive, otherwise there is really
54
no sense to retry the open of the event
58
process= OpenProcess(SYNCHRONIZE| PROCESS_QUERY_INFORMATION, FALSE, pid);
65
if (!GetExitCodeProcess(process,&exit_code))
67
fprintf(stderr, "GetExitCodeProcess failed, pid= %d, err= %d\n",
72
if (exit_code != STILL_ACTIVE)
81
if (retry_open_event--)
85
fprintf(stderr, "Failed to open shutdown_event '%s', error: %d\n",
86
safe_process_name, GetLastError());
91
if(SetEvent(shutdown_event) == 0)
93
fprintf(stderr, "Failed to signal shutdown_event '%s', error: %d\n",
94
safe_process_name, GetLastError());
95
CloseHandle(shutdown_event);
98
CloseHandle(shutdown_event);