mirror of
https://github.com/tmux/tmux.git
synced 2025-01-07 16:28:48 +00:00
Write error messages for rename. Also tweak some error outputs, and fix -i.
This commit is contained in:
parent
a6875d0dae
commit
653ee721df
4
CHANGES
4
CHANGES
@ -1,5 +1,7 @@
|
|||||||
29 September 2007
|
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.
|
* (nicm) Pass through bell in any window to current.
|
||||||
|
|
||||||
28 September 2007
|
28 September 2007
|
||||||
@ -72,5 +74,5 @@
|
|||||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||||
customisation.
|
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 $
|
||||||
|
|
||||||
|
30
client.c
30
client.c
@ -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>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -128,11 +128,13 @@ int
|
|||||||
client_flush(struct client_ctx *cctx)
|
client_flush(struct client_ctx *cctx)
|
||||||
{
|
{
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
|
struct hdr hdr;
|
||||||
|
|
||||||
/* XXX error response! */
|
for (;;) {
|
||||||
while (BUFFER_USED(cctx->srv_out) > 0) {
|
|
||||||
pfd.fd = cctx->srv_fd;
|
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 (poll(&pfd, 1, INFTIM) == -1) {
|
||||||
if (errno == EAGAIN || errno == EINTR)
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
@ -144,9 +146,25 @@ client_flush(struct client_ctx *cctx)
|
|||||||
log_warnx("lost server");
|
log_warnx("lost server");
|
||||||
return (1);
|
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
|
int
|
||||||
|
17
op.c
17
op.c
@ -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>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -38,7 +38,7 @@ op_new(char *path, int argc, char **argv)
|
|||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
case 's':
|
||||||
if (strlcpy(name, optarg, sizeof name) >= sizeof name) {
|
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);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -77,7 +77,7 @@ op_attach(char *path, int argc, char **argv)
|
|||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
case 's':
|
||||||
if (strlcpy(name, optarg, sizeof name) >= sizeof name) {
|
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);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -119,16 +119,17 @@ op_rename(char *path, int argc, char **argv)
|
|||||||
case 's':
|
case 's':
|
||||||
if (strlcpy(sname, optarg, sizeof sname)
|
if (strlcpy(sname, optarg, sizeof sname)
|
||||||
>= sizeof sname) {
|
>= sizeof sname) {
|
||||||
log_warnx("%s: session name too long", optarg);
|
log_warnx("session name too long: %s", optarg);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
data.idx = strtonum(optarg, 0, INT_MAX, &errstr);
|
data.idx = strtonum(optarg, 0, INT_MAX, &errstr);
|
||||||
if (errstr != NULL)
|
if (errstr != NULL) {
|
||||||
log_warnx("%s: window index %s", optarg,
|
log_warnx(
|
||||||
errstr);
|
"window index %s: %s", errstr, optarg);
|
||||||
return (1);
|
return (1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
@ -146,7 +147,7 @@ op_rename(char *path, int argc, char **argv)
|
|||||||
client_fill_sessid(&data.sid, sname);
|
client_fill_sessid(&data.sid, sname);
|
||||||
if ((strlcpy(data.newname, argv[0], sizeof data.newname)
|
if ((strlcpy(data.newname, argv[0], sizeof data.newname)
|
||||||
>= 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);
|
return (1);
|
||||||
}
|
}
|
||||||
client_write_server(&cctx, MSG_RENAME, &data, sizeof data);
|
client_write_server(&cctx, MSG_RENAME, &data, sizeof data);
|
||||||
|
16
server-fn.c
16
server-fn.c
@ -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>
|
* 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);
|
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. */
|
/* Write message command to a client. */
|
||||||
void
|
void
|
||||||
|
26
server-msg.c
26
server-msg.c
@ -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>
|
* 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;
|
c->sy = 25;
|
||||||
|
|
||||||
if ((c->session = server_find_sessid(&data.sid, &cause)) == NULL) {
|
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);
|
xfree(cause);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -353,7 +353,7 @@ server_msg_fn_windows(struct hdr *hdr, struct client *c)
|
|||||||
buffer_read(c->in, &data, hdr->size);
|
buffer_read(c->in, &data, hdr->size);
|
||||||
|
|
||||||
if ((s = server_find_sessid(&data.sid, &cause)) == NULL) {
|
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);
|
xfree(cause);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -396,26 +396,28 @@ server_msg_fn_rename(struct hdr *hdr, struct client *c)
|
|||||||
buffer_read(c->in, &data, hdr->size);
|
buffer_read(c->in, &data, hdr->size);
|
||||||
|
|
||||||
data.newname[(sizeof data.newname) - 1] = '\0';
|
data.newname[(sizeof data.newname) - 1] = '\0';
|
||||||
|
|
||||||
if ((s = server_find_sessid(&data.sid, &cause)) == NULL) {
|
if ((s = server_find_sessid(&data.sid, &cause)) == NULL) {
|
||||||
/* XXX: Send message to client */
|
server_write_error(c, "%s", cause);
|
||||||
|
xfree(cause);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.idx == -1)
|
if (data.idx == -1)
|
||||||
w = s->window;
|
w = s->window;
|
||||||
else
|
else {
|
||||||
|
if (data.idx < 0)
|
||||||
|
fatalx("bad window index");
|
||||||
w = window_at(&s->windows, data.idx);
|
w = window_at(&s->windows, data.idx);
|
||||||
|
if (w == NULL) {
|
||||||
if (w == NULL) {
|
server_write_error(c, "window not found: %d", data.idx);
|
||||||
/* XXX: Send message to client */
|
return (0);
|
||||||
return (0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(w->name, data.newname, sizeof w->name);
|
strlcpy(w->name, data.newname, sizeof w->name);
|
||||||
|
|
||||||
|
server_write_client(c, MSG_DONE, NULL, 0);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Last window message from client */
|
/* Last window message from client */
|
||||||
|
4
tmux.h
4
tmux.h
@ -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>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -261,6 +261,7 @@ struct buffer {
|
|||||||
enum hdrtype {
|
enum hdrtype {
|
||||||
MSG_ATTACH,
|
MSG_ATTACH,
|
||||||
MSG_CREATE,
|
MSG_CREATE,
|
||||||
|
MSG_DONE,
|
||||||
MSG_ERROR,
|
MSG_ERROR,
|
||||||
MSG_EXIT,
|
MSG_EXIT,
|
||||||
MSG_INPUT,
|
MSG_INPUT,
|
||||||
@ -538,6 +539,7 @@ int server_msg_dispatch(struct client *);
|
|||||||
|
|
||||||
/* server-fn.c */
|
/* server-fn.c */
|
||||||
struct session *server_find_sessid(struct sessid *, char **);
|
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_message(struct client *, const char *, ...);
|
||||||
void server_write_client(
|
void server_write_client(
|
||||||
struct client *, enum hdrtype, const void *, size_t);
|
struct client *, enum hdrtype, const void *, size_t);
|
||||||
|
Loading…
Reference in New Issue
Block a user