diff options
author | Tiago Cunha <tcunha@gmx.com> | 2009-10-11 23:30:28 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2009-10-11 23:30:28 +0000 |
commit | 91e4dc83fcfa8c2d4a318d5f23dcebbaeeea2096 (patch) | |
tree | b5fe84fa223ed89dd3c17d43a56c7c0bb4ef93eb /server.c | |
parent | a4ea6a9d19ef9dc4290a9cd15e352a414198d268 (diff) | |
download | rtmux-91e4dc83fcfa8c2d4a318d5f23dcebbaeeea2096.tar.gz rtmux-91e4dc83fcfa8c2d4a318d5f23dcebbaeeea2096.tar.bz2 rtmux-91e4dc83fcfa8c2d4a318d5f23dcebbaeeea2096.zip |
Sync OpenBSD patchset 370:
Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.
This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.
Diff/idea largely from Thomas Adam, tweaked by me.
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 68 |
1 files changed, 54 insertions, 14 deletions
@@ -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 <nicm@users.sourceforge.net> @@ -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); |