diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2007-09-27 09:52:03 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2007-09-27 09:52:03 +0000 |
commit | 22990a6595fdff840010aa6df9a60ada61331b5e (patch) | |
tree | 48fa49a39ca8ba91652d9e5bbdcc7a942462c183 /server-fn.c | |
parent | 3fa8f1636486420b9f27b129dbd0f36015d4c24b (diff) | |
download | rtmux-22990a6595fdff840010aa6df9a60ada61331b5e.tar.gz rtmux-22990a6595fdff840010aa6df9a60ada61331b5e.tar.bz2 rtmux-22990a6595fdff840010aa6df9a60ada61331b5e.zip |
New session selection rules:
- find by name if given
- otherwise try current index from $TMUX
- otherwise if only one session, use it
- otherwise error
Diffstat (limited to 'server-fn.c')
-rw-r--r-- | server-fn.c | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/server-fn.c b/server-fn.c index 0429af94..9309b343 100644 --- a/server-fn.c +++ b/server-fn.c @@ -1,4 +1,4 @@ -/* $Id: server-fn.c,v 1.3 2007-09-27 09:15:58 nicm Exp $ */ +/* $Id: server-fn.c,v 1.4 2007-09-27 09:52:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -19,9 +19,60 @@ #include <sys/types.h> #include <string.h> +#include <unistd.h> #include "tmux.h" +/* Find session from sessid. */ +struct session * +server_find_sessid(struct sessid *sid, char **cause) +{ + struct session *s; + u_int i, n; + + if (*sid->name != '\0') { + if ((s = session_find(sid->name)) == NULL) { + xasprintf(cause, "session not found: %s", sid->name); + return (NULL); + } + return (s); + } + + if (sid->pid != -1) { + if (sid->pid != getpid()) { + xasprintf(cause, "wrong server: %lld", sid->pid); + return (NULL); + } + if (sid->idx > ARRAY_LENGTH(&sessions)) { + xasprintf(cause, "index out of range: %u", sid->idx); + return (NULL); + } + if ((s = ARRAY_ITEM(&sessions, sid->idx) = NULL)) { + xasprintf(cause, "session doesn't exist: %u", sid->idx); + return (NULL); + } + return (s); + } + + s = NULL; + n = 0; + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + if (ARRAY_ITEM(&sessions, i) != NULL) { + s = ARRAY_ITEM(&sessions, i); + n++; + } + } + if (s == NULL) { + xasprintf(cause, "no sessions"); + return (NULL); + } + if (n != 1) { + xasprintf(cause, "multiple sessions and session not specified"); + return (NULL); + } + return (s); +} + /* Write command to a client. */ void server_write_client(struct client *c, enum hdrtype type, void *buf, size_t len) |