New session selection rules:

- find by name if given
	- otherwise try current index from $TMUX
	- otherwise if only one session, use it
	- otherwise error
This commit is contained in:
Nicholas Marriott
2007-09-27 09:52:03 +00:00
parent 3fa8f16364
commit 22990a6595
7 changed files with 131 additions and 57 deletions

View File

@ -1,4 +1,4 @@
/* $Id: server-msg.c,v 1.4 2007-09-26 18:50:49 nicm Exp $ */
/* $Id: server-msg.c,v 1.5 2007-09-27 09:52:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -138,9 +138,7 @@ int
server_msg_fn_attach(struct hdr *hdr, struct client *c)
{
struct attach_data data;
char *msg;
struct session *s;
u_int i;
char *cause;
if (c->session != NULL)
return (0);
@ -155,23 +153,9 @@ server_msg_fn_attach(struct hdr *hdr, struct client *c)
if (c->sy == 0)
c->sy = 25;
if (*data.name != '\0') {
if ((c->session = session_find(data.name)) == NULL)
xasprintf(&msg, "session not found: %s", data.name);
} else {
/* Find the oldest session. */
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
if ((s = ARRAY_ITEM(&sessions, i)) == NULL)
continue;
if (c->session == NULL || s->tim < c->session->tim)
c->session = s;
}
if (c->session == NULL)
xasprintf(&msg, "no sessions found");
}
if (c->session == NULL) {
server_write_client(c, MSG_ERROR, msg, strlen(msg));
xfree(msg);
if ((c->session = server_find_sessid(&data.sid, &cause)) == NULL) {
server_write_client(c, MSG_ERROR, cause, strlen(cause));
xfree(cause);
return (0);
}
@ -361,15 +345,15 @@ server_msg_fn_windows(struct hdr *hdr, struct client *c)
struct session *s;
struct window *w;
u_int i;
char *cause;
if (hdr->size != sizeof data)
fatalx("bad MSG_WINDOWS size");
buffer_read(c->in, &data, hdr->size);
s = session_find(data.name);
if (s == NULL) {
data.windows = 0;
server_write_client(c, MSG_WINDOWS, &data, sizeof data);
if ((s = server_find_sessid(&data.sid, &cause)) == NULL) {
server_write_client(c, MSG_ERROR, cause, strlen(cause));
xfree(cause);
return (0);
}