Skip to content

Commit

Permalink
improve c_TerminateProcess types and propigate failure
Browse files Browse the repository at this point in the history
Thanks to @Mistuke for the review and for suggesting the better
name terminateProcessById.
  • Loading branch information
joeyh authored and Mistuke committed Oct 26, 2017
1 parent 443cda2 commit 6a4e3b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 6 additions & 5 deletions System/Win32/Process.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

2 comments on commit 6a4e3b0

@Mistuke
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Win32 Bindings for Haskell :: Win32 Continuous builds Build 45 is now running

@Mistuke
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Win32 Bindings for Haskell :: Win32 Continuous builds Build 45 outcome was SUCCESS
Summary: Running Build time: 00:07:56

Please sign in to comment.