(not) catching ^C in ghc-built application

Simon Marlow simonmar@microsoft.com
Tue, 13 Aug 2002 10:40:07 +0100


> I have a program, written in a mixture of Haskell and C, in which the
> C part is supposed to handle a ^C interrupt, accomplished through the
> usual signal() call.  It works as expected when the Haskell part is
> compiled by nhc98.  But when it is compiled by ghc, for some reason
> the ghc RTS appears to trap the interrupt itself, and halts the
> program with the message
>     prog: interrupted
> instead of allowing the newly installed C signal handler to run.
>=20
> I have looked through the ghc user manual for some means to=20
> turn off or
> divert the RTS signal-handling, but I couldn't find anything relevant.
> The nearest thing is Exception.block, which excludes an asynchronous
> exception from happening whilst the `block' is in operation, but that
> doesn't seem to stop a ^C from interrupting the program, so I guess
> that isn't its real purpose.
>=20
> So, what should I use instead?

It's probably quite naughty of us to install a SIGINT handler without
checking whether there was already one installed.  The relevant code is
in ghc/rts/Signals.c around line 359.  If you send me a patch I'll
incorporate it.

For a quick workaround, if you install your own handler *after* calling
startupHaskell(), you should be able to override GHC's.

Cheers,
	Simon