summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-12-20 00:03:56 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-12-20 00:03:56 +0000
commit9f7c689cb8ccc8428baf5d610708ebbb50f2b592 (patch)
treeb09d4e96930f9058c62b67b15e142ec8712a0be9 /usr.bin/tmux
parent38ab20a6f6c33e027490420674d8c89ebf6c07ca (diff)
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.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-choose-window.c11
-rw-r--r--usr.bin/tmux/cmd-find-window.c35
-rw-r--r--usr.bin/tmux/cmd-load-buffer.c7
-rw-r--r--usr.bin/tmux/session.c14
-rw-r--r--usr.bin/tmux/tmux.h3
5 files changed, 48 insertions, 22 deletions
diff --git a/usr.bin/tmux/cmd-choose-window.c b/usr.bin/tmux/cmd-choose-window.c
index 2429601d492..b8214d1a533 100644
--- a/usr.bin/tmux/cmd-choose-window.c
+++ b/usr.bin/tmux/cmd-choose-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-choose-window.c,v 1.15 2010/12/06 22:51:02 nicm Exp $ */
+/* $OpenBSD: cmd-choose-window.c,v 1.16 2010/12/20 00:03:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -129,20 +129,19 @@ void
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);
diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c
index d9cdb62796c..cbbf1f50ce1 100644
--- a/usr.bin/tmux/cmd-find-window.c
+++ b/usr.bin/tmux/cmd-find-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-find-window.c,v 1.6 2009/11/13 19:53:29 nicm Exp $ */
+/* $OpenBSD: cmd-find-window.c,v 1.7 2010/12/20 00:03:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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 @@ const struct cmd_entry cmd_find_window_entry = {
};
struct cmd_find_window_data {
- u_int session;
+ struct session *session;
};
int
@@ -134,11 +135,11 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
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 @@ void
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);
+}
diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c
index b43f57feb92..3629c6eda87 100644
--- a/usr.bin/tmux/cmd-load-buffer.c
+++ b/usr.bin/tmux/cmd-load-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-load-buffer.c,v 1.13 2010/07/24 20:11:59 nicm Exp $ */
+/* $OpenBSD: cmd-load-buffer.c,v 1.14 2010/12/20 00:03:55 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -81,6 +81,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
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 @@ cmd_load_buffer_callback(struct client *c, void *data)
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 @@ cmd_load_buffer_callback(struct client *c, void *data)
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 @@ cmd_load_buffer_callback(struct client *c, void *data)
}
out:
+ cdata->session->references--;
xfree(cdata);
}
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index c6178c04437..c23d1b79e8c 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.20 2010/09/08 22:02:28 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.21 2010/12/20 00:03:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -35,6 +35,18 @@ struct session_groups session_groups;
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)
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 6ccdea89d1b..25cf7bc5730 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.250 2010/12/11 18:39:25 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.251 2010/12/20 00:03:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1968,6 +1968,7 @@ void clear_signals(int);
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,