mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-26 10:03:08 +01:00
Add a TTY_OPENED flag and tidy a little.
This commit is contained in:
parent
ff65e37545
commit
4ec8ade11c
1
tmux.h
1
tmux.h
@ -869,6 +869,7 @@ struct tty {
|
||||
#define TTY_ESCAPE 0x4
|
||||
#define TTY_UTF8 0x8
|
||||
#define TTY_STARTED 0x10
|
||||
#define TTY_OPENED 0x20
|
||||
int flags;
|
||||
|
||||
int term_flags;
|
||||
|
34
tty.c
34
tty.c
@ -80,8 +80,11 @@ tty_open(struct tty *tty, const char *overrides, char **cause)
|
||||
tty->log_fd = -1;
|
||||
|
||||
tty->term = tty_term_find(tty->termname, tty->fd, overrides, cause);
|
||||
if (tty->term == NULL)
|
||||
goto error;
|
||||
if (tty->term == NULL) {
|
||||
tty_close(tty);
|
||||
return (-1);
|
||||
}
|
||||
tty->flags |= TTY_OPENED;
|
||||
|
||||
tty->in = buffer_create(BUFSIZ);
|
||||
tty->out = buffer_create(BUFSIZ);
|
||||
@ -95,12 +98,6 @@ tty_open(struct tty *tty, const char *overrides, char **cause)
|
||||
tty_fill_acs(tty);
|
||||
|
||||
return (0);
|
||||
|
||||
error:
|
||||
close(tty->fd);
|
||||
tty->fd = -1;
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void
|
||||
@ -289,9 +286,6 @@ tty_get_acs(struct tty *tty, u_char ch)
|
||||
void
|
||||
tty_close(struct tty *tty)
|
||||
{
|
||||
if (tty->fd == -1)
|
||||
return;
|
||||
|
||||
if (tty->log_fd != -1) {
|
||||
close(tty->log_fd);
|
||||
tty->log_fd = -1;
|
||||
@ -299,14 +293,20 @@ tty_close(struct tty *tty)
|
||||
|
||||
tty_stop_tty(tty);
|
||||
|
||||
tty_term_free(tty->term);
|
||||
tty_keys_free(tty);
|
||||
if (tty->flags & TTY_OPENED) {
|
||||
tty_term_free(tty->term);
|
||||
tty_keys_free(tty);
|
||||
|
||||
close(tty->fd);
|
||||
tty->fd = -1;
|
||||
buffer_destroy(tty->in);
|
||||
buffer_destroy(tty->out);
|
||||
|
||||
buffer_destroy(tty->in);
|
||||
buffer_destroy(tty->out);
|
||||
tty->flags &= ~TTY_OPENED;
|
||||
}
|
||||
|
||||
if (tty->fd != -1) {
|
||||
close(tty->fd);
|
||||
tty->fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user