process group killing
This seems to work pretty well. Handled the process groups like this: - git-annex processes started by the assistant for transfers are run in their own process groups. - otherwise, rely on the shell to allocate a process group for git-annex There is potentially a problem if some other program runs git-annex directly (not using sh -c) The program and git-annex would then be in the same process group. If that git-annex starts a transfer and it's canceled, the program would also get killed. May or may not be a desired result. Also, the new updateTransferInfo probably closes a race where it was possible for the thread id to not be recorded in the transfer info, if the transfer info file from the transfer process is read first.
This commit is contained in:
parent
d5e06e7b89
commit
a76078a78e
4 changed files with 40 additions and 34 deletions
|
@ -29,7 +29,8 @@ import Yesod
|
|||
import Text.Hamlet
|
||||
import qualified Data.Map as M
|
||||
import Control.Concurrent
|
||||
import System.Posix.Signals (signalProcess, sigTERM, sigKILL)
|
||||
import System.Posix.Signals (signalProcessGroup, sigTERM, sigKILL)
|
||||
import System.Posix.Process (getProcessGroupIDOf)
|
||||
|
||||
{- A display of currently running and queued transfers.
|
||||
-
|
||||
|
@ -180,7 +181,11 @@ cancelTransfer t = do
|
|||
maybe noop killThread $ transferTid info
|
||||
maybe noop killproc $ transferPid info
|
||||
removeTransfer (daemonStatus webapp) t
|
||||
{- In order to stop helper processes like rsync,
|
||||
- kill the whole process group of the process running the
|
||||
- transfer. -}
|
||||
killproc pid = do
|
||||
void $ tryIO $ signalProcess sigTERM pid
|
||||
g <- getProcessGroupIDOf pid
|
||||
void $ tryIO $ signalProcessGroup sigTERM g
|
||||
threadDelay 100000 -- 0.1 second grace period
|
||||
void $ tryIO $ signalProcess sigKILL pid
|
||||
void $ tryIO $ signalProcessGroup sigKILL g
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue