If a session is destroyed, safely kill all other clients attached to it.

This commit is contained in:
Nicholas Marriott 2007-08-27 12:05:15 +00:00
parent 7000277f94
commit 6e210bb005
3 changed files with 41 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $Id: server.c,v 1.4 2007-08-27 11:45:03 nicm Exp $ */ /* $Id: server.c,v 1.5 2007-08-27 12:05:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -655,17 +655,33 @@ void
lost_window(struct window *w) lost_window(struct window *w)
{ {
struct client *c; struct client *c;
u_int i; struct session *s;
u_int i, j;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) { for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i); c = ARRAY_ITEM(&clients, i);
if (c != NULL && c->session != NULL) { if (c == NULL || c->session == NULL)
if (session_has(c->session, w)) { continue;
if (session_detach(c->session, w) != 0) if (!session_has(c->session, w))
write_client(c, MSG_EXIT, NULL, 0); continue;
else s = c->session;
changed_window(c);
} /* Detach window from session. */
session_detach(s, w);
/* Try to flush session and redraw if not destroyed. */
if (session_flush(s) == 0) {
changed_window(c);
continue;
}
/* Kill all clients attached to this session. */
for (j = 0; j < ARRAY_LENGTH(&clients); j++) {
c = ARRAY_ITEM(&clients, j);
if (c == NULL || c->session != s)
continue;
c->session = NULL;
write_client(c, MSG_EXIT, NULL, 0);
} }
} }
} }

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.3 2007-08-27 09:53:38 nicm Exp $ */ /* $Id: session.c,v 1.4 2007-08-27 12:05:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -119,7 +119,7 @@ session_attach(struct session *s, struct window *w)
} }
/* Detach a window from a session. */ /* Detach a window from a session. */
int void
session_detach(struct session *s, struct window *w) session_detach(struct session *s, struct window *w)
{ {
if (s->window == w) { if (s->window == w) {
@ -128,13 +128,20 @@ session_detach(struct session *s, struct window *w)
} }
window_remove(&s->windows, w); window_remove(&s->windows, w);
if (ARRAY_EMPTY(&s->windows)) {
session_destroy(s);
return (1);
}
return (0); return (0);
} }
/* Flush session if it is empty. */
int
session_flush(struct session *s)
{
if (!ARRAY_EMPTY(&s->windows))
return (0);
session_destroy(s);
return (1);
}
/* Return if session has window. */ /* Return if session has window. */
int int
session_has(struct session *s, struct window *w) session_has(struct session *s, struct window *w)

5
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.3 2007-08-27 11:05:21 nicm Exp $ */ /* $Id: tmux.h,v 1.4 2007-08-27 12:05:15 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -531,7 +531,8 @@ void session_destroy(struct session *);
int session_index(struct session *, u_int *); int session_index(struct session *, u_int *);
int session_new(struct session *, const char *, u_int, u_int); int session_new(struct session *, const char *, u_int, u_int);
void session_attach(struct session *, struct window *); void session_attach(struct session *, struct window *);
int session_detach(struct session *, struct window *); void session_detach(struct session *, struct window *);
int session_flush(struct session *);
int session_has(struct session *, struct window *); int session_has(struct session *, struct window *);
int session_next(struct session *); int session_next(struct session *);
int session_previous(struct session *); int session_previous(struct session *);