diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2010-12-21 22:37:59 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2010-12-21 22:37:59 +0000 |
commit | acf13ce9784111ca1e42ffc8206e752668476859 (patch) | |
tree | 49ccd47b2e589a27dab8657d516133205f07f393 /server-fn.c | |
parent | 1b8488ee75458c4561089bf056c0e911de958428 (diff) |
Store sessions in an RB tree by name rather than a list, this is tidier
and allows them to easily be shown sorted in various lists
(list-sessions/choose-sessions).
Keep a session index which is used in a couple of places internally but
make it an ever-increasing number rather than filling in gaps with new
sessions.
Diffstat (limited to 'server-fn.c')
-rw-r--r-- | server-fn.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/server-fn.c b/server-fn.c index 134cfb6e..ada92b9a 100644 --- a/server-fn.c +++ b/server-fn.c @@ -30,13 +30,10 @@ void server_callback_identify(int, short, void *); void server_fill_environ(struct session *s, struct environ *env) { - char tmuxvar[MAXPATHLEN], *term; - u_int idx; + char tmuxvar[MAXPATHLEN], *term; - if (session_index(s, &idx) != 0) - fatalx("session not found"); xsnprintf(tmuxvar, sizeof tmuxvar, - "%s,%ld,%u", socket_path, (long) getpid(), idx); + "%s,%ld,%u", socket_path, (long) getpid(), s->idx); environ_set(env, "TMUX", tmuxvar); term = options_get_string(&s->options, "default-terminal"); @@ -175,7 +172,6 @@ void server_status_window(struct window *w) { struct session *s; - u_int i; /* * This is slightly different. We want to redraw the status line of any @@ -183,9 +179,8 @@ server_status_window(struct window *w) * current window. */ - for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { - s = ARRAY_ITEM(&sessions, i); - if (s != NULL && session_has(s, w) != NULL) + RB_FOREACH(s, sessions, &sessions) { + if (session_has(s, w) != NULL) server_status_session(s); } } @@ -246,11 +241,9 @@ server_kill_window(struct window *w) { struct session *s; struct winlink *wl; - u_int i; - for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { - s = ARRAY_ITEM(&sessions, i); - if (s == NULL || session_has(s, w) == NULL) + RB_FOREACH(s, sessions, &sessions) { + if (session_has(s, w) == NULL) continue; while ((wl = winlink_find_by_window(&s->windows, w)) != NULL) { if (session_detach(s, wl)) { @@ -365,12 +358,10 @@ struct session * server_next_session(struct session *s) { struct session *s_loop, *s_out; - u_int i; s_out = NULL; - for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { - s_loop = ARRAY_ITEM(&sessions, i); - if (s_loop == NULL || s_loop == s) + RB_FOREACH(s_loop, sessions, &sessions) { + if (s_loop == s) continue; if (s_out == NULL || timercmp(&s_loop->activity_time, &s_out->activity_time, <)) @@ -411,15 +402,13 @@ void server_check_unattached (void) { struct session *s; - u_int i; /* * If any sessions are no longer attached and have destroy-unattached * set, collect them. */ - for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { - s = ARRAY_ITEM(&sessions, i); - if (s == NULL || !(s->flags & SESSION_UNATTACHED)) + RB_FOREACH(s, sessions, &sessions) { + if (!(s->flags & SESSION_UNATTACHED)) continue; if (options_get_number (&s->options, "destroy-unattached")) session_destroy(s); |