From 22990a6595fdff840010aa6df9a60ada61331b5e Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 27 Sep 2007 09:52:03 +0000 Subject: New session selection rules: - find by name if given - otherwise try current index from $TMUX - otherwise if only one session, use it - otherwise error --- server-msg.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'server-msg.c') diff --git a/server-msg.c b/server-msg.c index 0f8d092d..4d84a3d3 100644 --- a/server-msg.c +++ b/server-msg.c @@ -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 @@ -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); } -- cgit v1.2.3