summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-10-10 09:46:12 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-10-10 09:46:12 +0000
commit79fc4e03d25eb15999e2ba0c4e7f9bab8470133d (patch)
treea66044b89b9b395f683c3ce91030f91e99e20eaa /usr.bin/tmux
parentd5cdc5f5f5ea995faaebb8826ae6e7d2eda59974 (diff)
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 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-set-option.c3
-rw-r--r--usr.bin/tmux/server-msg.c8
-rw-r--r--usr.bin/tmux/server.c68
-rw-r--r--usr.bin/tmux/session.c4
-rw-r--r--usr.bin/tmux/tmux.129
-rw-r--r--usr.bin/tmux/tmux.c5
-rw-r--r--usr.bin/tmux/tmux.h4
7 files changed, 89 insertions, 32 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index 1632c39303e..59cb726b3c4 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.20 2009/09/23 06:18:47 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.21 2009/10/10 09:46:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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/usr.bin/tmux/server-msg.c b/usr.bin/tmux/server-msg.c
index 0a0937ae45d..761cbf66a32 100644
--- a/usr.bin/tmux/server-msg.c
+++ b/usr.bin/tmux/server-msg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-msg.c,v 1.22 2009/09/24 07:02:56 nicm Exp $ */
+/* $OpenBSD: server-msg.c,v 1.23 2009/10/10 09:46:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -105,7 +105,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)
@@ -181,7 +182,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/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 50a1b7d2343..88e4f3d0dc1 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.45 2009/10/10 09:31:39 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.46 2009/10/10 09:46:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -86,6 +86,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);
@@ -249,8 +251,6 @@ server_start(char *path)
key_bindings_init();
utf8_build();
- server_activity = time(NULL);
-
start_time = time(NULL);
socket_path = path;
@@ -842,10 +842,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 */
@@ -1254,6 +1254,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)
@@ -1261,16 +1306,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/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index 0da2c013a55..75d27021c5d 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.9 2009/09/20 14:58:12 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.10 2009/10/10 09:46:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -23,6 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <time.h>
#include "tmux.h"
@@ -124,6 +125,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/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 8a5863774cf..9b31b6ffbe2 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.99 2009/10/09 07:27:00 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.100 2009/10/10 09:46:11 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -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/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index dcb62ec01d9..8172b00291d 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.47 2009/10/09 07:27:00 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.48 2009/10/10 09:46:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -46,8 +46,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;
@@ -379,6 +377,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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 63232244ec9..2fd7ad7e771 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.122 2009/10/09 07:33:12 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.123 2009/10/10 09:46:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -800,6 +800,7 @@ struct session_alert {
struct session {
char *name;
struct timeval tv;
+ time_t activity;
u_int sx;
u_int sy;
@@ -1117,7 +1118,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;