From b7921d953c0f2364c3aa6ea9ebf8de1be3099904 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 26 Sep 2010 20:43:31 +0000 Subject: Two new options: - server option "exit-unattached" makes the server exit when no clients are attached, even if sessions are present; - session option "destroy-unattached" destroys a session once no clients are attached to it. These are useful for preventing tmux remaining in the background where it is undesirable and when using tmux as a login shell to keep a limit on new sessions. --- usr.bin/tmux/cmd-set-option.c | 4 +++- usr.bin/tmux/cmd-switch-client.c | 3 ++- usr.bin/tmux/server-client.c | 3 ++- usr.bin/tmux/server-fn.c | 21 ++++++++++++++++++++- usr.bin/tmux/server.c | 12 +++++++----- usr.bin/tmux/tmux.1 | 10 ++++++++-- usr.bin/tmux/tmux.c | 4 +++- usr.bin/tmux/tmux.h | 3 ++- 8 files changed, 47 insertions(+), 13 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index c7baf3fcf05..ebc0f709564 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.38 2010/09/01 21:06:51 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.39 2010/09/26 20:43:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -75,6 +75,7 @@ const char *set_option_bell_action_list[] = { const struct set_option_entry set_option_table[] = { { "escape-time", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, + { "exit-unattached", SET_OPTION_FLAG, 0, 0, NULL }, { "quiet", SET_OPTION_FLAG, 0, 0, NULL }, { NULL, 0, 0, 0, NULL } }; @@ -87,6 +88,7 @@ const struct set_option_entry set_session_option_table[] = { { "default-path", SET_OPTION_STRING, 0, 0, NULL }, { "default-shell", SET_OPTION_STRING, 0, 0, NULL }, { "default-terminal", SET_OPTION_STRING, 0, 0, NULL }, + { "destroy-unattached", SET_OPTION_FLAG, 0, 0, NULL }, { "detach-on-destroy", SET_OPTION_FLAG, 0, 0, NULL }, { "display-panes-colour", SET_OPTION_COLOUR, 0, 0, NULL }, { "display-panes-active-colour", SET_OPTION_COLOUR, 0, 0, NULL }, diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index d44c4ef276f..4f9a6d12cb7 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.6 2010/09/08 22:02:28 nicm Exp $ */ +/* $OpenBSD: cmd-switch-client.c,v 1.7 2010/09/26 20:43:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -152,6 +152,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx) c->session = s; recalculate_sizes(); + server_check_unattached(); server_redraw_client(c); return (0); diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index bd575ecbc22..21c22b4c8a7 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.40 2010/08/31 22:46:59 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.41 2010/09/26 20:43:30 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -185,6 +185,7 @@ server_client_lost(struct client *c) c->flags |= CLIENT_DEAD; recalculate_sizes(); + server_check_unattached(); server_update_socket(); } diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index 3e47f7b6edc..a69ff8d9d67 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.41 2010/08/11 07:36:23 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.42 2010/09/26 20:43:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -404,6 +404,25 @@ server_destroy_session(struct session *s) recalculate_sizes(); } +void +server_check_unattached (void) +{ + struct session *s; + u_int i; + + /* + * If any sessions are no longer attached and have destroy-unattached + * set, collect them. + */ + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + s = ARRAY_ITEM(&sessions, i); + if (s == NULL || !(s->flags & SESSION_UNATTACHED)) + continue; + if (options_get_number (&s->options, "destroy-unattached")) + session_destroy(s); + } +} + void server_set_identify(struct client *c) { diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index 973f0c40a65..f13b3b98bd2 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.93 2010/09/26 18:51:48 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.94 2010/09/26 20:43:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -222,15 +222,17 @@ server_loop(void) } } -/* Check if the server should be shutting down (no more clients or windows). */ +/* Check if the server should be shutting down (no more clients or sessions). */ int server_should_shutdown(void) { u_int i; - for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { - if (ARRAY_ITEM(&sessions, i) != NULL) - return (0); + if (!options_get_number(&global_options, "exit-unattached")) { + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + if (ARRAY_ITEM(&sessions, i) != NULL) + return (0); + } } for (i = 0; i < ARRAY_LENGTH(&clients); i++) { if (ARRAY_ITEM(&clients, i) != NULL) diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 84b940e615f..e3c8f99c32e 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.184 2010/09/25 20:35:52 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.185 2010/09/26 20:43:30 nicm 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: September 25 2010 $ +.Dd $Mdocdate: September 26 2010 $ .Dt TMUX 1 .Os .Sh NAME @@ -1587,6 +1587,9 @@ Set the time in milliseconds for which waits after an escape is input to determine if it is part of a function or meta key sequences. The default is 500 milliseconds. +.It Ic exit-unattached +If enabled, the server will exit when there are no attached clients, rather +than when there are no attached sessions. .It Ic quiet Enable or disable the display of various informational messages (see also the .Fl q @@ -1659,6 +1662,9 @@ to work correctly, this be set to .Ql screen or a derivative of it. +.It Ic destroy-unattached +If enabled and the session is no longer attached to any clients, it is +destroyed. .It Ic detach-on-destroy If on (the default), the client is detached when the session it is attached to is destroyed. diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 3493b2bd35c..f28800f91e2 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.87 2010/08/19 18:29:01 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.88 2010/09/26 20:43:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -331,6 +331,7 @@ main(int argc, char **argv) oo = &global_options; options_set_number(oo, "quiet", quiet); options_set_number(oo, "escape-time", 500); + options_set_number(oo, "exit-unattached", 0); options_init(&global_s_options, NULL); so = &global_s_options; @@ -341,6 +342,7 @@ main(int argc, char **argv) options_set_string(so, "default-path", "%s", ""); options_set_string(so, "default-shell", "%s", getshell()); options_set_string(so, "default-terminal", "screen"); + options_set_number(so, "destroy-unattached", 0); options_set_number(so, "detach-on-destroy", 1); options_set_number(so, "display-panes-active-colour", 1); options_set_number(so, "display-panes-colour", 4); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index bd29e5f549e..e419cb59e26 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.240 2010/09/11 16:19:22 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.241 2010/09/26 20:43:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1661,6 +1661,7 @@ void server_unlink_window(struct session *, struct winlink *); void server_destroy_pane(struct window_pane *); void server_destroy_session_group(struct session *); void server_destroy_session(struct session *); +void server_check_unattached (void); void server_set_identify(struct client *); void server_clear_identify(struct client *); void server_update_event(struct client *); -- cgit v1.2.3