mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
Implement virKill for Win32 platform
This commit is contained in:
parent
4d713eabf5
commit
52e51d278e
@ -1,3 +1,7 @@
|
||||
Thu Jan 15 19:39:19 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
|
||||
|
||||
* src/util.c: Implement virKill() for Win32 platform
|
||||
|
||||
Thu Jan 15 17:29:19 GMT 2009 John Levon <levon@movementarian.org>
|
||||
|
||||
* src/internal.h:
|
||||
|
47
src/util.c
47
src/util.c
@ -1379,5 +1379,50 @@ int virKillProcess(pid_t pid, int sig)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return kill(pid, sig);
|
||||
#ifdef WIN32
|
||||
/* Mingw / Windows don't have many signals (AFAIK) */
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
/* This does a Ctrl+C equiv */
|
||||
if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid)) {
|
||||
errno = ESRCH;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIGTERM:
|
||||
/* Since TerminateProcess is closer to SIG_KILL, we do
|
||||
* a Ctrl+Break equiv which is more pleasant like the
|
||||
* good old unix SIGTERM/HUP
|
||||
*/
|
||||
if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid)) {
|
||||
errno = ESRCH;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
HANDLE proc;
|
||||
proc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||
if (!proc) {
|
||||
errno = ESRCH; /* Not entirely accurate, but close enough */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* TerminateProcess is more or less equiv to SIG_KILL, in that
|
||||
* a process can't trap / block it
|
||||
*/
|
||||
if (!TerminateProcess(proc, sig)) {
|
||||
errno = ESRCH;
|
||||
return -1;
|
||||
}
|
||||
CloseHandle(proc);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
return kill(pid, sig);
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user