]> git.lyx.org Git - lyx.git/blobdiff - src/support/kill.C
make "make distcheck" work
[lyx.git] / src / support / kill.C
index f9f462d91692df1439b020e05617c330d393be70..3c23a96a9ec97336ce9426c6d52cf35e04521ff5 100644 (file)
@@ -1,20 +1,52 @@
+/**
+ * \file kill.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
 #include <config.h>
 
+#include "support/lyxlib.h"
+
 #include <sys/types.h>
-#include <signal.h>
+#include <csignal>
 
-#ifdef CXX_WORKING_NAMESPACES
-namespace lyx {
-       int kill(long int pid, int sig)
-       {
-               return ::kill(pid, sig);
-       }
-}
-#else
-#include "lyxlib.h"
+#ifdef _WIN32
+#include "debug.h"
+#include "os.h"
+
+#include <windows.h>
+#include <errno.h>
 
-int lyx::kill(long int pid, int sig)
+using std::endl;
+#endif //_WIN32
+
+int lyx::support::kill(int pid, int sig)
 {
+#ifdef _WIN32
+       if (pid == (int)GetCurrentProcessId()) {
+               return -(raise(sig));
+       } else {
+               HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
+               if (!hProcess) {
+                       lyxerr << "kill OpenProcess failed!" << endl;
+                       return -1;
+               } else {
+                       if (!TerminateProcess(hProcess, sig)){
+                               lyxerr << "kill process failed!" << endl;
+                               CloseHandle(hProcess);
+                               return -1;
+                       }
+               CloseHandle(hProcess);
+               }
+       }
+       return 0;
+
+#else
        return ::kill(pid, sig);
-}
 #endif
+}