summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/options-table.c10
-rw-r--r--usr.bin/tmux/proc.c4
-rw-r--r--usr.bin/tmux/server-fn.c24
-rw-r--r--usr.bin/tmux/tmux.120
4 files changed, 44 insertions, 14 deletions
diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c
index 7f51a0a69db..3dbc1b8479b 100644
--- a/usr.bin/tmux/options-table.c
+++ b/usr.bin/tmux/options-table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options-table.c,v 1.168 2023/09/01 13:48:54 nicm Exp $ */
+/* $OpenBSD: options-table.c,v 1.169 2024/02/13 08:10:23 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -85,6 +85,9 @@ static const char *options_table_window_size_list[] = {
static const char *options_table_remain_on_exit_list[] = {
"off", "on", "failed", NULL
};
+static const char *options_table_destroy_unattached_list[] = {
+ "off", "on", "keep-last", "keep-group", NULL
+};
static const char *options_table_detach_on_destroy_list[] = {
"off", "on", "no-detached", "previous", "next", NULL
};
@@ -484,11 +487,12 @@ const struct options_table_entry options_table[] = {
},
{ .name = "destroy-unattached",
- .type = OPTIONS_TABLE_FLAG,
+ .type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_SESSION,
+ .choices = options_table_destroy_unattached_list,
.default_num = 0,
.text = "Whether to destroy sessions when they have no attached "
- "clients."
+ "clients, or keep the last session whether in the group."
},
{ .name = "detach-on-destroy",
diff --git a/usr.bin/tmux/proc.c b/usr.bin/tmux/proc.c
index f0c7e547c96..d001ba9c3d1 100644
--- a/usr.bin/tmux/proc.c
+++ b/usr.bin/tmux/proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.c,v 1.23 2024/01/16 13:09:11 claudio Exp $ */
+/* $OpenBSD: proc.c,v 1.24 2024/02/13 08:10:23 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -92,7 +92,7 @@ proc_event_cb(__unused int fd, short events, void *arg)
log_debug("peer %p message %d", peer, imsg.hdr.type);
if (peer_check_version(peer, &imsg) != 0) {
- int fd = imsg_get_fd(&imsg);
+ fd = imsg_get_fd(&imsg);
if (fd != -1)
close(fd);
imsg_free(&imsg);
diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c
index 75acd18791b..7ddb7e7d26c 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.134 2023/09/01 13:48:54 nicm Exp $ */
+/* $OpenBSD: server-fn.c,v 1.135 2024/02/13 08:10:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -454,7 +454,8 @@ server_destroy_session(struct session *s)
void
server_check_unattached(void)
{
- struct session *s;
+ struct session *s;
+ struct session_group *sg;
/*
* If any sessions are no longer attached and have destroy-unattached
@@ -463,8 +464,23 @@ server_check_unattached(void)
RB_FOREACH(s, sessions, &sessions) {
if (s->attached != 0)
continue;
- if (options_get_number (s->options, "destroy-unattached"))
- session_destroy(s, 1, __func__);
+ switch (options_get_number(s->options, "destroy-unattached")) {
+ case 0: /* off */
+ continue;
+ case 1: /* on */
+ break;
+ case 2: /* keep-last */
+ sg = session_group_contains(s);
+ if (sg == NULL || session_group_count(sg) <= 1)
+ continue;
+ break;
+ case 3: /* keep-group */
+ sg = session_group_contains(s);
+ if (sg != NULL && session_group_count(sg) == 1)
+ continue;
+ break;
+ }
+ session_destroy(s, 1, __func__);
}
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index bb690cbd5d7..43fbad273fa 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.935 2023/12/27 20:23:59 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.936 2024/02/13 08:10:23 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -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: December 27 2023 $
+.Dd $Mdocdate: February 13 2024 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -4023,10 +4023,20 @@ The value is the width and height separated by an
character.
The default is 80x24.
.It Xo Ic destroy-unattached
-.Op Ic on | off
+.Op Ic off | on | keep-last | keep-group
.Xc
-If enabled and the session is no longer attached to any clients, it is
-destroyed.
+If
+.Ic on ,
+destroy the session after the last client has detached.
+If
+.Ic off
+(the default), leave the session orphaned.
+If
+.Ic keep-last ,
+destroy the session only if it is in a group and has other sessions in that group.
+If
+.Ic keep-group ,
+destroy the session unless it is in a group and is the only session in that group.
.It Xo Ic detach-on-destroy
.Op Ic off | on | no-detached | previous | next
.Xc