version 1.191, 2015/10/27 15:58:43 |
version 1.192, 2015/10/31 13:12:03 |
|
|
|
|
#include "tmux.h" |
#include "tmux.h" |
|
|
|
static int tty_log_fd = -1; |
|
|
void tty_read_callback(struct bufferevent *, void *); |
void tty_read_callback(struct bufferevent *, void *); |
void tty_error_callback(struct bufferevent *, short, void *); |
void tty_error_callback(struct bufferevent *, short, void *); |
|
|
|
|
#define tty_pane_full_width(tty, ctx) \ |
#define tty_pane_full_width(tty, ctx) \ |
((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) |
((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) |
|
|
|
void |
|
tty_create_log(void) |
|
{ |
|
char name[64]; |
|
|
|
xsnprintf(name, sizeof name, "tmux-out-%ld.log", (long)getpid()); |
|
|
|
tty_log_fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644); |
|
if (tty_log_fd != -1 && fcntl(tty_log_fd, F_SETFD, FD_CLOEXEC) == -1) |
|
fatal("fcntl failed"); |
|
} |
|
|
int |
int |
tty_init(struct tty *tty, struct client *c, int fd, char *term) |
tty_init(struct tty *tty, struct client *c, int fd, char *term) |
{ |
{ |
|
|
return (-1); |
return (-1); |
|
|
memset(tty, 0, sizeof *tty); |
memset(tty, 0, sizeof *tty); |
tty->log_fd = -1; |
|
|
|
if (term == NULL || *term == '\0') |
if (term == NULL || *term == '\0') |
tty->termname = xstrdup("unknown"); |
tty->termname = xstrdup("unknown"); |
|
|
int |
int |
tty_open(struct tty *tty, char **cause) |
tty_open(struct tty *tty, 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, cause); |
tty->term = tty_term_find(tty->termname, tty->fd, cause); |
if (tty->term == NULL) { |
if (tty->term == NULL) { |
tty_close(tty); |
tty_close(tty); |
|
|
void |
void |
tty_close(struct tty *tty) |
tty_close(struct tty *tty) |
{ |
{ |
if (tty->log_fd != -1) { |
|
close(tty->log_fd); |
|
tty->log_fd = -1; |
|
} |
|
|
|
if (event_initialized(&tty->key_timer)) |
if (event_initialized(&tty->key_timer)) |
evtimer_del(&tty->key_timer); |
evtimer_del(&tty->key_timer); |
tty_stop_tty(tty); |
tty_stop_tty(tty); |
|
|
return; |
return; |
bufferevent_write(tty->event, s, strlen(s)); |
bufferevent_write(tty->event, s, strlen(s)); |
|
|
if (tty->log_fd != -1) |
if (tty_log_fd != -1) |
write(tty->log_fd, s, strlen(s)); |
write(tty_log_fd, s, strlen(s)); |
} |
} |
|
|
void |
void |
|
|
tty->cx++; |
tty->cx++; |
} |
} |
|
|
if (tty->log_fd != -1) |
if (tty_log_fd != -1) |
write(tty->log_fd, &ch, 1); |
write(tty_log_fd, &ch, 1); |
} |
} |
|
|
void |
void |
tty_putn(struct tty *tty, const void *buf, size_t len, u_int width) |
tty_putn(struct tty *tty, const void *buf, size_t len, u_int width) |
{ |
{ |
bufferevent_write(tty->event, buf, len); |
bufferevent_write(tty->event, buf, len); |
if (tty->log_fd != -1) |
if (tty_log_fd != -1) |
write(tty->log_fd, buf, len); |
write(tty_log_fd, buf, len); |
tty->cx += width; |
tty->cx += width; |
} |
} |
|
|