windows: Fix process termination code.
The ctrl-c hack used before didn't actually seem to work. No haskell libraries expose TerminateProcess. I tried just calling it via FFI, but got segfaults, probably to do with the wacky process handle not being managed correctly. Moving it all into one C function worked. This was hell. The EvilLinker hack was just final icing on the cake. We all know what the cake was made of.
This commit is contained in:
parent
84083ecdd3
commit
f11f7520b5
10 changed files with 58 additions and 24 deletions
|
@ -39,7 +39,7 @@ import qualified Control.Concurrent.MSemN as MSemN
|
|||
import System.Posix.Process (getProcessGroupIDOf)
|
||||
import System.Posix.Signals (signalProcessGroup, sigTERM, sigKILL)
|
||||
#else
|
||||
import System.Win32.Console (generateConsoleCtrlEvent, cTRL_C_EVENT, cTRL_BREAK_EVENT)
|
||||
import Utility.WinProcess
|
||||
#endif
|
||||
|
||||
type TransferGenerator = Assistant (Maybe (Transfer, TransferInfo, Transferrer -> Assistant ()))
|
||||
|
@ -256,23 +256,19 @@ cancelTransfer pause t = do
|
|||
signalthread tid
|
||||
| pause = throwTo tid PauseTransfer
|
||||
| otherwise = killThread tid
|
||||
{- In order to stop helper processes like rsync,
|
||||
- kill the whole process group of the process
|
||||
- running the transfer. -}
|
||||
killproc pid = void $ tryIO $ do
|
||||
#ifndef mingw32_HOST_OS
|
||||
{- In order to stop helper processes like rsync,
|
||||
- kill the whole process group of the process
|
||||
- running the transfer. -}
|
||||
g <- getProcessGroupIDOf pid
|
||||
let signal sig = void $ tryIO $ signalProcessGroup sig g
|
||||
signal sigTERM
|
||||
graceperiod
|
||||
threadDelay 50000 -- 0.05 second grace period
|
||||
signal sigKILL
|
||||
#else
|
||||
let signal sig = void $ tryIO $ generateConsoleCtrlEvent sig pid
|
||||
signal cTRL_C_EVENT
|
||||
graceperiod
|
||||
signal cTRL_BREAK_EVENT
|
||||
terminatePID pid
|
||||
#endif
|
||||
graceperiod = threadDelay 50000 -- 0.05 second
|
||||
|
||||
{- Start or resume a transfer. -}
|
||||
startTransfer :: Transfer -> Assistant ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue