gracefully invoking `less` using System.Process (and ignoring ctrl-c)

Hi, I'm looking at a bug that we should fix for the 2.10 release of darcs. I'd like to make the invocation of the pager (most of the time `less`) as identical to git as possible. Currently darcs has a workaround for the "resource vanished (broken pipe)" problem (that happens when you leave `less` before all of the text has been read by it). The workaround involves creating a temporary file and then passing it to less [1]. This works but it's slow (for big inputs) and ugly IMO. I have a fix proposal [2] that is made of two changes: * use System.Process.createProcess (just to update the code), and * in the "ortryrunning" function (that chains attempts at calling various pagers until one works), ignoring IOError's of the kind ResourceVanished (otherwise we would invoke every pager in the chain if we quit them before they read all their input) The problem is that pressing CTRL-C in `less` now kills everything (darcs+less). Is there a way to fix this? Note that the darcs executable runs inside of the function withSignalHandled [3], which defines its behaviour with respect to various signals. Guillaume [1] http://hub.darcs.net/darcs/darcs-reviewed/browse/src/Darcs/UI/External.hs#46... [2] http://hub.darcs.net/gh/darcs-screened_1/patch/20141210002305-5ef8f [3] http://hub.darcs.net/darcs/darcs-reviewed/browse/src/Darcs/Util/SignalHandle...

On Fri, Dec 12, 2014 at 12:19 PM, Guillaume Hoffmann
The problem is that pressing CTRL-C in `less` now kills everything (darcs+less). Is there a way to fix this?
On Unix you'd just arrange for your job to ignore sigINT itself, overriding the withSignalHandled setting. The various online documentation systems are all on Linux and don't document win32-specific modules as a result, but it looks like you might be able to use withCtrlCHandler id realActionGoesHere on Windows. (Someone with Windows knowledge needs to verify that; it's nested under another withCtrlCHandler in withSignalHandled, and I have no clue how they would interact.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Quoth Guillaume Hoffmann
* use System.Process.createProcess (just to update the code), and * in the "ortryrunning" function (that chains attempts at calling various pagers until one works), ignoring IOError's of the kind ResourceVanished (otherwise we would invoke every pager in the chain if we quit them before they read all their input)
The problem is that pressing CTRL-C in `less` now kills everything (darcs+less).
And didn't before? Do you suppose, because of the createProcess? I don't keep track as well as I should, of the library's herculean efforts to support UNIX functionality like this on a platform independent layer, but I notice in the docs a "delegate_ctlc" option, and some discussion of it and pointers to more discussion, in System.Process. Does any of that help? Do you want to support this on Windows? Donn

On Fri, Dec 12, 2014 at 1:19 PM, Donn Cave
The problem is that pressing CTRL-C in `less` now kills everything (darcs+less).
And didn't before? Do you suppose, because of the createProcess?
The withSIgnalHandled function cited in the original message explicitly un-ignores SIGINT, which leads to the observed behavior. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Thanks Donn, I tried with process-1.2.0.0 and the delegate_ctlc option and now the behaviour is correct :-)
participants (3)
-
Brandon Allbery
-
Donn Cave
-
Guillaume Hoffmann