util/chpty.cc
/// This is to be called in the newly forked CHILD *before* executing
/// the target program. It opens m_rfd, sets terminal attributes,
/// and attaches  stdin/stout/stderr.
///
/// * May throw Chpty_*_exceptions
///
This is to be called in the newly forked CHILD *before* executing
the target program. It opens m_rfd, sets terminal attributes,
and attaches  stdin/stout/stderr.

May throw Chpty_*_exceptions
This is to be called in the newly forked CHILD * before * executing the target program . It opens m_rfd sets terminal attributes and attaches stdin / stout / stderr . May throw Chpty_ * _exceptions
void Pty_controller::child_init()
{
    if (libc_err == setsid()) { throw Chpty_open_exception(); }
    close_pty();      
    m_rfd = open( m_remote_name.c_str(), O_RDWR );
    if (libc_err == m_rfd) {
        throw Chpty_open_exception();
    }
    if (m_valid_termios) {
        if (libc_err == tcsetattr( m_rfd, TCSANOW, &m_termios )) {
            throw Chpty_termio_exception();
        }
    }
    if (libc_err == ioctl(m_rfd, TIOCSWINSZ, &m_winsize)) {
        throw Chpty_ioctl_exception();
    }
    if (STDIN_FILENO != dup2(m_rfd,STDIN_FILENO)) {
        throw Chpty_dup2_exception();
    }
    if (STDOUT_FILENO != dup2(m_rfd,STDOUT_FILENO)) {
        throw Chpty_dup2_exception();
    }
    if (STDERR_FILENO != dup2(m_rfd,STDERR_FILENO)) {
        throw Chpty_dup2_exception();
    }
    if (m_rfd > STDERR_FILENO) {
        close(m_rfd);
        m_rfd = non_fd;
    }
}
void Pty_controller :: child_init ( ) { if ( libc_err == setsid ( ) ) { throw Chpty_open_exception ( ) ; } close_pty ( ) ; m_rfd = open ( m_remote_name . c_str ( ) , O_RDWR ) ; if ( libc_err == m_rfd ) { throw Chpty_open_exception ( ) ; } if ( m_valid_termios ) { if ( libc_err == tcsetattr ( m_rfd , TCSANOW , & m_termios ) ) { throw Chpty_termio_exception ( ) ; } } if ( libc_err == ioctl ( m_rfd , TIOCSWINSZ , & m_winsize ) ) { throw Chpty_ioctl_exception ( ) ; } if ( STDIN_FILENO != dup2 ( m_rfd , STDIN_FILENO ) ) { throw Chpty_dup2_exception ( ) ; } if ( STDOUT_FILENO != dup2 ( m_rfd , STDOUT_FILENO ) ) { throw Chpty_dup2_exception ( ) ; } if ( STDERR_FILENO != dup2 ( m_rfd , STDERR_FILENO ) ) { throw Chpty_dup2_exception ( ) ; } if ( m_rfd > STDERR_FILENO ) { close ( m_rfd ) ; m_rfd = non_fd ; } }
This is to be called in the newly forked CHILD *before* executing
the target program.
This is to be called in the newly forked CHILD * before * executing the target program .
// set session id // not needed in child // If valid, set remote tty attributes NOW // Set window size // Redirect stdin, stdout, stderr streams to the pty