"Daniel P. Berrange" <berrange(a)redhat.com> wrote:
This patches provides a minimal implementation for virKill
on Win32. We don't particularly need this, but it avoids a
need to #ifdef out code elsewhere and may come in handy.
ACK, looks reasonable. (caveat: I haven't read documentation
for any of those MS-specific functions)
util.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
Daniel
diff --git a/src/util.c b/src/util.c
--- a/src/util.c
+++ b/src/util.c
@@ -1379,5 +1379,50 @@ int virKillProcess(pid_t pid, int sig)
return -1;
}
+#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
}