Beispiel #1
0
void
completely_mirror_slaves_output_settings()
{
  struct termios *pterm_stdin, *pterm_slave;  
  DEBUG_RANDOM_SLEEP;
  pterm_stdin = my_tcgetattr(STDIN_FILENO, "stdin");
  pterm_slave = my_tcgetattr(slave_pty_fd, "slave pty");
  if (pterm_slave && pterm_stdin) { /* no error message -  we can be called while slave is already dead */
    pterm_stdin -> c_oflag = pterm_slave -> c_oflag;
    tcsetattr(STDIN_FILENO, TCSANOW, pterm_stdin);
  }     
  myfree(pterm_slave);
  myfree(pterm_stdin);
  DEBUG_RANDOM_SLEEP;
}
Beispiel #2
0
void
write_EOF_to_master_pty()
{
  struct termios *pterm_slave = my_tcgetattr(slave_pty_fd, "slave pty");
  char *sent_EOF = mysavestring("?");

  *sent_EOF = (pterm_slave && pterm_slave->c_cc[VEOF]  ? pterm_slave->c_cc[VEOF] : 4) ; /*@@@ HL shouldn't we directly mysavestring(pterm_slave->c_cc[VEOF]) ??*/
  DPRINTF1(DEBUG_TERMIO, "Sending %s", mangle_string_for_debug_log(sent_EOF, MANGLE_LENGTH));
  put_in_output_queue(sent_EOF);
  myfree(pterm_slave);
  free(sent_EOF);
}
Beispiel #3
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   */
}
Beispiel #4
0
void
completely_mirror_slaves_terminal_settings()
{
  
  struct termios *pterm_slave;
  DEBUG_RANDOM_SLEEP;
  pterm_slave = my_tcgetattr(slave_pty_fd, "slave pty");
  log_terminal_settings(pterm_slave);
  if (pterm_slave && tcsetattr(STDIN_FILENO, TCSANOW, pterm_slave) < 0 && errno != ENOTTY)
    ;   /* myerror ("cannot prepare terminal (tcsetattr error on stdin)"); */
  myfree(pterm_slave);
  DEBUG_RANDOM_SLEEP;
}
Beispiel #5
0
static void android_os_Exec_setPtyUTF8Mode(JNIEnv *env, jobject clazz, jint fd, jboolean utf8Mode)
{
    struct termios tios;

    if (my_tcgetattr(fd, &tios) != 0)
        env->ThrowNew(env->FindClass("java/io/IOException"), "Failed to get terminal attributes");

    if (utf8Mode) {
        tios.c_iflag |= IUTF8;
    } else {
        tios.c_iflag &= ~IUTF8;
    }

    if (my_tcsetattr(fd, &tios) != 0)
        env->ThrowNew(env->FindClass("java/io/IOException"), "Failed to set terminal UTF-8 mode");
}
Beispiel #6
0
int
slave_is_in_raw_mode()
{
  struct termios *pterm_slave;
  static int been_warned = 0;
  int in_raw_mode;
  if (always_echo)
    return FALSE;

  if (command_is_dead)
    return FALSE; /* filter last words  too (even if ncurses-ridden) */
  if (!(pterm_slave = my_tcgetattr(slave_pty_fd, "slave pty"))) {
    if (been_warned++ == 1)     /* only warn once, but not the first time (as this usually means that the rlwrapped command has just died)
                                   - this is still a race when signals get delivered very late*/
      mywarn("tcgetattr error on slave pty (from parent process)");
    return TRUE;
  }     
 
  in_raw_mode = !(pterm_slave -> c_lflag & ICANON);
  myfree(pterm_slave);
  return in_raw_mode;
  
}
Beispiel #7
0
/* @@@ The next fuction is probably superfluous */
void
write_EOL_to_master_pty(char *received_eol)
{
  struct termios *pterm_slave = my_tcgetattr(slave_pty_fd, "slave pty");
  char *sent_eol = mysavestring("?");

  *sent_eol = *received_eol;
  if (pterm_slave) { 
    switch (*received_eol) {
    case '\n':
      if (pterm_slave->c_iflag & INLCR)
        *sent_eol = '\r';
      break;
    case '\r':
      if (pterm_slave->c_iflag & IGNCR)
        return;
      if (pterm_slave->c_iflag & ICRNL)
        *sent_eol = '\n';
    }
  } 
  put_in_output_queue(sent_eol);
  myfree(pterm_slave);
  free(sent_eol);
}