diff options
Diffstat (limited to 'server-fn.c')
-rw-r--r-- | server-fn.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/server-fn.c b/server-fn.c index e3cc181f..656de08e 100644 --- a/server-fn.c +++ b/server-fn.c @@ -312,6 +312,7 @@ server_destroy_pane(struct window_pane *wp, int notify) struct grid_cell gc; time_t t; char tim[26]; + int remain_on_exit; if (wp->fd != -1) { #ifdef HAVE_UTEMPTER @@ -323,10 +324,17 @@ server_destroy_pane(struct window_pane *wp, int notify) wp->fd = -1; } - if (options_get_number(wp->options, "remain-on-exit")) { - if (~wp->flags & PANE_STATUSREADY) - return; - + remain_on_exit = options_get_number(wp->options, "remain-on-exit"); + if (remain_on_exit != 0 && (~wp->flags & PANE_STATUSREADY)) + return; + switch (remain_on_exit) { + case 0: + break; + case 2: + if (WIFEXITED(wp->status) && WEXITSTATUS(wp->status) == 0) + break; + /* FALLTHROUGH */ + case 1: if (wp->flags & PANE_STATUSDRAWN) return; wp->flags |= PANE_STATUSDRAWN; @@ -394,9 +402,8 @@ server_destroy_session_group(struct session *s) static struct session * server_next_session(struct session *s) { - struct session *s_loop, *s_out; + struct session *s_loop, *s_out = NULL; - s_out = NULL; RB_FOREACH(s_loop, sessions, &sessions) { if (s_loop == s) continue; @@ -407,17 +414,35 @@ server_next_session(struct session *s) return (s_out); } +static struct session * +server_next_detached_session(struct session *s) +{ + struct session *s_loop, *s_out = NULL; + + RB_FOREACH(s_loop, sessions, &sessions) { + if (s_loop == s || s_loop->attached) + continue; + if (s_out == NULL || + timercmp(&s_loop->activity_time, &s_out->activity_time, <)) + s_out = s_loop; + } + return (s_out); +} + void server_destroy_session(struct session *s) { struct client *c; struct session *s_new; + int detach_on_destroy; - if (!options_get_number(s->options, "detach-on-destroy")) + detach_on_destroy = options_get_number(s->options, "detach-on-destroy"); + if (detach_on_destroy == 0) s_new = server_next_session(s); + else if (detach_on_destroy == 2) + s_new = server_next_detached_session(s); else s_new = NULL; - TAILQ_FOREACH(c, &clients, entry) { if (c->session != s) continue; |