2015-07-31 20:00:13 +00:00
|
|
|
{- git-annex actions
|
|
|
|
-
|
|
|
|
- Copyright 2010-2015 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2015-07-31 20:00:13 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2019-06-19 16:35:08 +00:00
|
|
|
module Annex.Action (
|
|
|
|
startup,
|
|
|
|
shutdown,
|
|
|
|
stopCoProcesses,
|
|
|
|
reapZombies,
|
|
|
|
) where
|
2015-07-31 20:00:13 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
#ifndef mingw32_HOST_OS
|
2017-12-31 20:08:31 +00:00
|
|
|
import System.Posix.Process (getAnyProcessStatus)
|
|
|
|
import Utility.Exception
|
2015-07-31 20:00:13 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2015-07-31 20:00:13 +00:00
|
|
|
import qualified Annex
|
|
|
|
import Annex.Content
|
2019-06-19 16:35:08 +00:00
|
|
|
import Annex.Concurrent
|
2015-07-31 20:00:13 +00:00
|
|
|
|
|
|
|
{- Actions to perform each time ran. -}
|
|
|
|
startup :: Annex ()
|
2019-01-21 21:21:02 +00:00
|
|
|
startup = return ()
|
2015-07-31 20:00:13 +00:00
|
|
|
|
|
|
|
{- Cleanup actions. -}
|
|
|
|
shutdown :: Bool -> Annex ()
|
|
|
|
shutdown nocommit = do
|
|
|
|
saveState nocommit
|
|
|
|
sequence_ =<< M.elems <$> Annex.getState Annex.cleanup
|
2017-09-30 02:36:08 +00:00
|
|
|
stopCoProcesses
|
2015-07-31 20:00:13 +00:00
|
|
|
liftIO reapZombies -- zombies from long-running git processes
|
2017-09-30 02:36:08 +00:00
|
|
|
|
2017-12-31 20:08:31 +00:00
|
|
|
{- Reaps any zombie processes that may be hanging around.
|
|
|
|
-
|
|
|
|
- Warning: Not thread safe. Anything that was expecting to wait
|
|
|
|
- on a process and get back an exit status is going to be confused
|
|
|
|
- if this reap gets there first. -}
|
|
|
|
reapZombies :: IO ()
|
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
reapZombies =
|
|
|
|
-- throws an exception when there are no child processes
|
|
|
|
catchDefaultIO Nothing (getAnyProcessStatus False True)
|
|
|
|
>>= maybe (return ()) (const reapZombies)
|
|
|
|
|
|
|
|
#else
|
|
|
|
reapZombies = return ()
|
|
|
|
#endif
|