From 72bc03ac4c0fa3757d16363ab9cacb0a152275f9 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Sat, 14 Nov 2009 17:48:39 +0000 Subject: [PATCH] Sync OpenBSD patchset 535: Destroy panes immediately rather than checking them all every loop. --- cmd-respawn-window.c | 3 ++- server-fn.c | 23 +++++++++++++++- server-window.c | 64 +------------------------------------------- server.c | 8 +++--- tmux.h | 3 ++- window.c | 6 ++--- 6 files changed, 32 insertions(+), 75 deletions(-) diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c index abf030f6..9028fdd4 100644 --- a/cmd-respawn-window.c +++ b/cmd-respawn-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-respawn-window.c,v 1.22 2009-09-16 12:36:27 nicm Exp $ */ +/* $Id: cmd-respawn-window.c,v 1.23 2009-11-14 17:48:39 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -80,6 +80,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx) ctx->error(ctx, "respawn window failed: %s", cause); xfree(cause); environ_free(&env); + server_destroy_pane(wp); return (-1); } layout_init(w); diff --git a/server-fn.c b/server-fn.c index 4684ac8c..607c757f 100644 --- a/server-fn.c +++ b/server-fn.c @@ -1,4 +1,4 @@ -/* $Id: server-fn.c,v 1.96 2009-11-08 23:11:23 tcunha Exp $ */ +/* $Id: server-fn.c,v 1.97 2009-11-14 17:48:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -316,6 +316,27 @@ server_unlink_window(struct session *s, struct winlink *wl) server_redraw_session_group(s); } +void +server_destroy_pane(struct window_pane *wp) +{ + struct window *w = wp->window; + + close(wp->fd); + bufferevent_free(wp->event); + wp->fd = -1; + + if (options_get_number(&w->options, "remain-on-exit")) + return; + + layout_close_pane(wp); + window_remove_pane(w, wp); + + if (TAILQ_EMPTY(&w->panes)) + server_kill_window(w); + else + server_redraw_window(w); +} + void server_destroy_session_group(struct session *s) { diff --git a/server-window.c b/server-window.c index 3ebf2034..be863922 100644 --- a/server-window.c +++ b/server-window.c @@ -1,4 +1,4 @@ -/* $Id: server-window.c,v 1.11 2009-11-08 23:35:53 tcunha Exp $ */ +/* $Id: server-window.c,v 1.12 2009-11-14 17:48:39 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -28,7 +28,6 @@ int server_window_check_bell(struct session *, struct window *); int server_window_check_activity(struct session *, struct window *); int server_window_check_content( struct session *, struct window *, struct window_pane *); -void server_window_check_alive(struct window *); /* Check if this window should suspend reading. */ int @@ -90,8 +89,6 @@ server_window_loop(void) server_window_check_content(s, w, wp); } w->flags &= ~(WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_CONTENT); - - server_window_check_alive(w); } } @@ -228,62 +225,3 @@ server_window_check_content( return (1); } - -/* Check if window still exists. */ -void -server_window_check_alive(struct window *w) -{ - struct window_pane *wp, *wq; - struct options *oo = &w->options; - struct session *s; - struct winlink *wl; - u_int i; - int destroyed; - - destroyed = 1; - - wp = TAILQ_FIRST(&w->panes); - while (wp != NULL) { - wq = TAILQ_NEXT(wp, entry); - /* - * If the pane has died and the remain-on-exit flag is not set, - * remove the pane; otherwise, if the flag is set, don't allow - * the window to be destroyed (or it'll close when the last - * pane dies). - */ - if (wp->fd == -1 && !options_get_number(oo, "remain-on-exit")) { - layout_close_pane(wp); - window_remove_pane(w, wp); - server_redraw_window(w); - } else - destroyed = 0; - wp = wq; - } - - if (!destroyed) - return; - - for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { - s = ARRAY_ITEM(&sessions, i); - if (s == NULL) - continue; - if (!session_has(s, w)) - continue; - - restart: - /* Detach window and either redraw or kill clients. */ - RB_FOREACH(wl, winlinks, &s->windows) { - if (wl->window != w) - continue; - if (session_detach(s, wl)) { - server_destroy_session_group(s); - break; - } - server_redraw_session(s); - server_status_session_group(s); - goto restart; - } - } - - recalculate_sizes(); -} diff --git a/server.c b/server.c index 6f272b24..79526d8a 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.228 2009-11-13 16:52:46 tcunha Exp $ */ +/* $Id: server.c,v 1.229 2009-11-14 17:48:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -353,7 +353,6 @@ server_accept_callback(int fd, short events, unused void *data) return; } server_client_create(newfd); - } /* Set up server signal handling. */ @@ -467,9 +466,8 @@ server_child_exited(pid_t pid, int status) continue; TAILQ_FOREACH(wp, &w->panes, entry) { if (wp->pid == pid) { - close(wp->fd); - bufferevent_free(wp->event); - wp->fd = -1; + server_destroy_pane(wp); + break; } } } diff --git a/tmux.h b/tmux.h index 8b2bc2ce..496a2a43 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.514 2009-11-13 16:58:24 tcunha Exp $ */ +/* $Id: tmux.h,v 1.515 2009-11-14 17:48:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1589,6 +1589,7 @@ void server_kill_window(struct window *); int server_link_window(struct session *, struct winlink *, struct session *, int, int, int, char **); 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_set_identify(struct client *); diff --git a/window.c b/window.c index 1bdbd4b7..6980a84a 100644 --- a/window.c +++ b/window.c @@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.121 2009-11-08 23:22:24 tcunha Exp $ */ +/* $Id: window.c,v 1.122 2009-11-14 17:48:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -592,9 +592,7 @@ window_pane_error_callback( { struct window_pane *wp = data; - close(wp->fd); - bufferevent_free(wp->event); - wp->fd = -1; + server_destroy_pane(wp); } void