Lift last MAXNAMELEN limit on -s argument.

This commit is contained in:
Nicholas Marriott 2007-10-23 10:48:23 +00:00
parent 21c17da7e6
commit 688a487570
7 changed files with 45 additions and 48 deletions

View File

@ -1,5 +1,6 @@
23 October 2007
* (nicm) Lift limit on session name passed with -s.
* (nicm) Show size in session/window lists.
* (nicm) Pass tty up to server when client identifies and add a list-clients
command to list connected clients.
@ -150,5 +151,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.47 2007-10-23 09:36:19 nicm Exp $
$Id: CHANGES,v 1.48 2007-10-23 10:48:22 nicm Exp $

1
TODO
View File

@ -47,7 +47,6 @@
-- For 0.1 --------------------------------------------------------------------
- man page
- get rid of MAXNAMELEN limits (sessid)
- commands:
rename sessions
swap windows

View File

@ -1,4 +1,4 @@
/* $Id: client-fn.c,v 1.2 2007-10-03 12:34:16 nicm Exp $ */
/* $Id: client-fn.c,v 1.3 2007-10-23 10:48:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,15 +24,13 @@
#include "tmux.h"
void
client_fill_sessid(struct sessid *sid, char name[MAXNAMELEN])
client_fill_session(struct msg_command_data *data)
{
char *env, *ptr, buf[256];
const char *errstr;
long long ll;
strlcpy(sid->name, name, sizeof sid->name);
sid->pid = -1;
data->pid = -1;
if ((env = getenv("TMUX")) == NULL)
return;
if ((ptr = strchr(env, ',')) == NULL)
@ -45,12 +43,12 @@ client_fill_sessid(struct sessid *sid, char name[MAXNAMELEN])
ll = strtonum(ptr + 1, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return;
sid->idx = ll;
data->idx = ll;
ll = strtonum(buf, 0, LLONG_MAX, &errstr);
if (errstr != NULL)
return;
sid->pid = ll;
data->pid = ll;
}
void

View File

@ -1,4 +1,4 @@
/* $Id: server-fn.c,v 1.21 2007-10-19 10:21:35 nicm Exp $ */
/* $Id: server-fn.c,v 1.22 2007-10-23 10:48:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -23,33 +23,33 @@
#include "tmux.h"
/* Find session from sessid. */
/* Find session from command message. */
struct session *
server_find_sessid(struct sessid *sid, char **cause)
server_extract_session(struct msg_command_data *data, char *name, char **cause)
{
struct session *s;
u_int i, n;
if (*sid->name != '\0') {
sid->name[(sizeof sid->name) - 1] = '\0';
if ((s = session_find(sid->name)) == NULL) {
xasprintf(cause, "session not found: %s", sid->name);
if (name != NULL) {
if ((s = session_find(name)) == NULL) {
xasprintf(cause, "session not found: %s", name);
return (NULL);
}
return (s);
}
if (sid->pid != -1) {
if (sid->pid != getpid()) {
xasprintf(cause, "wrong server: %lld", sid->pid);
if (data->pid != -1) {
if (data->pid != getpid()) {
xasprintf(cause, "wrong server: %lld", data->pid);
return (NULL);
}
if (sid->idx > ARRAY_LENGTH(&sessions)) {
xasprintf(cause, "index out of range: %u", sid->idx);
if (data->idx > ARRAY_LENGTH(&sessions)) {
xasprintf(cause, "index out of range: %u", data->idx);
return (NULL);
}
if ((s = ARRAY_ITEM(&sessions, sid->idx)) == NULL) {
xasprintf(cause, "session doesn't exist: %u", sid->idx);
if ((s = ARRAY_ITEM(&sessions, data->idx)) == NULL) {
xasprintf(
cause, "session doesn't exist: %u", data->idx);
return (NULL);
}
return (s);

View File

@ -1,4 +1,4 @@
/* $Id: server-msg.c,v 1.28 2007-10-23 09:36:19 nicm Exp $ */
/* $Id: server-msg.c,v 1.29 2007-10-23 10:48:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -108,11 +108,12 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
struct msg_command_data data;
struct cmd_ctx ctx;
struct cmd *cmd;
char *cause;
char *name, *cause;
if (hdr->size < sizeof data)
fatalx("bad MSG_COMMAND size");
buffer_read(c->in, &data, sizeof data);
name = cmd_recv_string(c->in);
cmd = cmd_recv(c->in);
log_debug("got command %s from client %d", cmd->entry->name, c->fd);
@ -123,26 +124,29 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
ctx.client = c;
ctx.flags = 0;
if (data.sid.pid != -1 && (cmd->entry->flags & CMD_CANTNEST)) {
if (data.pid != -1 && (cmd->entry->flags & CMD_CANTNEST)) {
server_msg_fn_command_error(&ctx, "sessions should be nested "
"with care. unset $TMUX to force");
return (0);
goto out;
}
if (cmd->entry->flags & CMD_NOSESSION)
ctx.session = NULL;
else {
ctx.session = server_find_sessid(&data.sid, &cause);
ctx.session = server_extract_session(&data, name, &cause);
if (ctx.session == NULL) {
server_msg_fn_command_error(&ctx, "%s", cause);
xfree(cause);
return (0);
goto out;
}
}
cmd_exec(cmd, &ctx);
cmd_free(cmd);
out:
if (name != NULL)
xfree(name);
return (0);
}

13
tmux.c
View File

@ -1,4 +1,4 @@
/* $Id: tmux.c,v 1.35 2007-10-20 09:57:08 nicm Exp $ */
/* $Id: tmux.c,v 1.36 2007-10-23 10:48:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -170,19 +170,17 @@ main(int argc, char **argv)
struct hdr hdr;
const char *shell;
struct passwd *pw;
char *path, *cause, name[MAXNAMELEN];
char *path, *cause, *name;
int n, opt;
*name = '\0';
path = NULL;
path = name = NULL;
while ((opt = getopt(argc, argv, "S:s:v")) != EOF) {
switch (opt) {
case 'S':
path = xstrdup(optarg);
break;
case 's':
if (strlcpy(name, optarg, sizeof name) >= sizeof name)
errx(1, "session name too long: %s", optarg);
name = xstrdup(optarg);
break;
case 'v':
debug_level++;
@ -225,10 +223,11 @@ main(int argc, char **argv)
memset(&cctx, 0, sizeof cctx);
if (!(cmd->entry->flags & CMD_NOSESSION) ||
(cmd->entry->flags & CMD_CANTNEST))
client_fill_sessid(&data.sid, name);
client_fill_session(&data);
if (client_init(path, &cctx, cmd->entry->flags & CMD_STARTSERVER) != 0)
exit(1);
b = buffer_create(BUFSIZ);
cmd_send_string(b, name);
cmd_send(cmd, b);
cmd_free(cmd);

20
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.64 2007-10-23 10:21:59 nicm Exp $ */
/* $Id: tmux.h,v 1.65 2007-10-23 10:48:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -44,7 +44,6 @@ extern char *__progname;
#define TTY_NAME_MAX 32
#endif
#define MAXNAMELEN 32
#define MAXTITLELEN 192
/* Fatal errors. */
@ -283,13 +282,6 @@ enum hdrtype {
MSG_PAUSE,
};
/* Session identification. */
struct sessid {
long long pid; /* pid from $TMUX or -1 */
u_int idx; /* index from $TMUX */
char name[MAXNAMELEN]; /* empty for current */
};
/* Message header structure. */
struct hdr {
enum hdrtype type;
@ -297,7 +289,10 @@ struct hdr {
};
struct msg_command_data {
struct sessid sid;
long long pid; /* pid from $TMUX or -1 */
u_int idx; /* index from $TMUX */
size_t namelen;
};
struct msg_identify_data {
@ -565,7 +560,7 @@ int client_msg_dispatch(struct client_ctx *, char **);
void client_write_server(struct client_ctx *, enum hdrtype, void *, size_t);
void client_write_server2(
struct client_ctx *, enum hdrtype, void *, size_t, void *, size_t);
void client_fill_sessid(struct sessid *, char [MAXNAMELEN]);
void client_fill_session(struct msg_command_data *);
/* key-bindings.c */
extern struct bindings key_bindings;
@ -587,7 +582,8 @@ int server_start(char *);
int server_msg_dispatch(struct client *);
/* server-fn.c */
struct session *server_find_sessid(struct sessid *, char **);
struct session *server_extract_session(
struct msg_command_data *, char *, char **);
void server_write_client(
struct client *, enum hdrtype, const void *, size_t);
void server_write_session(