Пример #1
0
int skip_rlwrap() { /* this function is called from sigTSTP signal handler. Is it re-entrant? */
  int retval = FALSE;
  DEBUG_RANDOM_SLEEP;
  if (dont_wrap_command_waits())
    retval = TRUE;
  else if (always_readline)
    retval =  FALSE;
  else if (slave_is_in_raw_mode())
    retval= TRUE;
  DEBUG_RANDOM_SLEEP;
  return retval;
}
Пример #2
0
void
mirror_slaves_echo_mode()
{                               /* important e.g. when slave command asks for password  */
  struct termios *pterm_slave = NULL;
  int should_echo_anyway = always_echo || (always_readline && !dont_wrap_command_waits());

  if ( !(pterm_slave = my_tcgetattr(slave_pty_fd, "slave pty")) ||
       command_is_dead ||
       always_echo 
       )
    /* race condition here: SIGCHLD may not yet have been caught */
    return;

  assert (pterm_slave != NULL);
  
  if (tcsetattr(STDIN_FILENO, TCSANOW, pterm_slave) < 0 && errno != ENOTTY) /* @@@ */
    myerror ("cannot prepare terminal (tcsetattr error on stdin)");

  term_eof = pterm_slave -> c_cc[VEOF];
  
  /* if the --always-readline option is set with argument "assword:", determine whether prompt ends with "assword:\s" */
  if (should_echo_anyway && password_prompt_search_string) {
    char *p, *q;

    assert(strlen(saved_rl_state.raw_prompt) < BUFFSIZE);
    p = saved_rl_state.raw_prompt + strlen(saved_rl_state.raw_prompt) - 1;
    q =
      password_prompt_search_string + strlen(password_prompt_search_string) -
      1;
    while (*p == ' ')           /* skip trailing spaces in prompt */
      p--;
    while (p >= saved_rl_state.raw_prompt && q >= password_prompt_search_string)
      if (*p-- != *q--)
        break;

    if (q < password_prompt_search_string)      /* found "assword:" */
      should_echo_anyway = FALSE;
  }


  if (!command_is_dead && (should_echo_anyway || pterm_slave->c_lflag & ECHO)) {
    redisplay = TRUE;
  } else {
    redisplay = FALSE;
  }
  if (pterm_slave)
    free(pterm_slave);
  set_echo(redisplay);          /* This is a bit weird: we want echo off all the time, because readline takes care
                                   of echoing, but as readline uses the current ECHO mode to determine whether
                                   you want echo or not, we must set it even if we know that readline will switch it
                                   off immediately   */
}
Пример #3
0
int
adapt_tty_winsize(int from_fd, int to_fd)
{
    int ret;

    struct winsize old_winsize = winsize;

    ret = ioctl(from_fd, TIOCGWINSZ, &winsize);
    DPRINTF1(DEBUG_SIGNALS, "ioctl (..., TIOCGWINSZ) = %d", ret);
    if (winsize.ws_col != old_winsize.ws_col || winsize.ws_row != old_winsize.ws_row) {
        DPRINTF4(DEBUG_SIGNALS, "ws.col: %d -> %d, ws.row: %d -> %d", old_winsize.ws_col, winsize.ws_col, old_winsize.ws_row, winsize.ws_row);
        if (always_readline &&!dont_wrap_command_waits())  /* if --always_readline option is set, the client will probably spew a */
            deferred_adapt_commands_window_size = TRUE;      /* volley of control chars at us when its terminal is resized. Hence we don't do it now */
        else {
            ret = ioctl(to_fd, TIOCSWINSZ, &winsize);
            DPRINTF1(DEBUG_SIGNALS, "ioctl (..., TIOCSWINSZ) = %d", ret);
        }
        DPRINTF2(DEBUG_READLINE, "rl_prompt: %s, line_buffer: %s", mangle_string_for_debug_log(rl_prompt, 100), rl_line_buffer);
        rl_set_screen_size(winsize.ws_row, winsize.ws_col); /* this is safe: we know that right now rlwrap is not calling
                                                           the readline library because we keep SIGWINCH blocked all the time */

        if (!within_line_edit && !skip_rlwrap()) {
            wipe_textarea(&old_winsize);

            received_WINCH = TRUE;           /* we can't start line edit in signal handler, so we only set a flag */
        } else if (within_line_edit) {      /* try to keep displayed line tidy */
            wipe_textarea(&old_winsize);
            rl_on_new_line();
            rl_redisplay();

        }

        return (!always_readline || dont_wrap_command_waits()); /* pass the signal on (except when always_readline is set and command is not waiting) */
    } else {                      /* window size has not changed */
        return FALSE;
    }

}