summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-10-31 13:12:04 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-10-31 13:12:04 +0000
commitf751bdbad271dd30657b99762bcd6e5a8a7fd9bc (patch)
tree6e4a537e8c2de893b7217f66bdcc507f5a5e2131 /usr.bin/tmux
parent4bed8e2b496820d95fdc693565ad55928a2131f8 (diff)
The output log is only useful once and it means creating a file, so open
it once at startup instead of in every call to tty_open.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/server-client.c3
-rw-r--r--usr.bin/tmux/server.c4
-rw-r--r--usr.bin/tmux/tmux.h5
-rw-r--r--usr.bin/tmux/tty.c45
4 files changed, 27 insertions, 30 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 25d214fb2d7..4e3fe2af15c 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.165 2015/10/31 08:13:58 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.166 2015/10/31 13:12:03 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1178,7 +1178,6 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg)
proc_send(c->peer, MSG_STDIN, -1, NULL, 0);
c->tty.fd = -1;
- c->tty.log_fd = -1;
close(c->fd);
c->fd = -1;
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index df145a16a2a..256cbeb597d 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.145 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.146 2015/10/31 13:12:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -173,6 +173,8 @@ server_start(struct event_base *base, int lockfd, char *lockfile)
}
close(pair[0]);
+ if (debug_level > 3)
+ tty_create_log();
if (pledge("stdio rpath wpath cpath fattr unix recvfd proc exec tty "
"ps", NULL) != 0)
fatal("pledge failed");
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index ce8ae8f097e..c2bd0be20b5 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.569 2015/10/31 08:13:58 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.570 2015/10/31 13:12:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1102,8 +1102,6 @@ struct tty {
int fd;
struct bufferevent *event;
- int log_fd;
-
struct termios tio;
struct grid_cell cell;
@@ -1555,6 +1553,7 @@ void environ_update(const char *, struct environ *, struct environ *);
void environ_push(struct environ *);
/* tty.c */
+void tty_create_log(void);
void tty_init_termios(int, struct termios *, struct bufferevent *);
void tty_raw(struct tty *, const char *);
void tty_attributes(struct tty *, const struct grid_cell *,
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index acc33ea1adb..99d5a1efb8e 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.191 2015/10/27 15:58:43 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.192 2015/10/31 13:12:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,6 +31,8 @@
#include "tmux.h"
+static int tty_log_fd = -1;
+
void tty_read_callback(struct bufferevent *, void *);
void tty_error_callback(struct bufferevent *, short, void *);
@@ -59,6 +61,18 @@ void tty_default_colours(struct grid_cell *, const struct window_pane *);
#define tty_pane_full_width(tty, ctx) \
((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
tty_init(struct tty *tty, struct client *c, int fd, char *term)
{
@@ -68,7 +82,6 @@ tty_init(struct tty *tty, struct client *c, int fd, char *term)
return (-1);
memset(tty, 0, sizeof *tty);
- tty->log_fd = -1;
if (term == NULL || *term == '\0')
tty->termname = xstrdup("unknown");
@@ -139,17 +152,6 @@ tty_set_size(struct tty *tty, u_int sx, u_int sy) {
int
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);
if (tty->term == NULL) {
tty_close(tty);
@@ -308,11 +310,6 @@ tty_stop_tty(struct tty *tty)
void
tty_close(struct tty *tty)
{
- if (tty->log_fd != -1) {
- close(tty->log_fd);
- tty->log_fd = -1;
- }
-
if (event_initialized(&tty->key_timer))
evtimer_del(&tty->key_timer);
tty_stop_tty(tty);
@@ -406,8 +403,8 @@ tty_puts(struct tty *tty, const char *s)
return;
bufferevent_write(tty->event, s, strlen(s));
- if (tty->log_fd != -1)
- write(tty->log_fd, s, strlen(s));
+ if (tty_log_fd != -1)
+ write(tty_log_fd, s, strlen(s));
}
void
@@ -438,16 +435,16 @@ tty_putc(struct tty *tty, u_char ch)
tty->cx++;
}
- if (tty->log_fd != -1)
- write(tty->log_fd, &ch, 1);
+ if (tty_log_fd != -1)
+ write(tty_log_fd, &ch, 1);
}
void
tty_putn(struct tty *tty, const void *buf, size_t len, u_int width)
{
bufferevent_write(tty->event, buf, len);
- if (tty->log_fd != -1)
- write(tty->log_fd, buf, len);
+ if (tty_log_fd != -1)
+ write(tty_log_fd, buf, len);
tty->cx += width;
}