diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-08-28 13:12:21 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-08-28 13:12:21 +0000 |
commit | effd5cf2561114fdc31f69435c049ea8bb45b740 (patch) | |
tree | 5d5e33b506069690edbed9e09ba411f1b5f99dd1 /usr.bin | |
parent | aa118bc4839dcbadcc66dab8bd8600c249ca735e (diff) |
Per-session timers for locking, and remove the global one-second timer.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-set-option.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/server.c | 47 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 42 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 |
4 files changed, 48 insertions, 49 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index 70d3c49bc90..aab181187b6 100644 --- a/usr.bin/tmux/cmd-set-option.c +++ b/usr.bin/tmux/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-option.c,v 1.77 2015/08/28 12:16:28 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.78 2015/08/28 13:12:20 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -176,7 +176,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_ERROR); } - /* Start or stop timers when name or status options changed. */ + /* Start or stop timers if necessary. */ if (strcmp(oe->name, "automatic-rename") == 0) { RB_FOREACH(w, windows, &windows) { if (options_get_number(&w->options, "automatic-rename")) diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index 83ff9513135..787b334d27e 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.133 2015/08/28 12:31:55 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.134 2015/08/28 13:12:20 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -46,7 +46,6 @@ struct clients clients; int server_fd; int server_shutdown; struct event server_ev_accept; -struct event server_ev_second; struct session *marked_session; struct winlink *marked_winlink; @@ -163,9 +162,8 @@ server_create_socket(void) int server_start(int lockfd, char *lockfile) { - int pair[2]; - struct timeval tv; - char *cause; + int pair[2]; + char *cause; /* The first client is special and gets a socketpair; create it. */ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0) @@ -243,11 +241,6 @@ server_start(int lockfd, char *lockfile) server_add_accept(0); - memset(&tv, 0, sizeof tv); - tv.tv_sec = 1; - evtimer_set(&server_ev_second, server_second_callback, NULL); - evtimer_add(&server_ev_second, &tv); - set_signals(server_signal_callback); server_loop(); status_prompt_save_history(); @@ -498,37 +491,3 @@ server_child_stopped(pid_t pid, int status) } } } - -/* Handle once-per-second timer events. */ -void -server_second_callback(unused int fd, unused short events, unused void *arg) -{ - struct timeval tv; - - server_lock_sessions(); - - evtimer_del(&server_ev_second); - memset(&tv, 0, sizeof tv); - tv.tv_sec = 1; - evtimer_add(&server_ev_second, &tv); -} - -/* Lock any sessions which have timed out. */ -void -server_lock_sessions(void) -{ - struct session *s; - int timeout; - time_t t; - - t = time(NULL); - RB_FOREACH(s, sessions, &sessions) { - if (s->flags & SESSION_UNATTACHED) - continue; - timeout = options_get_number(&s->options, "lock-after-time"); - if (timeout > 0 && t > s->activity_time.tv_sec + timeout) { - server_lock_session(s); - recalculate_sizes(); - } - } -} diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 0e8d2798d47..fe746303fc7 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.51 2015/08/28 13:01:03 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.52 2015/08/28 13:12:20 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -33,6 +33,8 @@ struct session_groups session_groups; void session_free(int, short, void *); +void session_lock_timer(int, short, void *); + struct winlink *session_next_alert(struct winlink *); struct winlink *session_previous_alert(struct winlink *); @@ -108,7 +110,7 @@ session_create(const char *name, int argc, char **argv, const char *path, struct session *s; struct winlink *wl; - s = xmalloc(sizeof *s); + s = xcalloc(1, sizeof *s); s->references = 1; s->flags = 0; @@ -149,6 +151,10 @@ session_create(const char *name, int argc, char **argv, const char *path, } RB_INSERT(sessions, &sessions, s); + if (gettimeofday(&s->creation_time, NULL) != 0) + fatal("gettimeofday failed"); + session_update_activity(s, &s->creation_time); + if (argc >= 0) { wl = session_new(s, NULL, argc, argv, path, cwd, idx, cause); if (wl == NULL) { @@ -200,6 +206,9 @@ session_destroy(struct session *s) free(s->tio); + if (event_initialized(&s->lock_timer)) + event_del(&s->lock_timer); + session_group_remove(s); environ_free(&s->environ); options_free(&s->options); @@ -224,17 +233,46 @@ session_check_name(const char *name) return (*name != '\0' && name[strcspn(name, ":.")] == '\0'); } +/* Lock session if it has timed out. */ +void +session_lock_timer(unused int fd, unused short events, void *arg) +{ + struct session *s = arg; + + if (s->flags & SESSION_UNATTACHED) + return; + + log_debug("session %s locked, activity time %lld", s->name, + (long long)s->activity_time.tv_sec); + + server_lock_session(s); + recalculate_sizes(); +} + /* Update activity time. */ void session_update_activity(struct session *s, struct timeval *from) { struct timeval *last = &s->last_activity_time; + struct timeval tv; 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); + + if (evtimer_initialized(&s->lock_timer)) + evtimer_del(&s->lock_timer); + else + evtimer_set(&s->lock_timer, session_lock_timer, s); + + if (~s->flags & SESSION_UNATTACHED) { + timerclear(&tv); + tv.tv_sec = options_get_number(&s->options, "lock-after-time"); + if (tv.tv_sec != 0) + evtimer_add(&s->lock_timer, &tv); + } } /* Find the next usable session. */ diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 3d5e0ed22f5..c7ceaee35ff 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.536 2015/08/28 13:01:03 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.537 2015/08/28 13:12:20 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -993,6 +993,8 @@ struct session { struct timeval activity_time; struct timeval last_activity_time; + struct event lock_timer; + u_int sx; u_int sy; |