summaryrefslogtreecommitdiff
path: root/Utility/Batch.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-10-22 14:39:45 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-10-22 14:49:41 -0400
commitb9186e3c2097cf8c94403b38c9dbe6ed382d82b0 (patch)
tree77fe35280a9c999f2bb74939f6ef334ab64a9f48 /Utility/Batch.hs
parent708745e1e23725f0e90a4fa4f01b863edbf844d4 (diff)
make git fsck batch-capable
Diffstat (limited to 'Utility/Batch.hs')
-rw-r--r--Utility/Batch.hs38
1 files changed, 25 insertions, 13 deletions
diff --git a/Utility/Batch.hs b/Utility/Batch.hs
index fcd844885..011d30c94 100644
--- a/Utility/Batch.hs
+++ b/Utility/Batch.hs
@@ -44,7 +44,28 @@ batch a = a
maxNice :: Int
maxNice = 19
-{- Runs a command in a way that's suitable for batch jobs.
+{- Converts a command to run niced. -}
+toBatchCommand :: (String, [CommandParam]) -> (String, [CommandParam])
+toBatchCommand (command, params) = (command', params')
+ where
+#ifndef mingw32_HOST_OS
+ commandline = unwords $ map shellEscape $ command : toCommand params
+ nicedcommand
+ | Build.SysConfig.nice = "nice " ++ commandline
+ | otherwise = commandline
+ command' = "sh"
+ params' =
+ [ Param "-c"
+ , Param $ "exec " ++ nicedcommand
+ ]
+#else
+ command' = command
+ params' = params
+#endif
+
+{- Runs a command in a way that's suitable for batch jobs that can be
+ - interrupted.
+ -
- The command is run niced. If the calling thread receives an async
- exception, it sends the command a SIGTERM, and after the command
- finishes shuttting down, it re-raises the async exception. -}
@@ -63,15 +84,6 @@ batchCommandEnv command params environ = do
void $ waitForProcess pid
E.throwIO asyncexception
where
-#ifndef mingw32_HOST_OS
- p = proc "sh"
- [ "-c"
- , "exec " ++ nicedcommand
- ]
- commandline = unwords $ map shellEscape $ command : toCommand params
- nicedcommand
- | Build.SysConfig.nice = "nice " ++ commandline
- | otherwise = commandline
-#else
- p = proc command (toCommand params)
-#endif
+ (command', params') = toBatchCommand (command, params)
+ p = proc command' $ toCommand params'
+