diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-08-28 13:01:04 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-08-28 13:01:04 +0000 |
commit | aa118bc4839dcbadcc66dab8bd8600c249ca735e (patch) | |
tree | 713527ef385b9d968c64ac0e90a9c14e323bfdf1 /usr.bin | |
parent | df7c3d11b4f76b2df4cb36445cc1109db51ff25d (diff) |
Make session_update_activity more useful and use it in more places.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-attach-session.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-new-session.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-switch-client.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/server-client.c | 12 | ||||
-rw-r--r-- | usr.bin/tmux/server-fn.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 23 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 |
7 files changed, 31 insertions, 26 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c index 6fb693bdb9f..0f885bcafca 100644 --- a/usr.bin/tmux/cmd-attach-session.c +++ b/usr.bin/tmux/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-attach-session.c,v 1.39 2015/08/28 12:16:28 nicm Exp $ */ +/* $OpenBSD: cmd-attach-session.c,v 1.40 2015/08/28 13:01:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -135,7 +135,7 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, c->session = s; status_timer_start(c); notify_attached_session_changed(c); - session_update_activity(s); + session_update_activity(s, NULL); server_redraw_client(c); s->curw->flags &= ~WINLINK_ALERTFLAGS; } else { @@ -180,7 +180,7 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, c->session = s; status_timer_start(c); notify_attached_session_changed(c); - session_update_activity(s); + session_update_activity(s, NULL); server_redraw_client(c); s->curw->flags &= ~WINLINK_ALERTFLAGS; diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index 58ea2402f99..7d6238c374d 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-session.c,v 1.69 2015/08/28 12:16:28 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.70 2015/08/28 13:01:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -277,7 +277,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) c->session = s; status_timer_start(c); notify_attached_session_changed(c); - session_update_activity(s); + session_update_activity(s, NULL); server_redraw_client(c); } recalculate_sizes(); diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index b3e1767cd41..d52655867be 100644 --- a/usr.bin/tmux/cmd-switch-client.c +++ b/usr.bin/tmux/cmd-switch-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-switch-client.c,v 1.28 2015/08/28 12:16:28 nicm Exp $ */ +/* $OpenBSD: cmd-switch-client.c,v 1.29 2015/08/28 13:01:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -128,7 +128,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq) c->last_session = c->session; c->session = s; status_timer_start(c); - session_update_activity(s); + session_update_activity(s, NULL); recalculate_sizes(); server_check_unattached(); diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 93d19c61fa3..733cbe7eca5 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.148 2015/08/28 12:16:28 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.149 2015/08/28 13:01:03 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -561,9 +561,7 @@ server_client_handle_key(struct client *c, int key) /* Update the activity timer. */ if (gettimeofday(&c->activity_time, NULL) != 0) fatal("gettimeofday failed"); - memcpy(&s->last_activity_time, &s->activity_time, - sizeof s->last_activity_time); - memcpy(&s->activity_time, &c->activity_time, sizeof s->activity_time); + session_update_activity(s, &c->activity_time); /* Number keys jump to pane in identify mode. */ if (c->flags & CLIENT_IDENTIFY && key >= '0' && key <= '9') { @@ -981,6 +979,7 @@ server_client_msg_dispatch(struct client *c) struct msg_stdin_data stdindata; const char *data; ssize_t n, datalen; + struct session *s; if ((n = imsg_read(&c->ibuf)) == -1 || n == 0) return (-1); @@ -1064,11 +1063,12 @@ server_client_msg_dispatch(struct client *c) if (c->tty.fd == -1) /* exited in the meantime */ break; + s = c->session; if (gettimeofday(&c->activity_time, NULL) != 0) fatal("gettimeofday"); - if (c->session != NULL) - session_update_activity(c->session); + if (s != NULL) + session_update_activity(s, &c->activity_time); tty_start_tty(&c->tty); server_redraw_client(c); diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index 7b4404e3400..effceceef1c 100644 --- a/usr.bin/tmux/server-fn.c +++ b/usr.bin/tmux/server-fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-fn.c,v 1.86 2015/08/28 12:16:28 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.87 2015/08/28 13:01:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -421,7 +421,7 @@ server_destroy_session(struct session *s) c->session = s_new; status_timer_start(c); notify_attached_session_changed(c); - session_update_activity(s_new); + session_update_activity(s_new, NULL); server_redraw_client(c); } } diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index e4a2305cb65..0e8d2798d47 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.50 2015/06/05 18:18:32 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.51 2015/08/28 13:01:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -112,10 +112,6 @@ session_create(const char *name, int argc, char **argv, const char *path, s->references = 1; s->flags = 0; - if (gettimeofday(&s->creation_time, NULL) != 0) - fatal("gettimeofday failed"); - session_update_activity(s); - s->cwd = dup(cwd); s->curw = NULL; @@ -133,6 +129,10 @@ session_create(const char *name, int argc, char **argv, const char *path, memcpy(s->tio, tio, sizeof *s->tio); } + if (gettimeofday(&s->creation_time, NULL) != 0) + fatal("gettimeofday failed"); + session_update_activity(s, &s->creation_time); + s->sx = sx; s->sy = sy; @@ -224,12 +224,17 @@ session_check_name(const char *name) return (*name != '\0' && name[strcspn(name, ":.")] == '\0'); } -/* Update session active time. */ +/* Update activity time. */ void -session_update_activity(struct session *s) +session_update_activity(struct session *s, struct timeval *from) { - if (gettimeofday(&s->activity_time, NULL) != 0) - fatal("gettimeofday"); + struct timeval *last = &s->last_activity_time; + + memcpy(last, &s->activity_time, sizeof *last); + if (from == NULL) + gettimeofday(&s->activity_time, NULL); + else + memcpy(&s->activity_time, from, sizeof s->activity_time); } /* Find the next usable session. */ diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index af650a3e39c..3d5e0ed22f5 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.535 2015/08/28 12:25:42 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.536 2015/08/28 13:01:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -2248,7 +2248,7 @@ struct session *session_create(const char *, int, char **, const char *, void session_destroy(struct session *); void session_unref(struct session *); int session_check_name(const char *); -void session_update_activity(struct session *); +void session_update_activity(struct session *, struct timeval *); struct session *session_next_session(struct session *); struct session *session_previous_session(struct session *); struct winlink *session_new(struct session *, const char *, int, char **, |