Logo Search packages:      
Sourcecode: iterm version File versions  Download package

TerminalIO* TtyTerminalIO_new ( int  width,
int  height,
char *  program_name,
char *  argv[] 
)

TTYIO Constructor.
Meaings of programe_name and argv are same as execvp(3)

Parameters:
width width of window
height height of window
program_name name of program
argv argments for program terminated by NULL
Returns:
reference to ttyio object

Definition at line 307 of file ttyio.c.

References TtyTerminalIO_new().

Referenced by TtyTerminalIO_new().

{
  pid_t pid;
  int master_fd;
  char slave_name[20];
  struct Concrete_IO *cio;
  TerminalIO *tio;

#ifdef SIGTTOU
      /* so that TIOCSWINSZ || TIOCSIZE doesn't block */
  signal(SIGTTOU,SIG_IGN);
#endif
  if ( (master_fd = open_master(slave_name)) < 0 )
      return NULL;

  if ( (tio = malloc(sizeof(TerminalIO))) == NULL )
      return NULL;
  
  if ( (cio = malloc(sizeof(struct Concrete_IO))) == NULL )
      return NULL;

  strcpy(cio->slave_name,slave_name);
  tty_name = cio->slave_name;
  
  signal(SIGCHLD,finish_child);
  if ( (pid = fork()) < 0 )
      return NULL;

  if(pid)
  {
    child = cio->child = pid;
    cio->fd = master_fd;
    tio->concrete_io = cio;
    tio->read = tty_read;
    tio->write = tty_write;
    tio->tell_window_size = tty_tell_window_size;
    tio->concrete_io->closed = 0;
    return tio;
  }
  else /* child */
  {
    int fd;

#if defined(HAVE_LIBUTEMPTER)    
    write_utmp(cio->slave_name,master_fd);
#else
    write_utmp(cio->slave_name);
#endif
    if ( (fd = get_slave_fd(master_fd,slave_name)) < 0)
      exit(1);

    if ( set_window_size(fd,width,height) < 0 )
      exit(1);

    if ( dup_fds(fd) < 0 )
      exit(1);

    chown(slave_name,getuid(),getgid());
    setgid(getgid());
    setuid(getuid());
    signal(SIGINT,SIG_DFL);
    signal(SIGQUIT,SIG_DFL);
    signal(SIGCHLD,SIG_DFL);
    execvp(program_name,argv);
  }
  return NULL;
}


Generated by  Doxygen 1.6.0   Back to index