From 6a4e3b037398acd5bdabdcb6fea29be8cdf803ae Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 25 Oct 2017 19:28:12 -0400 Subject: [PATCH] improve c_TerminateProcess types and propigate failure Thanks to @Mistuke for the review and for suggesting the better name terminateProcessById. --- System/Win32/Process.hsc | 11 ++++++----- changelog.md | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/System/Win32/Process.hsc b/System/Win32/Process.hsc index 0fb82629..80f2d3b7 100644 --- a/System/Win32/Process.hsc +++ b/System/Win32/Process.hsc @@ -19,9 +19,10 @@ module System.Win32.Process where import Control.Exception ( bracket ) -import Control.Monad ( liftM5, void ) +import Control.Monad ( liftM5 ) import Foreign ( Ptr, peekByteOff, allocaBytes, pokeByteOff , plusPtr ) +import Foreign.C.Types ( CUInt(..) ) import System.Win32.File ( closeHandle ) import System.Win32.Types @@ -82,13 +83,13 @@ getCurrentProcess :: IO ProcessHandle getCurrentProcess = c_GetCurrentProcess foreign import WINDOWS_CCONV unsafe "windows.h TerminateProcess" - c_TerminateProcess :: ProcessHandle -> Int -> IO Int + c_TerminateProcess :: ProcessHandle -> CUInt -> IO Bool -terminateProcessId :: ProcessId -> IO () -terminateProcessId p = bracket +terminateProcessById :: ProcessId -> IO () +terminateProcessById p = bracket (openProcess pROCESS_TERMINATE False p) closeHandle - (\h -> void $ c_TerminateProcess h 1) + (\h -> failIfFalse_ "TerminateProcess" $ c_TerminateProcess h 1) type Th32SnapHandle = HANDLE type Th32SnapFlags = DWORD diff --git a/changelog.md b/changelog.md index 3d0602db..37c874a1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog for [`Win32` package](http://hackage.haskell.org/package/Win32) +## not released yet + +* Add `terminateProcessById` (See #91) + ## 2.6.0.0 *September 2017* * Make cabal error out on compilation on non-Windows OSes. (See #80)