int tty_open(struct tty *tty, const char *overrides, char **cause) { char out[64]; int fd; if (debug_level > 3) { xsnprintf(out, sizeof out, "tmux-out-%ld.log", (long) getpid()); fd = open(out, O_WRONLY|O_CREAT|O_TRUNC, 0644); if (fd != -1 && fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) fatal("fcntl failed"); tty->log_fd = fd; } tty->term = tty_term_find(tty->termname, tty->fd, overrides, cause); if (tty->term == NULL) { tty_close(tty); return (-1); } tty->flags |= TTY_OPENED; tty->flags &= ~(TTY_NOCURSOR|TTY_FREEZE|TTY_ESCAPE); tty->event = bufferevent_new( tty->fd, tty_read_callback, NULL, tty_error_callback, tty); tty_start_tty(tty); tty_keys_init(tty); return (0); }
int tty_open(struct tty *tty, char **cause) { int mode; tty->fd = open(tty->path, O_RDWR|O_NONBLOCK); if (tty->fd == -1) { xasprintf(cause, "%s: %s", tty->path, strerror(errno)); return (-1); } if ((mode = fcntl(tty->fd, F_GETFL)) == -1) fatal("fcntl failed"); if (fcntl(tty->fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failedo"); if (fcntl(tty->fd, F_SETFD, FD_CLOEXEC) == -1) fatal("fcntl failed"); if (debug_level > 3) tty->log_fd = open("tmux.out", O_WRONLY|O_CREAT|O_TRUNC, 0644); else tty->log_fd = -1; if ((tty->term = tty_term_find(tty->termname, tty->fd, cause)) == NULL) goto error; tty->in = buffer_create(BUFSIZ); tty->out = buffer_create(BUFSIZ); tty->flags &= TTY_UTF8; tty_start_tty(tty); tty_keys_init(tty); tty_fill_acs(tty); return (0); error: close(tty->fd); tty->fd = -1; return (-1); }