summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2009-08-11 20:29:04 +0000
committernicm <nicm@openbsd.org>2009-08-11 20:29:04 +0000
commit3542b2713bca8767db54e9826607b5340f65e6ba (patch)
treef59acce4e2cb96c43789f2b8869984c254ad1e43
parenturtw does not do hostap, so remove the hostap example; (diff)
downloadwireguard-openbsd-3542b2713bca8767db54e9826607b5340f65e6ba.tar.xz
wireguard-openbsd-3542b2713bca8767db54e9826607b5340f65e6ba.zip
Add a TTY_OPENED flag and tidy a little.
-rw-r--r--usr.bin/tmux/tmux.h3
-rw-r--r--usr.bin/tmux/tty.c36
2 files changed, 20 insertions, 19 deletions
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index c196b802142..f7b23dfa4bb 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.76 2009/08/11 19:32:25 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.77 2009/08/11 20:29:04 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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;
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index 514d6140512..03084c4a1ef 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.20 2009/08/11 19:32:25 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.21 2009/08/11 20:29:05 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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);
+
+ buffer_destroy(tty->in);
+ buffer_destroy(tty->out);
- close(tty->fd);
- tty->fd = -1;
+ tty->flags &= ~TTY_OPENED;
+ }
- buffer_destroy(tty->in);
- buffer_destroy(tty->out);
+ if (tty->fd != -1) {
+ close(tty->fd);
+ tty->fd = -1;
+ }
}
void