-/* $OpenBSD: cmd-attach-session.c,v 1.32 2015/02/05 10:29:43 nicm Exp $ */
+/* $OpenBSD: cmd-attach-session.c,v 1.33 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct window_pane *wp = NULL;
const char *update;
char *cause;
- u_int i;
int fd;
struct format_tree *ft;
char *cp;
* Can't use server_write_session in case attaching to
* the same session as currently attached to.
*/
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session != s)
- continue;
- if (c == cmdq->client)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != s || c == cmdq->client)
continue;
server_write_client(c, MSG_DETACH,
c->session->name,
-/* $OpenBSD: cmd-choose-client.c,v 1.22 2015/02/05 10:29:43 nicm Exp $ */
+/* $OpenBSD: cmd-choose-client.c,v 1.23 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
struct winlink *wl;
const char *template;
char *action;
- u_int i, idx, cur;
+ u_int idx, cur;
if ((c = cmd_current_client(cmdq)) == NULL) {
cmdq_error(cmdq, "no client available");
action = xstrdup("detach-client -t '%%'");
cur = idx = 0;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c1 = ARRAY_ITEM(&clients, i);
- if (c1 == NULL || c1->session == NULL || c1->tty.path == NULL)
+ TAILQ_FOREACH(c1, &clients, entry) {
+ if (c1->session == NULL || c1->tty.path == NULL)
continue;
if (c1 == cmdq->client)
cur = idx;
- idx++;
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
- cdata->idx = i;
+ cdata->idx = idx;
cdata->ft_template = xstrdup(template);
- format_add(cdata->ft, "line", "%u", i);
+ format_add(cdata->ft, "line", "%u", idx);
format_defaults(cdata->ft, c1, NULL, NULL, NULL);
cdata->command = cmd_template_replace(action, c1->tty.path, 1);
window_choose_add(wl->window->active, cdata);
+
+ idx++;
}
free(action);
cmd_choose_client_callback(struct window_choose_data *cdata)
{
struct client *c;
+ u_int idx;
if (cdata == NULL)
return;
if (cdata->start_client->flags & CLIENT_DEAD)
return;
- if (cdata->idx > ARRAY_LENGTH(&clients) - 1)
- return;
- c = ARRAY_ITEM(&clients, cdata->idx);
+ idx = 0;
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (idx == cdata->idx)
+ break;
+ idx++;
+ }
if (c == NULL || c->session == NULL)
return;
-/* $OpenBSD: cmd-detach-client.c,v 1.19 2015/01/30 15:57:30 nicm Exp $ */
+/* $OpenBSD: cmd-detach-client.c,v 1.20 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct client *c, *cloop;
struct session *s;
enum msgtype msgtype;
- u_int i;
if (self->entry == &cmd_suspend_client_entry) {
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
if (s == NULL)
return (CMD_RETURN_ERROR);
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- cloop = ARRAY_ITEM(&clients, i);
- if (cloop == NULL || cloop->session != s)
+ TAILQ_FOREACH(cloop, &clients, entry) {
+ if (cloop->session != s)
continue;
server_write_client(cloop, msgtype,
cloop->session->name,
return (CMD_RETURN_ERROR);
if (args_has(args, 'a')) {
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- cloop = ARRAY_ITEM(&clients, i);
- if (cloop == NULL || cloop->session == NULL)
- continue;
- if (cloop == c)
+ TAILQ_FOREACH(cloop, &clients, entry) {
+ if (cloop->session == NULL || cloop == c)
continue;
server_write_client(cloop, msgtype,
cloop->session->name,
-/* $OpenBSD: cmd-list-clients.c,v 1.20 2015/02/05 10:29:43 nicm Exp $ */
+/* $OpenBSD: cmd-list-clients.c,v 1.21 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct session *s;
struct format_tree *ft;
const char *template;
- u_int i;
+ u_int idx;
char *line;
if (args_has(args, 't')) {
if ((template = args_get(args, 'F')) == NULL)
template = LIST_CLIENTS_TEMPLATE;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
- continue;
-
- if (s != NULL && s != c->session)
+ idx = 0;
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session == NULL || (s != NULL && s != c->session))
continue;
ft = format_create();
- format_add(ft, "line", "%u", i);
+ format_add(ft, "line", "%u", idx);
format_defaults(ft, c, NULL, NULL, NULL);
line = format_expand(ft, template);
free(line);
format_free(ft);
+
+ idx++;
}
return (CMD_RETURN_NORMAL);
-/* $OpenBSD: cmd-set-option.c,v 1.73 2015/04/24 21:38:18 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.74 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct options *oo;
struct window *w;
const char *optstr, *valstr;
- u_int i;
/* Get the option name and value. */
optstr = args->argv[0];
/* Update sizes and redraw. May not need it but meh. */
recalculate_sizes();
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && c->session != NULL)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != NULL)
server_redraw_client(c);
}
-/* $OpenBSD: cmd.c,v 1.100 2015/04/21 22:42:27 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.101 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
NULL
};
+ARRAY_DECL(client_list, struct client *);
+
int cmd_session_better(struct session *, struct session *, int);
struct session *cmd_choose_session_list(struct sessionslist *);
struct session *cmd_choose_session(int);
-struct client *cmd_choose_client(struct clients *);
+struct client *cmd_choose_client(struct client_list *);
struct client *cmd_lookup_client(const char *);
struct session *cmd_lookup_session(struct cmd_q *, const char *, int *);
struct session *cmd_lookup_session_id(const char *);
{
struct session *s;
struct client *c;
- struct clients cc;
- u_int i;
+ struct client_list cc;
if (cmdq->client != NULL && cmdq->client->session != NULL)
return (cmdq->client);
s = cmd_current_session(cmdq, 0);
if (s != NULL && !(s->flags & SESSION_UNATTACHED)) {
ARRAY_INIT(&cc);
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- if ((c = ARRAY_ITEM(&clients, i)) == NULL)
- continue;
+ TAILQ_FOREACH(c, &clients, entry) {
if (s == c->session)
ARRAY_ADD(&cc, c);
}
return (c);
}
- return (cmd_choose_client(&clients));
+ ARRAY_INIT(&cc);
+ TAILQ_FOREACH(c, &clients, entry)
+ ARRAY_ADD(&cc, c);
+ c = cmd_choose_client(&cc);
+ ARRAY_FREE(&cc);
+ return (c);
}
/* Choose the most recently used client from a list. */
struct client *
-cmd_choose_client(struct clients *cc)
+cmd_choose_client(struct client_list *cc)
{
struct client *c, *cbest;
struct timeval *tv = NULL;
{
struct client *c;
const char *path;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL || c->tty.path == NULL)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session == NULL || c->tty.path == NULL)
continue;
path = c->tty.path;
-/* $OpenBSD: control-notify.c,v 1.10 2015/02/05 10:29:43 nicm Exp $ */
+/* $OpenBSD: control-notify.c,v 1.11 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@users.sourceforge.net>
struct session *s;
struct format_tree *ft;
struct winlink *wl;
- u_int i;
const char *template;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
+ TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
continue;
s = c->session;
{
struct client *c;
struct session *cs;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
+ TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
continue;
cs = c->session;
{
struct client *c;
struct session *cs;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
+ TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
continue;
cs = c->session;
{
struct client *c;
struct session *cs;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
+ TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
continue;
cs = c->session;
control_notify_session_renamed(struct session *s)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
+ TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
continue;
control_notify_session_created(unused struct session *s)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
+ TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
continue;
control_notify_session_close(unused struct session *s)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
+ TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
continue;
-/* $OpenBSD: notify.c,v 1.5 2012/09/25 07:41:22 nicm Exp $ */
+/* $OpenBSD: notify.c,v 1.6 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2012 George Nachman <tmux@georgester.com>
notify_input(struct window_pane *wp, struct evbuffer *input)
{
struct client *c;
- u_int i;
/*
* notify_input() is not queued and only does anything when
if (!notify_enabled)
return;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && (c->flags & CLIENT_CONTROL))
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->flags & CLIENT_CONTROL)
control_notify_input(c, wp, input);
}
}
-/* $OpenBSD: resize.c,v 1.16 2015/04/22 15:32:33 nicm Exp $ */
+/* $OpenBSD: resize.c,v 1.17 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct client *c;
struct window *w;
struct window_pane *wp;
- u_int i, ssx, ssy, has, limit;
+ u_int ssx, ssy, has, limit;
int flag, has_status, is_zoomed, forced;
RB_FOREACH(s, sessions, &sessions) {
s->attached = 0;
ssx = ssy = UINT_MAX;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->flags & CLIENT_SUSPENDED)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->flags & CLIENT_SUSPENDED)
continue;
if (c->session == s) {
if (c->tty.sx < ssx)
-/* $OpenBSD: server-client.c,v 1.134 2015/04/22 15:30:11 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.135 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
server_client_create(int fd)
{
struct client *c;
- u_int i;
setblocking(fd, 0);
evtimer_set(&c->repeat_timer, server_client_repeat_timer, c);
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- if (ARRAY_ITEM(&clients, i) == NULL) {
- ARRAY_SET(&clients, i, c);
- return;
- }
- }
- ARRAY_ADD(&clients, c);
+ TAILQ_INSERT_TAIL(&clients, c, entry);
log_debug("new client %d", fd);
}
struct message_entry *msg;
u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- if (ARRAY_ITEM(&clients, i) == c)
- ARRAY_SET(&clients, i, NULL);
- }
+ TAILQ_REMOVE(&clients, c, entry);
log_debug("lost client %d", c->ibuf.fd);
/*
if (event_initialized(&c->event))
event_del(&c->event);
- for (i = 0; i < ARRAY_LENGTH(&dead_clients); i++) {
- if (ARRAY_ITEM(&dead_clients, i) == NULL) {
- ARRAY_SET(&dead_clients, i, c);
- break;
- }
- }
- if (i == ARRAY_LENGTH(&dead_clients))
- ARRAY_ADD(&dead_clients, c);
+ TAILQ_INSERT_TAIL(&dead_clients, c, entry);
c->flags |= CLIENT_DEAD;
server_add_accept(0); /* may be more file descriptors now */
struct client *c;
struct session *s;
struct timeval tv;
- u_int i;
int interval;
time_t difference;
if (gettimeofday(&tv, NULL) != 0)
fatal("gettimeofday failed");
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session == NULL)
continue;
if (c->message_string != NULL || c->prompt_string != NULL) {
/*
struct client *c;
struct window *w;
struct window_pane *wp;
- u_int i;
-
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL)
- continue;
+ TAILQ_FOREACH(c, &clients, entry) {
server_client_check_exit(c);
if (c->session != NULL) {
server_client_check_redraw(c);
void
server_client_check_focus(struct window_pane *wp)
{
- u_int i;
struct client *c;
int push;
* If our window is the current window in any focused clients with an
* attached session, we're focused.
*/
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
- continue;
-
- if (!(c->flags & CLIENT_FOCUSED))
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session == NULL || !(c->flags & CLIENT_FOCUSED))
continue;
if (c->session->flags & SESSION_UNATTACHED)
continue;
-/* $OpenBSD: server-fn.c,v 1.83 2015/04/22 15:32:33 nicm Exp $ */
+/* $OpenBSD: server-fn.c,v 1.84 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
size_t len)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
- continue;
+ TAILQ_FOREACH(c, &clients, entry) {
if (c->session == s)
server_write_client(c, type, buf, len);
}
server_redraw_session(struct session *s)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
- continue;
+ TAILQ_FOREACH(c, &clients, entry) {
if (c->session == s)
server_redraw_client(c);
}
server_status_session(struct session *s)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
- continue;
+ TAILQ_FOREACH(c, &clients, entry) {
if (c->session == s)
server_status_client(c);
}
server_redraw_window(struct window *w)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
- continue;
- if (c->session->curw->window == w)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != NULL && c->session->curw->window == w)
server_redraw_client(c);
}
w->flags |= WINDOW_REDRAW;
server_redraw_window_borders(struct window *w)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
- continue;
- if (c->session->curw->window == w)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != NULL && c->session->curw->window == w)
c->flags |= CLIENT_BORDERS;
}
}
server_lock(void)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL)
- continue;
- server_lock_client(c);
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != NULL)
+ server_lock_client(c);
}
}
server_lock_session(struct session *s)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL || c->session != s)
- continue;
- server_lock_client(c);
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session == s)
+ server_lock_client(c);
}
}
{
struct client *c;
struct session *s_new;
- u_int i;
if (!options_get_number(&s->options, "detach-on-destroy"))
s_new = server_next_session(s);
else
s_new = NULL;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session != s)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != s)
continue;
if (s_new == NULL) {
c->session = NULL;
-/* $OpenBSD: server-window.c,v 1.33 2015/04/22 15:30:11 nicm Exp $ */
+/* $OpenBSD: server-window.c,v 1.34 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
{
struct client *c;
struct window *w = wl->window;
- u_int i;
int action, visual;
if (!(w->flags & WINDOW_BELL) || wl->flags & WINLINK_BELL)
action = options_get_number(&s->options, "bell-action");
if (action == BELL_NONE)
return (0);
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session != s || c->flags & CLIENT_CONTROL)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != s || c->flags & CLIENT_CONTROL)
continue;
if (!visual) {
if (c->session->curw->window == w || action == BELL_ANY)
{
struct client *c;
struct window *w = wl->window;
- u_int i;
if (s->curw->window == w)
w->flags &= ~WINDOW_ACTIVITY;
wl->flags |= WINLINK_ACTIVITY;
if (options_get_number(&s->options, "visual-activity")) {
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session != s)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != s)
continue;
status_message_set(c, "Activity in window %d", wl->idx);
}
struct client *c;
struct window *w = wl->window;
struct timeval timer;
- u_int i;
int silence_interval, timer_difference;
if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
wl->flags |= WINLINK_SILENCE;
if (options_get_number(&s->options, "visual-silence")) {
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session != s)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != s)
continue;
status_message_set(c, "Silence in window %d", wl->idx);
}
ring_bell(struct session *s)
{
struct client *c;
- u_int i;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && c->session == s && !(c->flags & CLIENT_CONTROL))
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session == s && !(c->flags & CLIENT_CONTROL))
tty_bell(&c->tty);
}
}
-/* $OpenBSD: server.c,v 1.121 2015/04/22 15:30:11 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.122 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
RB_INIT(&windows);
RB_INIT(&all_window_panes);
- ARRAY_INIT(&clients);
- ARRAY_INIT(&dead_clients);
+ TAILQ_INIT(&clients);
+ TAILQ_INIT(&dead_clients);
RB_INIT(&sessions);
RB_INIT(&dead_sessions);
TAILQ_INIT(&session_groups);
cfg_cmd_q->emptyfn = cfg_default_done;
cfg_finished = 0;
cfg_references = 1;
- cfg_client = ARRAY_FIRST(&clients);
+ cfg_client = TAILQ_FIRST(&clients);
if (cfg_client != NULL)
cfg_client->references++;
server_should_shutdown(void)
{
struct client *c;
- u_int i;
if (!options_get_number(&global_options, "exit-unattached")) {
if (!RB_EMPTY(&sessions))
return (0);
}
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && c->session != NULL)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != NULL)
return (0);
}
* clients but don't actually exit until they've gone.
*/
cmd_wait_for_flush();
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- if (ARRAY_ITEM(&clients, i) != NULL)
- return (0);
- }
+ if (!TAILQ_EMPTY(&clients))
+ return (0);
return (1);
}
void
server_send_shutdown(void)
{
- struct client *c;
- struct session *s, *next_s;
- u_int i;
+ struct client *c, *c1;
+ struct session *s, *s1;
cmd_wait_for_flush();
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL) {
- if (c->flags & (CLIENT_BAD|CLIENT_SUSPENDED))
- server_client_lost(c);
- else
- server_write_client(c, MSG_SHUTDOWN, NULL, 0);
- c->session = NULL;
- }
+ TAILQ_FOREACH_SAFE(c, &clients, entry, c1) {
+ if (c->flags & (CLIENT_BAD|CLIENT_SUSPENDED))
+ server_client_lost(c);
+ else
+ server_write_client(c, MSG_SHUTDOWN, NULL, 0);
+ c->session = NULL;
}
- s = RB_MIN(sessions, &sessions);
- while (s != NULL) {
- next_s = RB_NEXT(sessions, &sessions, s);
+ RB_FOREACH_SAFE(s, sessions, &sessions, s1)
session_destroy(s);
- s = next_s;
- }
}
/* Free dead, unreferenced clients and sessions. */
void
server_clean_dead(void)
{
- struct session *s, *next_s;
- struct client *c;
- u_int i;
-
- s = RB_MIN(sessions, &dead_sessions);
- while (s != NULL) {
- next_s = RB_NEXT(sessions, &dead_sessions, s);
- if (s->references == 0) {
- RB_REMOVE(sessions, &dead_sessions, s);
- free(s->name);
- free(s);
- }
- s = next_s;
+ struct session *s, *s1;
+ struct client *c, *c1;
+
+ RB_FOREACH_SAFE(s, sessions, &dead_sessions, s1) {
+ if (s->references != 0)
+ continue;
+ RB_REMOVE(sessions, &dead_sessions, s);
+ free(s->name);
+ free(s);
}
- for (i = 0; i < ARRAY_LENGTH(&dead_clients); i++) {
- c = ARRAY_ITEM(&dead_clients, i);
- if (c == NULL || c->references != 0)
+ TAILQ_FOREACH_SAFE(c, &dead_clients, entry, c1) {
+ if (c->references != 0)
continue;
- ARRAY_SET(&dead_clients, i, NULL);
+ TAILQ_REMOVE(&dead_clients, c, entry);
free(c);
}
}
-/* $OpenBSD: tmux.h,v 1.498 2015/04/24 22:19:36 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.499 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct cmd_q *cmdq;
int references;
+
+ TAILQ_ENTRY(client) entry;
};
-ARRAY_DECL(clients, struct client *);
+TAILQ_HEAD(clients, client);
/* Parsed arguments structures. */
struct args_entry {
-/* $OpenBSD: tty.c,v 1.177 2015/04/19 21:34:21 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.178 2015/04/24 23:17:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
{
struct window_pane *wp = ctx->wp;
struct client *c;
- u_int i;
/* wp can be NULL if updating the screen but not the terminal. */
if (wp == NULL)
if (!window_pane_visible(wp) || wp->flags & PANE_DROP)
return;
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session == NULL || c->tty.term == NULL)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session == NULL || c->tty.term == NULL)
continue;
if (c->flags & CLIENT_SUSPENDED)
continue;