aboutsummaryrefslogtreecommitdiff
path: root/Assistant/TransferSlots.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-02-13 14:00:15 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-02-13 15:53:10 -0400
commit4f59f9439687cccfb7aac6aca62dbe97038179bf (patch)
tree94d8fa2e00989c183a20db782b8c5e9fa0e3ff9b /Assistant/TransferSlots.hs
parent16405cbd31e2ee5a2ef021a1c178738709b087c3 (diff)
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.
Diffstat (limited to 'Assistant/TransferSlots.hs')
-rw-r--r--Assistant/TransferSlots.hs16
1 files changed, 6 insertions, 10 deletions
diff --git a/Assistant/TransferSlots.hs b/Assistant/TransferSlots.hs
index de96cdf85..a36a3ee32 100644
--- a/Assistant/TransferSlots.hs
+++ b/Assistant/TransferSlots.hs
@@ -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 ()