Write error messages for rename. Also tweak some error outputs, and fix -i.

pull/1/head
Nicholas Marriott 2007-09-29 13:22:15 +00:00
parent a6875d0dae
commit 653ee721df
6 changed files with 68 additions and 29 deletions

View File

@ -1,5 +1,7 @@
29 September 2007
* (nicm) Permit error messages to be passed back for transient clients like
rename. Also make rename -i work.
* (nicm) Pass through bell in any window to current.
28 September 2007
@ -72,5 +74,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.14 2007-09-29 09:53:25 nicm Exp $
$Id: CHANGES,v 1.15 2007-09-29 13:22:15 nicm Exp $

View File

@ -1,4 +1,4 @@
/* $Id: client.c,v 1.8 2007-09-28 19:04:21 nicm Exp $ */
/* $Id: client.c,v 1.9 2007-09-29 13:22:15 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -128,11 +128,13 @@ int
client_flush(struct client_ctx *cctx)
{
struct pollfd pfd;
struct hdr hdr;
/* XXX error response! */
while (BUFFER_USED(cctx->srv_out) > 0) {
for (;;) {
pfd.fd = cctx->srv_fd;
pfd.events = POLLIN|POLLOUT;
pfd.events = POLLIN;
if (BUFFER_USED(cctx->srv_out) > 0)
pfd.events |= POLLOUT;
if (poll(&pfd, 1, INFTIM) == -1) {
if (errno == EAGAIN || errno == EINTR)
@ -144,9 +146,25 @@ client_flush(struct client_ctx *cctx)
log_warnx("lost server");
return (1);
}
}
return (0);
if (BUFFER_USED(cctx->srv_in) < sizeof hdr)
continue;
memcpy(&hdr, BUFFER_OUT(cctx->srv_in), sizeof hdr);
if (BUFFER_USED(cctx->srv_in) < (sizeof hdr) + hdr.size)
continue;
buffer_remove(cctx->srv_in, sizeof hdr);
if (hdr.type == MSG_DONE)
return (0);
if (hdr.type == MSG_ERROR) {
if (hdr.size > INT_MAX - 1)
fatalx("bad MSG_ERROR size");
log_warnx(
"%.*s", (int) hdr.size, BUFFER_OUT(cctx->srv_in));
return (1);
}
fatalx("unexpected message");
}
}
int

17
op.c
View File

@ -1,4 +1,4 @@
/* $Id: op.c,v 1.7 2007-09-28 21:41:52 mxey Exp $ */
/* $Id: op.c,v 1.8 2007-09-29 13:22:15 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -38,7 +38,7 @@ op_new(char *path, int argc, char **argv)
switch (opt) {
case 's':
if (strlcpy(name, optarg, sizeof name) >= sizeof name) {
log_warnx("%s: session name too long", optarg);
log_warnx("session name too long: %s", optarg);
return (1);
}
break;
@ -77,7 +77,7 @@ op_attach(char *path, int argc, char **argv)
switch (opt) {
case 's':
if (strlcpy(name, optarg, sizeof name) >= sizeof name) {
log_warnx("%s: session name too long", optarg);
log_warnx("session name too long: %s", optarg);
return (1);
}
break;
@ -119,16 +119,17 @@ op_rename(char *path, int argc, char **argv)
case 's':
if (strlcpy(sname, optarg, sizeof sname)
>= sizeof sname) {
log_warnx("%s: session name too long", optarg);
log_warnx("session name too long: %s", optarg);
return (1);
}
break;
case 'i':
data.idx = strtonum(optarg, 0, INT_MAX, &errstr);
if (errstr != NULL)
log_warnx("%s: window index %s", optarg,
errstr);
if (errstr != NULL) {
log_warnx(
"window index %s: %s", errstr, optarg);
return (1);
}
break;
case '?':
default:
@ -146,7 +147,7 @@ op_rename(char *path, int argc, char **argv)
client_fill_sessid(&data.sid, sname);
if ((strlcpy(data.newname, argv[0], sizeof data.newname)
>= sizeof data.newname)) {
log_warnx("%s: new window name too long", argv[0]);
log_warnx("new window name too long: %s", argv[0]);
return (1);
}
client_write_server(&cctx, MSG_RENAME, &data, sizeof data);

View File

@ -1,4 +1,4 @@
/* $Id: server-fn.c,v 1.7 2007-09-29 09:53:25 nicm Exp $ */
/* $Id: server-fn.c,v 1.8 2007-09-29 13:22:15 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -172,6 +172,20 @@ server_draw_client(struct client *c, u_int py_upper, u_int py_lower)
buffer_reverse_add(c->out, sizeof hdr);
}
/* Send error message command to client. */
void
server_write_error(struct client *c, const char *fmt, ...)
{
va_list ap;
char *msg;
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
va_end(ap);
server_write_client(c, MSG_ERROR, msg, strlen(msg));
xfree(msg);
}
/* Write message command to a client. */
void

View File

@ -1,4 +1,4 @@
/* $Id: server-msg.c,v 1.8 2007-09-28 22:47:21 nicm Exp $ */
/* $Id: server-msg.c,v 1.9 2007-09-29 13:22:15 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -155,7 +155,7 @@ server_msg_fn_attach(struct hdr *hdr, struct client *c)
c->sy = 25;
if ((c->session = server_find_sessid(&data.sid, &cause)) == NULL) {
server_write_client(c, MSG_ERROR, cause, strlen(cause));
server_write_error(c, "%s", cause);
xfree(cause);
return (0);
}
@ -353,7 +353,7 @@ server_msg_fn_windows(struct hdr *hdr, struct client *c)
buffer_read(c->in, &data, hdr->size);
if ((s = server_find_sessid(&data.sid, &cause)) == NULL) {
server_write_client(c, MSG_ERROR, cause, strlen(cause));
server_write_error(c, "%s", cause);
xfree(cause);
return (0);
}
@ -396,26 +396,28 @@ server_msg_fn_rename(struct hdr *hdr, struct client *c)
buffer_read(c->in, &data, hdr->size);
data.newname[(sizeof data.newname) - 1] = '\0';
if ((s = server_find_sessid(&data.sid, &cause)) == NULL) {
/* XXX: Send message to client */
server_write_error(c, "%s", cause);
xfree(cause);
return (0);
}
if (data.idx == -1)
if (data.idx == -1)
w = s->window;
else
else {
if (data.idx < 0)
fatalx("bad window index");
w = window_at(&s->windows, data.idx);
if (w == NULL) {
/* XXX: Send message to client */
return (0);
if (w == NULL) {
server_write_error(c, "window not found: %d", data.idx);
return (0);
}
}
strlcpy(w->name, data.newname, sizeof w->name);
server_write_client(c, MSG_DONE, NULL, 0);
return (0);
}
/* Last window message from client */

4
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.24 2007-09-29 10:57:39 nicm Exp $ */
/* $Id: tmux.h,v 1.25 2007-09-29 13:22:15 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -261,6 +261,7 @@ struct buffer {
enum hdrtype {
MSG_ATTACH,
MSG_CREATE,
MSG_DONE,
MSG_ERROR,
MSG_EXIT,
MSG_INPUT,
@ -538,6 +539,7 @@ int server_msg_dispatch(struct client *);
/* server-fn.c */
struct session *server_find_sessid(struct sessid *, char **);
void server_write_error(struct client *, const char *, ...);
void server_write_message(struct client *, const char *, ...);
void server_write_client(
struct client *, enum hdrtype, const void *, size_t);