diff options
author | Michael Snoyman <michael@snoyman.com> | 2016-10-01 21:24:05 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-10-02 14:57:44 -0400 |
commit | 42f1d86770f963cf810aa4d31757dda8a08a52fa (patch) | |
tree | 99400e6db8b967bda704df4ea1e431cc1e7a63f7 /utils | |
parent | 4d2b15d5895ea10a64194bffe8c321e447e39683 (diff) | |
download | haskell-42f1d86770f963cf810aa4d31757dda8a08a52fa.tar.gz |
runghc: use executeFile to run ghc process on POSIX
This means that, on POSIX systems, there will be only one ghc process
used for running scripts, as opposed to the current situation of a
runghc process and a ghc process. Beyond minor performance benefits of
not having an extra fork and resident process, the more important impact
of this is automatically getting proper signal handling. I noticed this
problem myself when running runghc as PID1 inside a Docker container.
I attempted to create a shim library for executeFile that would work for
both POSIX and Windows, but unfortunately I ran into issues with exit
codes being propagated correctly (see
https://github.com/fpco/replace-process/issues/2). Therefore, this patch
leaves the Windows behavior unchanged. Given that signals are a POSIX
issue, this isn't too bad a trade-off. If someone has suggestions for
better Windows _exec support, please let me know.
Reviewers: erikd, austin, bgamari
Reviewed By: bgamari
Subscribers: Phyx, thomie
Differential Revision: https://phabricator.haskell.org/D2538
Diffstat (limited to 'utils')
-rw-r--r-- | utils/runghc/Main.hs | 24 | ||||
-rw-r--r-- | utils/runghc/runghc.cabal.in | 3 |
2 files changed, 21 insertions, 6 deletions
diff --git a/utils/runghc/Main.hs b/utils/runghc/Main.hs index 001d902f80..bcf77e7b8a 100644 --- a/utils/runghc/Main.hs +++ b/utils/runghc/Main.hs @@ -24,11 +24,13 @@ import System.Environment import System.Exit import System.FilePath import System.IO -import System.Process #if defined(mingw32_HOST_OS) +import System.Process (runProcess) import Foreign import Foreign.C.String +#else +import System.Posix.Process (executeFile) #endif #if defined(mingw32_HOST_OS) @@ -141,11 +143,21 @@ doIt ghc ghc_args rest = do else [] c1 = ":set prog " ++ show filename c2 = ":main " ++ show prog_args - res <- rawSystem ghc (["-ignore-dot-ghci"] ++ - xflag ++ - ghc_args ++ - [ "-e", c1, "-e", c2, filename]) - exitWith res + + let cmd = ghc + args = ["-ignore-dot-ghci"] ++ + xflag ++ + ghc_args ++ + [ "-e", c1, "-e", c2, filename] + + +#if defined(mingw32_HOST_OS) + rawSystem cmd args >>= exitWith +#else + -- Passing False to avoid searching the PATH, since the cmd should + -- always be an absolute path to the ghc executable. + executeFile cmd False args Nothing +#endif getGhcArgs :: [String] -> ([String], [String]) getGhcArgs args diff --git a/utils/runghc/runghc.cabal.in b/utils/runghc/runghc.cabal.in index efef5ec4db..2253292cf0 100644 --- a/utils/runghc/runghc.cabal.in +++ b/utils/runghc/runghc.cabal.in @@ -30,3 +30,6 @@ Executable runghc directory >= 1 && < 1.3, process >= 1 && < 1.5, filepath + + if !os(windows) + build-depends: unix
\ No newline at end of file |