From bcac80d843e4378cb2ef2fc4c1ba13048c321441 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Oct 2025 07:28:38 +0000 Subject: [PATCH] Fix the logic of the no-detached case for detach-on-destroy option - a previous change made it so that even in the no-detached case, tmux would always re-attach to a session, even if there weren't any detached ones. From Martin Louazel in GitHub issue 4649. --- usr.bin/tmux/server-fn.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index 049932b384e..ae94a90abc6 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.139 2025/09/09 08:49:22 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.140 2025/10/20 07:28:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -401,7 +401,7 @@ server_find_session(struct session *s, struct session *s_loop, *s_out = NULL; RB_FOREACH(s_loop, sessions, &sessions) { - if (s_loop != s && (s_out == NULL || f(s_loop, s_out))) + if (s_loop != s && f(s_loop, s_out)) s_out = s_loop; } return (s_out); @@ -410,6 +410,8 @@ server_find_session(struct session *s, static int server_newer_session(struct session *s_loop, struct session *s_out) { + if (s_out == NULL) + return (1); return (timercmp(&s_loop->activity_time, &s_out->activity_time, >)); }