If the pane is still on all_window_panes but not actually connected to
authornicm <nicm@openbsd.org>
Thu, 22 Oct 2015 11:23:00 +0000 (11:23 +0000)
committernicm <nicm@openbsd.org>
Thu, 22 Oct 2015 11:23:00 +0000 (11:23 +0000)
window or session (which can happen if it is killed during a command
sequence and something else has a reference), fall back to the best
effort. Fixes "tmux killw\; detach" for Rudis Muiznieks.

usr.bin/tmux/cmd-find.c

index 2654ee0..d6c2399 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-find.c,v 1.13 2015/09/14 13:22:02 nicm Exp $ */
+/* $OpenBSD: cmd-find.c,v 1.14 2015/10/22 11:23:00 nicm Exp $ */
 
 /*
  * Copyright (c) 2015 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -255,24 +255,35 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs)
                wp = NULL;
 
        /* Not running in a pane. We know nothing. Find the best session. */
-       if (wp == NULL) {
-               fs->s = cmd_find_best_session(NULL, 0, fs->flags);
-               if (fs->s == NULL)
-                       return (-1);
-               fs->wl = fs->s->curw;
-               fs->idx = fs->wl->idx;
-               fs->w = fs->wl->window;
-               fs->wp = fs->w->active;
-               return (0);
-       }
+       if (wp == NULL)
+               goto unknown_pane;
 
        /* We now know the window and pane. */
        fs->w = wp->window;
        fs->wp = wp;
 
        /* Find the best session and winlink. */
-       if (cmd_find_best_session_with_window(fs) != 0)
+       if (cmd_find_best_session_with_window(fs) != 0) {
+               if (wp != NULL) {
+                       /*
+                        * The window may have been destroyed but the pane
+                        * still on all_window_panes due to something else
+                        * holding a reference.
+                        */
+                       goto unknown_pane;
+               }
                return (-1);
+       }
+       return (0);
+
+unknown_pane:
+       fs->s = cmd_find_best_session(NULL, 0, fs->flags);
+       if (fs->s == NULL)
+               return (-1);
+       fs->wl = fs->s->curw;
+       fs->idx = fs->wl->idx;
+       fs->w = fs->wl->window;
+       fs->wp = fs->w->active;
        return (0);
 }