Update of /cvsroot/tmux/tmux
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv28437
Modified Files:
cmd-choose-window.c cmd-find-window.c cmd-load-buffer.c
session.c tmux.h
Log Message:
Sync OpenBSD patchset 801:
Unify the way sessions are used by callbacks - store the address and use
the reference count, then check it is still on the global sessions list
in the callback.
Index: cmd-load-buffer.c
===================================================================
RCS file: /cvsroot/tmux/tmux/cmd-load-buffer.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cmd-load-buffer.c 9 Aug 2010 21:44:25 -0000 1.17
+++ cmd-load-buffer.c 22 Dec 2010 15:28:50 -0000 1.18
@@ -81,6 +81,7 @@
cdata = xmalloc(sizeof *cdata);
cdata->session = s;
+ cdata->session->references++;
cdata->buffer = data->buffer;
c->stdin_data = cdata;
c->stdin_callback = cmd_load_buffer_callback;
@@ -144,7 +145,6 @@
char *pdata;
size_t psize;
u_int limit;
- int idx;
/*
* Event callback has already checked client is not dead and reduced
@@ -153,7 +153,7 @@
c->flags |= CLIENT_EXIT;
/* Does the target session still exist? */
- if (session_index(s, &idx) != 0)
+ if (!session_alive(s))
goto out;
psize = EVBUFFER_LENGTH(c->stdin_event->input);
@@ -180,5 +180,6 @@
}
out:
+ cdata->session->references--;
xfree(cdata);
}
Index: cmd-choose-window.c
===================================================================
RCS file: /cvsroot/tmux/tmux/cmd-choose-window.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- cmd-choose-window.c 6 Dec 2010 22:52:20 -0000 1.23
+++ cmd-choose-window.c 22 Dec 2010 15:28:50 -0000 1.24
@@ -129,20 +129,19 @@
cmd_choose_window_callback(void *data, int idx)
{
struct cmd_choose_window_data *cdata = data;
+ struct session *s = cdata->session;
struct cmd_list *cmdlist;
struct cmd_ctx ctx;
char *target, *template, *cause;
if (idx == -1)
return;
- if (cdata->client->flags & CLIENT_DEAD)
- return;
- if (cdata->session->flags & SESSION_DEAD)
+ if (!session_alive(s))
return;
- if (cdata->client->session != cdata->session)
+ if (cdata->client->flags & CLIENT_DEAD)
return;
- xasprintf(&target, "%s:%d", cdata->session->name, idx);
+ xasprintf(&target, "%s:%d", s->name, idx);
template = cmd_template_replace(cdata->template, target, 1);
xfree(target);
Index: session.c
===================================================================
RCS file: /cvsroot/tmux/tmux/session.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- session.c 10 Sep 2010 13:36:17 -0000 1.78
+++ session.c 22 Dec 2010 15:28:50 -0000 1.79
@@ -34,6 +34,18 @@
struct winlink *session_next_alert(struct winlink *);
struct winlink *session_previous_alert(struct winlink *);
+/*
+ * Find if session is still alive. This is true if it is still on the global
+ * sessions list.
+ */
+int
+session_alive(struct session *s)
+{
+ u_int idx;
+
+ return (session_index(s, &idx) == 0);
+}
+
/* Find session by name. */
struct session *
session_find(const char *name)
Index: cmd-find-window.c
===================================================================
RCS file: /cvsroot/tmux/tmux/cmd-find-window.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cmd-find-window.c 14 Nov 2009 17:56:39 -0000 1.14
+++ cmd-find-window.c 22 Dec 2010 15:28:50 -0000 1.15
@@ -30,6 +30,7 @@
int cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
void cmd_find_window_callback(void *, int);
+void cmd_find_window_free(void *);
const struct cmd_entry cmd_find_window_entry = {
"find-window", "findw",
@@ -43,7 +44,7 @@
};
struct cmd_find_window_data {
- u_int session;
+ struct session *session;
};
int
@@ -134,11 +135,11 @@
}
cdata = xmalloc(sizeof *cdata);
- if (session_index(s, &cdata->session) != 0)
- fatalx("session not found");
+ cdata->session = s;
+ cdata->session->references++;
- window_choose_ready(
- wl->window->active, 0, cmd_find_window_callback, xfree, cdata);
+ window_choose_ready(wl->window->active,
+ 0, cmd_find_window_callback, cmd_find_window_free, cdata);
out:
ARRAY_FREE(&list_idx);
@@ -151,12 +152,24 @@
cmd_find_window_callback(void *data, int idx)
{
struct cmd_find_window_data *cdata = data;
- struct session *s;
+ struct session *s = cdata->session;
- if (idx != -1 && cdata->session <= ARRAY_LENGTH(&sessions) - 1) {
- s = ARRAY_ITEM(&sessions, cdata->session);
- if (s != NULL && session_select(s, idx) == 0)
- server_redraw_session(s);
+ if (idx == -1)
+ return;
+ if (!session_alive(s))
+ return;
+
+ if (session_select(s, idx) == 0) {
+ server_redraw_session(s);
recalculate_sizes();
}
}
+
+void
+cmd_find_window_free(void *data)
+{
+ struct cmd_find_window_data *cdata = data;
+
+ cdata->session->references--;
+ xfree(cdata);
+}
Index: tmux.h
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.h,v
retrieving revision 1.587
retrieving revision 1.588
diff -u -d -r1.587 -r1.588
--- tmux.h 11 Dec 2010 18:42:20 -0000 1.587
+++ tmux.h 22 Dec 2010 15:28:51 -0000 1.588
@@ -1966,6 +1966,7 @@
extern struct sessions sessions;
extern struct sessions dead_sessions;
extern struct session_groups session_groups;
+int session_alive(struct session *);
struct session *session_find(const char *);
struct session *session_create(const char *, const char *, const char *,
struct environ *, struct termios *, int, u_int, u_int,
------------------------------------------------------------------------------
Forrester recently released a report on the Return on Investment (ROI) of
Google Apps. They found a 300% ROI, 38%-56% cost savings, and break-even
within 7 months. Over 3 million businesses have gone Google with Google Apps:
an online email calendar, and document program that's accessible from your
browser. Read the Forrester report: http://p.sf.net/sfu/googleapps-sfnew
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs