summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-06-02 08:17:28 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-06-02 08:17:28 +0000
commit804f38b98845b180655d1befbd7c38480996b448 (patch)
treef046b2032aedad072f8fa3724289e33c763e187a
parent336161a702d4770a5311111b53e973508dce1fc6 (diff)
Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.
-rw-r--r--usr.bin/tmux/control.c26
-rw-r--r--usr.bin/tmux/server-client.c6
-rw-r--r--usr.bin/tmux/tmux.c16
-rw-r--r--usr.bin/tmux/tmux.h3
-rw-r--r--usr.bin/tmux/tty-keys.c4
-rw-r--r--usr.bin/tmux/window-copy.c17
6 files changed, 47 insertions, 25 deletions
diff --git a/usr.bin/tmux/control.c b/usr.bin/tmux/control.c
index d92d5f56120..9d28b398bf3 100644
--- a/usr.bin/tmux/control.c
+++ b/usr.bin/tmux/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.36 2020/06/01 21:08:05 nicm Exp $ */
+/* $OpenBSD: control.c,v 1.37 2020/06/02 08:17:27 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -45,6 +45,7 @@
struct control_block {
size_t size;
char *line;
+ uint64_t t;
TAILQ_ENTRY(control_block) entry;
TAILQ_ENTRY(control_block) all_entry;
@@ -152,6 +153,21 @@ control_add_pane(struct client *c, struct window_pane *wp)
return (cp);
}
+/* Get actual pane for this client. */
+static struct window_pane *
+control_window_pane(struct client *c, u_int pane)
+{
+ struct window_pane *wp;
+
+ if (c->session == NULL)
+ return (NULL);
+ if ((wp = window_pane_find_by_id(pane)) == NULL)
+ return (NULL);
+ if (winlink_find_by_window(&c->session->windows, wp->window) == NULL)
+ return (NULL);
+ return (wp);
+}
+
/* Reset control offsets. */
void
control_reset_offsets(struct client *c)
@@ -253,6 +269,7 @@ control_write(struct client *c, const char *fmt, ...)
cb = xcalloc(1, sizeof *cb);
xvasprintf(&cb->line, fmt, ap);
TAILQ_INSERT_TAIL(&cs->all_blocks, cb, all_entry);
+ cb->t = get_timer();
log_debug("%s: %s: storing line: %s", __func__, c->name, cb->line);
bufferevent_enable(cs->write_event, EV_WRITE);
@@ -290,6 +307,7 @@ control_write_output(struct client *c, struct window_pane *wp)
cb = xcalloc(1, sizeof *cb);
cb->size = new_size;
TAILQ_INSERT_TAIL(&cs->all_blocks, cb, all_entry);
+ cb->t = get_timer();
TAILQ_INSERT_TAIL(&cp->blocks, cb, entry);
log_debug("%s: %s: new output block of %zu for %%%u", __func__, c->name,
@@ -446,15 +464,13 @@ static int
control_write_pending(struct client *c, struct control_pane *cp, size_t limit)
{
struct control_state *cs = c->control_state;
- struct session *s = c->session;
struct window_pane *wp = NULL;
struct evbuffer *message = NULL;
size_t used = 0, size;
struct control_block *cb, *cb1;
- if (s == NULL ||
- (wp = window_pane_find_by_id(cp->pane)) == NULL ||
- winlink_find_by_window(&s->windows, wp->window) == NULL) {
+ wp = control_window_pane(c, cp->pane);
+ if (wp == NULL) {
TAILQ_FOREACH_SAFE(cb, &cp->blocks, entry, cb1) {
TAILQ_REMOVE(&cp->blocks, cb, entry);
control_free_block(cs, cb);
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 4ef882c22a2..e5f9b3d9d92 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.353 2020/06/01 20:58:42 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.354 2020/06/02 08:17:27 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1779,7 +1779,9 @@ server_client_check_exit(struct client *c)
struct client_file *cf;
const char *name = c->exit_session;
- if ((c->flags & CLIENT_EXITED) || (~c->flags & CLIENT_EXIT))
+ if (c->flags & (CLIENT_DEAD|CLIENT_EXITED))
+ return;
+ if (~c->flags & CLIENT_EXIT)
return;
if (c->flags & CLIENT_CONTROL) {
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 13346c966cf..4a610b4c769 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.201 2020/05/16 16:07:55 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.202 2020/06/02 08:17:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -240,6 +240,20 @@ setblocking(int fd, int state)
}
}
+uint64_t
+get_timer(void)
+{
+ struct timespec ts;
+
+ /*
+ * We want a timestamp in milliseconds suitable for time measurement,
+ * so prefer the monotonic clock.
+ */
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
+ clock_gettime(CLOCK_REALTIME, &ts);
+ return ((ts.tv_sec * 1000ULL) + (ts.tv_nsec / 1000000ULL));
+}
+
const char *
sig2name(int signo)
{
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index b334500f50c..d2baefeece0 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1059 2020/06/01 19:39:25 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1060 2020/06/02 08:17:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1852,6 +1852,7 @@ extern int ptm_fd;
extern const char *shell_command;
int checkshell(const char *);
void setblocking(int, int);
+uint64_t get_timer(void);
const char *sig2name(int);
const char *find_cwd(void);
const char *find_home(void);
diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c
index 7328937165a..9c12885ed36 100644
--- a/usr.bin/tmux/tty-keys.c
+++ b/usr.bin/tmux/tty-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty-keys.c,v 1.138 2020/05/25 18:57:25 nicm Exp $ */
+/* $OpenBSD: tty-keys.c,v 1.139 2020/06/02 08:17:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -637,8 +637,6 @@ tty_keys_next(struct tty *tty)
struct mouse_event m = { 0 };
struct key_event *event;
- gettimeofday(&tv, NULL);
-
/* Get key buffer. */
buf = EVBUFFER_DATA(tty->in);
len = EVBUFFER_LENGTH(tty->in);
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 50e037d6bad..a78954a63f6 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.291 2020/05/25 18:19:29 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.292 2020/06/02 08:17:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2934,15 +2934,6 @@ window_copy_search(struct window_mode_entry *wme, int direction, int regex)
return (found);
}
-static uint64_t
-window_copy_get_time(void)
-{
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
- return ((tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000ULL));
-}
-
static int
window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
int regex)
@@ -2985,11 +2976,11 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
return (0);
}
}
- tstart = window_copy_get_time();
+ tstart = get_timer();
start = 0;
end = gd->hsize + gd->sy;
- stop = window_copy_get_time() + WINDOW_COPY_SEARCH_ALL_TIMEOUT;
+ stop = get_timer() + WINDOW_COPY_SEARCH_ALL_TIMEOUT;
again:
free(data->searchmark);
@@ -3027,7 +3018,7 @@ again:
px++;
}
- t = window_copy_get_time();
+ t = get_timer();
if (t - tstart > WINDOW_COPY_SEARCH_TIMEOUT) {
data->timeout = 1;
break;