Why does gnu readline require me to hit the c control twice?

Typically, Control-C sends a signal to a program and kills it if it is not caught. The gnureadline library will install handlers for sigint. However, even when disabling these handlers in haskell, I still need to press Control-C twice to kill the program. What's happening?

import System.Console.Readline main = do setCatchSignals False mainLoop mainLoop = do maybeLine <- readline ">" case maybeLine of Nothing -> putStrLn ":(" Just line -> do putStr line putStr " catch:" catch <- getCatchSignals putStrLn $ show $ catch mainLoop 
+6
source share
1 answer

This may be due to ready / raw / rare modes; ^C does not always send a signal. It seems likely that readline frees up the terminal, and therefore any signals caused by keyboard input should be triggered by the logic in readline itself; it seems plausible that it can only initiate SIGINT on two consecutive ^C (especially since for many programs using readline, such as shells and REPL, a program exiting on one ^C will be very annoying!).

You may be able to change this behavior using the readline API to re-bind ^C to some of your own code that runs SIGINT. I have not used readline from Haskell, only with C, so I'm not sure exactly how you will do this, but the binding seems rich enough to reach it.

+8
source

Source: https://habr.com/ru/post/904407/


All Articles