From d6d0b1fe20397bf073f11d579f5c0c38785e071a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 24 Oct 2017 12:33:44 -0400 Subject: try to avoid TerminateProcess link error on windows Building with stack, it failed: `_TerminateProcess' referenced in section `.text' of .stack-work\dist\5f9bc736\build\git-annex\git-annex-tmp\Utility\WinProcess.o: defined in discarded section `.text' of C:/Users/jenkins/AppData/Local/Programs/stack/i386-windows/ghc-8.0.2/mingw/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(dacgs01154.o) This is a reversion of 6d66a81ca98f8579bf06f7fb724ed733670d39b9, to try the other way to implement it, which will hopefully avoid the problem. --- Utility/WinProcess.hs | 17 ++--------------- Utility/winprocess.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 15 deletions(-) create mode 100644 Utility/winprocess.c (limited to 'Utility') diff --git a/Utility/WinProcess.hs b/Utility/WinProcess.hs index 31f6cfc69..36f079d04 100644 --- a/Utility/WinProcess.hs +++ b/Utility/WinProcess.hs @@ -11,18 +11,5 @@ module Utility.WinProcess where import Utility.PID -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 +foreign import ccall unsafe "terminatepid" + terminatePID :: PID -> IO () diff --git a/Utility/winprocess.c b/Utility/winprocess.c new file mode 100644 index 000000000..b6e315573 --- /dev/null +++ b/Utility/winprocess.c @@ -0,0 +1,10 @@ +#include + +void terminatepid (DWORD pid) { + HANDLE h; + h = OpenProcess(PROCESS_TERMINATE, 0, pid); + if (h != NULL) { + TerminateProcess(h, 1); + } + CloseHandle(h); +} -- cgit v1.2.3