From a76078a78e4dc353e7b4e99a250ddd3d83f74ba3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Aug 2012 15:45:00 -0400 Subject: 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. --- Assistant/DaemonStatus.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'Assistant/DaemonStatus.hs') diff --git a/Assistant/DaemonStatus.hs b/Assistant/DaemonStatus.hs index 230d2ed37..fae51ea61 100644 --- a/Assistant/DaemonStatus.hs +++ b/Assistant/DaemonStatus.hs @@ -183,12 +183,17 @@ adjustTransfersSTM dstatus a = do s <- takeTMVar dstatus putTMVar dstatus $ s { currentTransfers = a (currentTransfers s) } -{- Variant that does send notifications. -} -adjustTransfers :: DaemonStatusHandle -> (TransferMap -> TransferMap) -> IO () -adjustTransfers dstatus a = +{- Updates a transfer's info. Preserves any transferTid value, which is not + - written to disk. -} +updateTransferInfo :: DaemonStatusHandle -> Transfer -> TransferInfo -> IO () +updateTransferInfo dstatus t info = notifyTransfer dstatus `after` modifyDaemonStatus_ dstatus go where - go s = s { currentTransfers = a (currentTransfers s) } + go s = s { currentTransfers = update (currentTransfers s) } + update m = M.insertWith' merge t info m + merge new old = case transferTid old of + Nothing -> new + Just _ -> new { transferTid = transferTid old } {- Removes a transfer from the map, and returns its info. -} removeTransfer :: DaemonStatusHandle -> Transfer -> IO (Maybe TransferInfo) -- cgit v1.2.3