Since we will be removing the winlinks as we process them, it is important to use RB_FOREACH_SAFE (now that it is available) to make sure that the traversal is not affected by removing the current winlink.
--- Example: Without the "safe" traversal, some winlinks may not be removed: tmux -L test-kw-a new-session -ds kw-a # window 0 tmux -L test-kw-a new-window -dt kw-a # window 1 tmux -L test-kw-a new-window -dt kw-a # window 2 tmux -L test-kw-a kill-window -at kw-a # kill all but 0 (i.e. 1 and 2) tmux -L test-kw-a list-windows -t kw-a # oops, window 2 is still left tmux -L test-kw-a kill-session -t kw-a Note: The above kill-window command will crash the server unless the previous "use session from -t" patch has also been applied. Also note: It may be difficult to paste the above commands unless something like my "client: defer reading stdin" patch is applied. A normal shell script should work fine. Another example: a session with windows 0, 1 (active), 2, 3: "kill-window -a" kills just 0, and 2 (should also kill 3) --- trunk/cmd-kill-window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trunk/cmd-kill-window.c b/trunk/cmd-kill-window.c index abe7738..ec2b189 100644 --- a/trunk/cmd-kill-window.c +++ b/trunk/cmd-kill-window.c @@ -40,14 +40,14 @@ int cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; - struct winlink *wl, *wl2; + struct winlink *wl, *wl2, *wl3; struct session *s; if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) return (-1); if (args_has(args, 'a')) { - RB_FOREACH(wl2, winlinks, &s->windows) { + RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) { if (wl != wl2) server_kill_window(wl2->window); } -- 1.7.10.2 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users