runghc has problem when the argument list is too big
The way runghc works is by calling ghc with some extra arguments. These extra arguments cause the argv passed to ghc to be larger than the original one. This can cause the size of argv to exceed the maximum allowed. This might seem like a minor issue, but it can confuse several unix tools that rely on exact calculations on the size of argv, such as xargs or find with the -exec option.
To demonstrate the problem, consider the following the program (call it print_size.hs):
import System.Environment
import System.Posix
main = getArgs >>= mapM_ printSize
where
printSize file = do
st <- getSymbolicLinkStatus file
putStrLn $ show (fileSize st) ++ " " ++ file
The program interpreters its argv as a list of files and prints their sizes.
Now suppose that you want to run the program without compiling it (i.e. by interpreting it) on a specific set files, as returned by find. For example, consider something like that:
find / -exec runhaskell print_size.hs {} +
If you run this, you will get the following error (multiple times):
runghc: /usr/bin/ghc: rawSystem: runInteractiveProcess: exec: resource exhausted (Argument list too long)
The problem here is that the -exec option of find, when used with the + switch, works as follows: it starts collecting the list of found files and just before the list exceeds the maximum allowed size for argv it runs the specified program on that list (it works this way in order to minimize the number of times the program is ran). Of course this is problematic because runghc will then increase the size of argv and because of that the call to ghc might fail.
The same thing happens if you try to run the following as well:
find / -print0 | xargs -0 runhaskell print_size.hs
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.11 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | low |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |