Opened 3 years ago

Closed 3 years ago

#4460 closed bug (fixed)

Input is not echoed when GHCi is suspended and subsequently brought to foreground.

Reported by: manzyuk Owned by: simonmar
Priority: normal Milestone: 7.0.2
Component: GHCi Version: 6.12.1
Keywords: suspend Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

How to reproduce:

  1. Start ghci.
  1. Press Ctrl-Z to suspend it.
  1. Type fg to bring ghci back to foreground.
  1. Hit RET to get the prompt.
  1. Type anything. The input is not echoed until you hit RET.

Also, if I press Ctrl-D to end the GHCi session (after it was suspended and brought back to foreground), I get

<stdin>: hWaitForInput: end of file

I am using ghc6 package from Debian Squeeze:

$ apt-cache show ghc6
Package: ghc6
Priority: optional
Section: haskell
Installed-Size: 378408
Maintainer: Kari Pahula <kaol@debian.org>
Architecture: amd64
Version: 6.12.1-13
Replaces: ghc6-doc (= 6.12.1-8), haddock
Provides: ghc, haddock, haskell-compiler, libghc6-array-dev, libghc6-array-dev-0.3.0.0-ed0c6, libghc6-base-dev, libghc6-base-dev-3.0.3.2-0092f, libghc6-base-dev-4.2.0.0-2cc27, libghc6-bin-package-db-dev, libghc6-bin-package-db-dev-0.0.0.0-4cfd2, libghc6-bytestring-dev, libghc6-bytestring-dev-0.9.1.5-125af, libghc6-cabal-dev, libghc6-cabal-dev-1.8.0.2-a7cb9, libghc6-containers-dev, libghc6-containers-dev-0.3.0.0-4a332, libghc6-directory-dev, libghc6-directory-dev-1.0.1.0-d465e, libghc6-dph-base-dev, libghc6-dph-base-dev-0.4.0-385a3, libghc6-dph-par-dev, libghc6-dph-par-dev-0.4.0-b4f33, libghc6-dph-prim-interface-dev, libghc6-dph-prim-interface-dev-0.4.0-9c8ab, libghc6-dph-prim-par-dev, libghc6-dph-prim-par-dev-0.4.0-4eccc, libghc6-dph-prim-seq-dev, libghc6-dph-prim-seq-dev-0.4.0-a2769, libghc6-dph-seq-dev, libghc6-dph-seq-dev-0.4.0-52cfd, libghc6-extensible-exceptions-dev, libghc6-extensible-exceptions-dev-0.1.1.1-95db3, libghc6-filepath-dev, libghc6-filepath-dev-1.1.0.3-3f3be, libghc6-ghc-binary-dev, libghc6-ghc-binary-dev-0.5.0.2-bb54d, libghc6-ghc-dev-6.12.1-3a757, libghc6-ghc-prim-dev, libghc6-ghc-prim-dev-0.2.0.0-9d35c, libghc6-haskell98-dev, libghc6-haskell98-dev-1.0.1.1-0fdaf, libghc6-hpc-dev, libghc6-hpc-dev-0.5.0.4-7df34, libghc6-integer-gmp-dev, libghc6-integer-gmp-dev-0.2.0.0-9a51f, libghc6-old-locale-dev, libghc6-old-locale-dev-1.0.0.2-ef43d, libghc6-old-time-dev, libghc6-old-time-dev-1.0.0.3-9efce, libghc6-pretty-dev, libghc6-pretty-dev-1.0.1.1-34534, libghc6-process-dev, libghc6-process-dev-1.0.1.2-d10eb, libghc6-random-dev, libghc6-random-dev-1.0.0.2-cf650, libghc6-rts-dev, libghc6-syb-dev, libghc6-syb-dev-0.1.0.2-3787e, libghc6-template-haskell-dev, libghc6-template-haskell-dev-2.4.0.0-bbc7c, libghc6-time-dev, libghc6-time-dev-1.1.4-1ced4, libghc6-unix-dev, libghc6-unix-dev-2.4.0.0-16adb, libghc6-utf8-string-dev, libghc6-utf8-string-dev-0.3.4-75a94
Depends: perl | perl5, gcc (>= 4:4.2), libgmp3-dev, libffi-dev, libbsd-dev, libc6-dev, libc6 (>= 2.3.4), libffi5 (>= 3.0.4), libgmp3c2, libncurses5 (>= 5.7+20100313)
Suggests: ghc6-prof, ghc6-doc, haskell-doc
Conflicts: ghc4 (<= 4.08.1-4), haddock
Breaks: cabal-install (<< 0.8.0), ghc6-doc (<= 6.12.1-8), haskell-devscripts (<< 0.6.19)
Filename: pool/main/g/ghc6/ghc6_6.12.1-13_amd64.deb
Size: 68875186
MD5sum: 84e247fb7f40f06a2fcd724d735c75e8
SHA1: 25e8d8f9ad9c8a484bd6a86494397ca44431208e
SHA256: 27096990dc41dfae6965ef16fa2bf12a3c2c3b7a8c9c77ead4f9b45cd422e9fe
Description: GHC - the Glasgow Haskell Compilation system
 Version 6 of the Glorious Glasgow Haskell Compilation system (GHC).  GHC is
 a compiler for Haskell98.
 .
 Haskell is "the" standard lazy functional programming language. Haskell98
 is the current version of the language. The language definition and
 additional documentation can be found in the `haskell-doc' package.
 Alternatively, there is an online version at
 http://haskell.org/onlinereport/.
Homepage: http://haskell.org/ghc/
Tag: devel::{compiler,interpreter,lang:haskell}, implemented-in::c, implemented-in::haskell, interface::commandline, interface::text-mode, role::program, scope::utility, uitoolkit::ncurses, works-with::software:source

Attachments (1)

Main.hs (731 bytes) - added by igloo 3 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 3 years ago by judahj

Interestingly, Haskeline (ghci's line-reading backend) by itself does not have this problem. For example, the above steps work fine for the test program at:

http://code.haskell.org/haskeline/examples/Test.hs

So this issue may be caused by something specific to ghci.

Changed 3 years ago by igloo

comment:2 Changed 3 years ago by igloo

The attached Main.hs has the same problem.

comment:3 Changed 3 years ago by igloo

  • Milestone set to 7.0.2

comment:4 Changed 3 years ago by igloo

The hSetBuffering stdin NoBuffering in particular is the problem. After suspending and resuming the program, icanon has been turned back on. We presumably need to set it to what we think it should be when we get a SIGCONT.

module Main (main) where

import Control.Monad.Trans
import System.Console.Haskeline
import System.Cmd
import System.IO

main :: IO ()
main = do gb 1
          hSetBuffering stdin NoBuffering
          gb 2
          runInputT defaultSettings runCommands
          putStrLn "Leaving."

runCommands :: InputT IO ()
runCommands = do liftIO $ gb 3
                 m <- getInputLine "Prompt: "
                 case m of
                     Nothing -> return ()
                     Just x -> do liftIO $ print x
                                  runCommands

gb :: Int -> IO ()
gb n = do putStrLn "----------------------------"
          b <- hGetBuffering stdin
          putStrLn ("b " ++ show n ++ " " ++ show b)
          rawSystem "stty" ["-a"]
          return ()

comment:5 Changed 3 years ago by simonmar

  • Owner set to simonmar

I'm on this.

comment:6 Changed 3 years ago by simonmar

  • Status changed from new to merge

Fixed:

Fri Jan  7 12:40:42 GMT 2011  Simon Marlow <marlowsd@gmail.com>
  * catch SIGTSTP and save/restore terminal settings (#4460)
  As far as I can tell, it is the responsibility of the program to save
  and restore its own terminal settings across a suspend/foreground, the
  shell doesn't do it (which seems odd).  So I've added a signal handler
  for SIGTSTP to the RTS which will save and restore the terminal
  settings iff we modified them with hSetBuffering or hSetEcho (we
  already restore them at exit time in these cases).

comment:7 Changed 3 years ago by igloo

  • Resolution set to fixed
  • Status changed from merge to closed

Merged.

Note: See TracTickets for help on using tickets.