summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-10-24 13:05:24 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-10-24 13:05:24 -0400
commit0eee7a2eb5f3459dbfc9c5b32757e5c866092e6b (patch)
tree2cb2ed274cfc2f5d8b491fb76f9b8d4ea0488d62
parenta6ed08a839f93ddc9d486cf7ca837aea6576f540 (diff)
Revert "try to avoid TerminateProcess link error on windows"
This reverts commit d6d0b1fe20397bf073f11d579f5c0c38785e071a. Neither way is working.. The other way failed: .stack-work\dist\5f9bc736\build\git-annex\git-annex-tmp\Assistant.o:fake:(.text+0x6bb3): undefined reference to `terminatepid' Seems that winprocess.c is not getting linked in.
-rw-r--r--Utility/WinProcess.hs17
-rw-r--r--Utility/winprocess.c10
-rw-r--r--Utility/winprocess.h3
-rw-r--r--git-annex.cabal2
4 files changed, 15 insertions, 17 deletions
diff --git a/Utility/WinProcess.hs b/Utility/WinProcess.hs
index cfac8794c..31f6cfc69 100644
--- a/Utility/WinProcess.hs
+++ b/Utility/WinProcess.hs
@@ -11,5 +11,18 @@ module Utility.WinProcess where
import Utility.PID
-foreign import ccall unsafe "winprocess.h terminatepid"
- terminatePID :: PID -> IO ()
+import System.Win32.Process
+import Control.Exception (bracket)
+import Control.Monad
+
+terminatePID :: PID -> IO ()
+terminatePID p = bracket
+ (openProcess pROCESS_TERMINATE False p)
+ (void . c_closeProcess)
+ (\h -> void $ c_TerminateProcess h 1)
+
+foreign import ccall unsafe "windows.h TerminateProcess"
+ c_TerminateProcess :: ProcessHandle -> Int -> IO Int
+
+foreign import ccall unsafe "windows.h CloseHandle"
+ c_closeProcess :: ProcessHandle -> IO Bool
diff --git a/Utility/winprocess.c b/Utility/winprocess.c
deleted file mode 100644
index b6e315573..000000000
--- a/Utility/winprocess.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <windows.h>
-
-void terminatepid (DWORD pid) {
- HANDLE h;
- h = OpenProcess(PROCESS_TERMINATE, 0, pid);
- if (h != NULL) {
- TerminateProcess(h, 1);
- }
- CloseHandle(h);
-}
diff --git a/Utility/winprocess.h b/Utility/winprocess.h
deleted file mode 100644
index eac954fca..000000000
--- a/Utility/winprocess.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include <windows.h>
-
-void terminatepid (DWORD pid);
diff --git a/git-annex.cabal b/git-annex.cabal
index 780d66a1e..4115b5ba6 100644
--- a/git-annex.cabal
+++ b/git-annex.cabal
@@ -1062,8 +1062,6 @@ Executable git-annex
Utility.LockFile.Windows
Utility.LockPool.Windows
Utility.WinProcess
- C-Sources: Utility/winprocess.c
- Includes: Utility/winprocess.h
else
Other-Modules:
Utility.LockFile.Posix