diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-11-15 14:09:05 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-11-15 14:09:05 +0000 |
commit | 86ae353066e692bce701fc2d2b6ae6251e51969b (patch) | |
tree | b2da3b4597a3150ba296d6149706e239e014eca4 /usr.bin/tmux/server-fn.c | |
parent | ae58853c01a2c1ba5f25057625b07899fb2645e7 (diff) |
Add no-detach-on-destroy client option (useful for control mode
clients). From laur dot aliste at gmail dot com, GitHub issue 4242.
Diffstat (limited to 'usr.bin/tmux/server-fn.c')
-rw-r--r-- | usr.bin/tmux/server-fn.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index e3cd2186cf7..0587897ab9a 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.137 2024/04/04 22:44:40 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.138 2024/11/15 14:09:04 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -425,7 +425,7 @@ void server_destroy_session(struct session *s) { struct client *c; - struct session *s_new = NULL; + struct session *s_new = NULL, *cs_new, *use_s; int detach_on_destroy; detach_on_destroy = options_get_number(s->options, "detach-on-destroy"); @@ -437,15 +437,26 @@ server_destroy_session(struct session *s) s_new = session_previous_session(s); else if (detach_on_destroy == 4) s_new = session_next_session(s); - if (s_new == s) - s_new = NULL; + + /* + * If no suitable new session was found above, then look for any + * session as an alternative in case a client needs it. + */ + if (s_new == NULL && + (detach_on_destroy == 1 || detach_on_destroy == 2)) + cs_new = server_find_session(s, server_newer_session); + TAILQ_FOREACH(c, &clients, entry) { if (c->session != s) continue; + use_s = s_new; + if (use_s == NULL && (c->flags & CLIENT_NO_DETACH_ON_DESTROY)) + use_s = cs_new; + c->session = NULL; c->last_session = NULL; - server_client_set_session(c, s_new); - if (s_new == NULL) + server_client_set_session(c, use_s); + if (use_s == NULL) c->flags |= CLIENT_EXIT; } recalculate_sizes(); |