mirror of
https://github.com/tmate-io/tmate.git
synced 2024-12-22 23:00:51 +01:00
If a session is destroyed, safely kill all other clients attached to it.
This commit is contained in:
parent
7000277f94
commit
6e210bb005
34
server.c
34
server.c
@ -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>
|
||||
@ -655,17 +655,33 @@ void
|
||||
lost_window(struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
u_int i;
|
||||
struct session *s;
|
||||
u_int i, j;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c != NULL && c->session != NULL) {
|
||||
if (session_has(c->session, w)) {
|
||||
if (session_detach(c->session, w) != 0)
|
||||
write_client(c, MSG_EXIT, NULL, 0);
|
||||
else
|
||||
changed_window(c);
|
||||
}
|
||||
if (c == NULL || c->session == NULL)
|
||||
continue;
|
||||
if (!session_has(c->session, w))
|
||||
continue;
|
||||
s = c->session;
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
19
session.c
19
session.c
@ -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>
|
||||
@ -119,7 +119,7 @@ session_attach(struct session *s, struct window *w)
|
||||
}
|
||||
|
||||
/* Detach a window from a session. */
|
||||
int
|
||||
void
|
||||
session_detach(struct session *s, struct window *w)
|
||||
{
|
||||
if (s->window == w) {
|
||||
@ -128,13 +128,20 @@ session_detach(struct session *s, struct window *w)
|
||||
}
|
||||
|
||||
window_remove(&s->windows, w);
|
||||
if (ARRAY_EMPTY(&s->windows)) {
|
||||
session_destroy(s);
|
||||
return (1);
|
||||
}
|
||||
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. */
|
||||
int
|
||||
session_has(struct session *s, struct window *w)
|
||||
|
5
tmux.h
5
tmux.h
@ -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>
|
||||
@ -531,7 +531,8 @@ void session_destroy(struct session *);
|
||||
int session_index(struct session *, u_int *);
|
||||
int session_new(struct session *, const char *, u_int, u_int);
|
||||
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_next(struct session *);
|
||||
int session_previous(struct session *);
|
||||
|
Loading…
Reference in New Issue
Block a user