=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/tty.c,v retrieving revision 1.29 retrieving revision 1.30 diff -c -r1.29 -r1.30 *** src/usr.bin/tmux/tty.c 2009/09/22 19:11:52 1.29 --- src/usr.bin/tmux/tty.c 2009/09/23 06:05:02 1.30 *************** *** 1,4 **** ! /* $OpenBSD: tty.c,v 1.29 2009/09/22 19:11:52 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: tty.c,v 1.30 2009/09/23 06:05:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 44,59 **** const struct grid_cell *, const struct grid_utf8 *); void ! tty_init(struct tty *tty, int fd, char *path, char *term) { ! tty->path = xstrdup(path); ! tty->fd = fd; tty->log_fd = -1; if (term == NULL || *term == '\0') tty->termname = xstrdup("unknown"); else tty->termname = xstrdup(term); tty->flags = 0; tty->term_flags = 0; } --- 44,74 ---- const struct grid_cell *, const struct grid_utf8 *); void ! tty_init(struct tty *tty, int fd, char *term) { ! int mode; ! char *path; ! ! memset(tty, 0, sizeof *tty); tty->log_fd = -1; if (term == NULL || *term == '\0') tty->termname = xstrdup("unknown"); else tty->termname = xstrdup(term); + + if ((mode = fcntl(fd, F_GETFL)) == -1) + fatal("fcntl failed"); + if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1) + fatal("fcntl failed"); + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) + fatal("fcntl failed"); + tty->fd = fd; + + if ((path = ttyname(fd)) == NULL) + fatalx("ttyname failed"); + tty->path = xstrdup(path); + tty->flags = 0; tty->term_flags = 0; } *************** *** 61,87 **** int tty_open(struct tty *tty, const char *overrides, char **cause) { ! int mode; ! if (tty->fd == -1) { ! 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 failed"); - 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; tty->term = tty_term_find(tty->termname, tty->fd, overrides, cause); if (tty->term == NULL) { --- 76,89 ---- int tty_open(struct tty *tty, const char *overrides, char **cause) { ! int fd; ! if (debug_level > 3) { ! fd = open("tmux.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) {