Skip to content

Pseudo terminal and process-1.2.0.0

Error:

AsyncCancelled

Original Trac source:

Hello,

I'm writing simple app which execute process and communicate with it
via pseudo terminal. Here is some sample code:

import System.Posix.Terminal
import System.Process

main = do
  (master, slave) <- openPseudoTerminal
  hslave <- fdToHandle slave
  hSetBuffering hslave NoBuffering
  (_,_,_,ph) <- createProcess (shell "mc"){ env = Just [("TERM", "xterm")]
                                          , std_in = UseHandle hslave
                                          , std_out = UseHandle hslave
                                          , std_err = UseHandle hslave
                                          , close_fds = True
                                          }
  forkIO $ readTerm master -- my function which reads output from process
  waitForProcess ph

The problem is that mc still wants some input from stdin but not
from slave terminal.
But when I changed function runIteractiveProcess from runProcess.c like this:

...
        /* Reset the SIGINT/SIGQUIT signal handlers in the child, if requested
         */
        if (reset_int_quit_handlers) {
            struct sigaction dfl;
            (void)sigemptyset(&dfl.sa_
mask);
            dfl.sa_flags = 0;
            dfl.sa_handler = SIG_DFL;
            (void)sigaction(SIGINT,  &dfl, NULL);
            (void)sigaction(SIGQUIT, &dfl, NULL);
        }

/********************************************************************************/
        setsid(); //Make the current process a new session leader
        ioctl(0, TIOCSCTTY, 1); //As the child is a session leader,
set the controlling terminal to be the slave side of the PTY
/********************************************************************************/
        /* the child */
        if (environment) {
            // XXX Check result
            execvpe(args[0], args, environment);
        } else {
            // XXX Check result
            execvp(args[0], args);
        }

        childFailed(forkCommunicationFds[1], forkExecFailed);
...

it worked as expected, I'm not proposing patch or solution but is there
any chance to add support for pseudo terminals in the process library? Maybe just add another record field in CreateProcess like pty :: Bool and then call these two additional instructions in runIteractiveProcess?

Best regards,
Karol Samborski
Trac metadata
Trac field Value
Version 7.6.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/process
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information