runghc: use executeFile to run ghc process on POSIX
authorMichael Snoyman <michael@snoyman.com>
Sun, 2 Oct 2016 01:24:05 +0000 (21:24 -0400)
committerBen Gamari <ben@smart-cactus.org>
Sun, 2 Oct 2016 19:20:01 +0000 (15:20 -0400)
commitc904258319b8eb6e47ba727c667bca765537802b
tree77273f7133404409e3123db59ed0e1b9e6866dd5
parenta24092ff501028ca1245b508320493f394378495
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

(cherry picked from commit 42f1d86770f963cf810aa4d31757dda8a08a52fa)
testsuite/tests/runghc/Makefile
testsuite/tests/runghc/T-signals-child.hs [new file with mode: 0644]
testsuite/tests/runghc/T7859.stderr
testsuite/tests/runghc/all.T
utils/runghc/Main.hs
utils/runghc/runghc.cabal.in