diff --git a/cmd-set-option.c b/cmd-set-option.c index d60b9a04..5230b4d3 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.81 2009-09-23 15:00:08 tcunha Exp $ */ +/* $Id: cmd-set-option.c,v 1.82 2009-10-11 23:30:28 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -63,6 +63,7 @@ const struct set_option_entry set_option_table[] = { { "history-limit", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, { "lock-after-time", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, { "lock-command", SET_OPTION_STRING, 0, 0, NULL }, + { "lock-server", SET_OPTION_FLAG, 0, 0, NULL }, { "message-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL }, { "message-bg", SET_OPTION_COLOUR, 0, 0, NULL }, { "message-fg", SET_OPTION_COLOUR, 0, 0, NULL }, diff --git a/server-msg.c b/server-msg.c index 35446723..2664643d 100644 --- a/server-msg.c +++ b/server-msg.c @@ -1,4 +1,4 @@ -/* $Id: server-msg.c,v 1.90 2009-09-25 17:47:42 tcunha Exp $ */ +/* $Id: server-msg.c,v 1.91 2009-10-11 23:30:28 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -104,7 +104,8 @@ server_msg_dispatch(struct client *c) tty_start_tty(&c->tty); server_redraw_client(c); recalculate_sizes(); - server_activity = time(NULL); + if (c->session != NULL) + c->session->activity = time(NULL); break; case MSG_ENVIRON: if (datalen != sizeof environdata) @@ -180,7 +181,8 @@ server_msg_command(struct client *c, struct msg_command_data *data) int argc; char **argv, *cause; - server_activity = time(NULL); + if (c->session != NULL) + c->session->activity = time(NULL); ctx.error = server_msg_command_error; ctx.print = server_msg_command_print; diff --git a/server.c b/server.c index 6dfc5f88..b6de3986 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.196 2009-10-11 23:25:44 tcunha Exp $ */ +/* $Id: server.c,v 1.197 2009-10-11 23:30:28 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -85,6 +85,8 @@ void server_check_window(struct window *); void server_check_redraw(struct client *); void server_set_title(struct client *); void server_check_timers(struct client *); +void server_lock_server(void); +void server_lock_sessions(void); void server_second_timers(void); int server_update_socket(void); @@ -250,8 +252,6 @@ server_start(char *path) key_bindings_init(); utf8_build(); - server_activity = time(NULL); - start_time = time(NULL); socket_path = path; @@ -845,10 +845,10 @@ server_handle_client(struct client *c) /* Process keys. */ keylist = options_get_data(&c->session->options, "prefix"); while (tty_keys_next(&c->tty, &key, mouse) == 0) { - server_activity = time(NULL); - if (c->session == NULL) return; + + c->session->activity = time(NULL); w = c->session->curw->window; wp = w->active; /* could die */ @@ -1257,6 +1257,51 @@ server_check_window(struct window *w) recalculate_sizes(); } +/* Lock the server if ALL sessions have hit the time limit. */ +void +server_lock_server(void) +{ + struct session *s; + u_int i; + int timeout; + time_t t; + + t = time(NULL); + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + if ((s = ARRAY_ITEM(&sessions, i)) == NULL) + continue; + + timeout = options_get_number(&s->options, "lock-after-time"); + if (timeout <= 0 || t <= s->activity + timeout) + return; /* not timed out */ + } + + server_lock(); + recalculate_sizes(); +} + +/* Lock any sessions which have timed out. */ +void +server_lock_sessions(void) +{ + struct session *s; + u_int i; + int timeout; + time_t t; + + t = time(NULL); + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + if ((s = ARRAY_ITEM(&sessions, i)) == NULL) + continue; + + timeout = options_get_number(&s->options, "lock-after-time"); + if (timeout > 0 && t > s->activity + timeout) { + server_lock_session(s); + recalculate_sizes(); + } + } +} + /* Call any once-per-second timers. */ void server_second_timers(void) @@ -1264,16 +1309,11 @@ server_second_timers(void) struct window *w; struct window_pane *wp; u_int i; - int xtimeout; - time_t t; - t = time(NULL); - - xtimeout = options_get_number(&global_s_options, "lock-after-time"); - if (xtimeout > 0 && t > server_activity + xtimeout) { - server_lock(); - recalculate_sizes(); - } + if (options_get_number(&global_s_options, "lock-server")) + server_lock_server(); + else + server_lock_sessions(); for (i = 0; i < ARRAY_LENGTH(&windows); i++) { w = ARRAY_ITEM(&windows, i); diff --git a/session.c b/session.c index b02cb06e..b6a23ad7 100644 --- a/session.c +++ b/session.c @@ -1,4 +1,4 @@ -/* $Id: session.c,v 1.67 2009-09-20 22:11:27 tcunha Exp $ */ +/* $Id: session.c,v 1.68 2009-10-11 23:30:28 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -22,6 +22,7 @@ #include #include #include +#include #include "tmux.h" @@ -123,6 +124,7 @@ session_create(const char *name, const char *cmd, const char *cwd, s = xmalloc(sizeof *s); s->references = 0; s->flags = 0; + s->activity = time(NULL); if (gettimeofday(&s->tv, NULL) != 0) fatal("gettimeofday failed"); diff --git a/tmux.1 b/tmux.1 index 10c18f28..328ec5d9 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.181 2009-10-09 13:07:04 tcunha Exp $ +.\" $Id: tmux.1,v 1.182 2009-10-11 23:30:28 tcunha Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 9 2009 $ +.Dd $Mdocdate: October 10 2009 $ .Dt TMUX 1 .Os .Sh NAME @@ -1253,20 +1253,33 @@ Set the maximum number of lines held in window history. This setting applies only to new windows - existing window histories are not resized and retain the limit at the point they were created. .It Ic lock-after-time Ar number -Lock the server (like the -.Ic lock-server +Lock the session (like the +.Ic lock-session command) after .Ar number -seconds of inactivity. -The default is off (set to 0). -This has no effect as a session option; it must be set as a global option using -.Fl g . +seconds of inactivity, or the entire server (all sessions) if the +.Ic lock-server +option is set. +The default is not to lock (set to 0). .It Ic lock-command Ar command Command to run when locking each client. The default is to run .Xr lock 1 with .Fl np . +.It Xo Ic lock-server +.Op Ic on | off +.Xc +If this option is +.Ic on +(the default), +instead of each session locking individually as each has been +idle for +.Ic lock-after-time +, the entire server will lock after +.Em all +sessions would have locked. +This has no effect as a session option; it must be set as a global option. .It Ic message-attr Ar attributes Set status line message attributes, where .Ar attributes diff --git a/tmux.c b/tmux.c index d2249599..7b65b6b3 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.176 2009-10-09 13:07:04 tcunha Exp $ */ +/* $Id: tmux.c,v 1.177 2009-10-11 23:30:28 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -51,8 +51,6 @@ struct options global_s_options; /* session options */ struct options global_w_options; /* window options */ struct environ global_environ; -time_t server_activity; - int debug_level; int be_quiet; time_t start_time; @@ -388,6 +386,7 @@ main(int argc, char **argv) options_set_number(so, "history-limit", 2000); options_set_number(so, "lock-after-time", 0); options_set_string(so, "lock-command", "lock -np"); + options_set_number(so, "lock-server", 1); options_set_number(so, "message-attr", 0); options_set_number(so, "message-bg", 3); options_set_number(so, "message-fg", 0); diff --git a/tmux.h b/tmux.h index 7403d452..63d05fc5 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.460 2009-10-09 13:11:42 tcunha Exp $ */ +/* $Id: tmux.h,v 1.461 2009-10-11 23:30:28 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -798,6 +798,7 @@ struct session_alert { struct session { char *name; struct timeval tv; + time_t activity; u_int sx; u_int sy; @@ -1115,7 +1116,6 @@ extern struct options global_s_options; extern struct options global_w_options; extern struct environ global_environ; extern char *cfg_file; -extern time_t server_activity; extern int debug_level; extern int be_quiet; extern time_t start_time;