summaryrefslogtreecommitdiffstats
authortcunha <tcunha>2009-07-28 22:12:16 (GMT)
committer tcunha <tcunha>2009-07-28 22:12:16 (GMT)
commitad1947baaf8f2449eeda751dc7e9e88b6c44db41 (patch) (side-by-side diff)
tree7ee5a6194f659307baa7cdbe56e0605c9fe86bbd
parent012e86d5e4fdeae7a2c0dc911059a170902a6e96 (diff)
downloadtmux-old-ad1947baaf8f2449eeda751dc7e9e88b6c44db41.zip
tmux-old-ad1947baaf8f2449eeda751dc7e9e88b6c44db41.tar.gz
tmux-old-ad1947baaf8f2449eeda751dc7e9e88b6c44db41.tar.bz2
Sync OpenBSD patchset 181:
Make all messages sent between the client and server fixed size. This is the first of two changes to make the protocol more resilient and less sensitive to other changes in the code, particularly with commands. The client now packs argv into a buffer and sends it to the server for parsing, rather than doing it itself and sending the parsed command data. As a side-effect this also removes a lot of now-unused command marshalling code. Mixing a server without this change and a client with or vice versa will cause tmux to hang or crash, please ensure that tmux is entirely killed before upgrading.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--client-fn.c16
-rw-r--r--client-msg.c13
-rw-r--r--client.c19
-rw-r--r--cmd-attach-session.c2
-rw-r--r--cmd-bind-key.c23
-rw-r--r--cmd-break-pane.c2
-rw-r--r--cmd-choose-session.c2
-rw-r--r--cmd-choose-window.c2
-rw-r--r--cmd-clear-history.c2
-rw-r--r--cmd-clock-mode.c2
-rw-r--r--cmd-command-prompt.c2
-rw-r--r--cmd-confirm-before.c2
-rw-r--r--cmd-copy-buffer.c25
-rw-r--r--cmd-copy-mode.c2
-rw-r--r--cmd-delete-buffer.c2
-rw-r--r--cmd-detach-client.c2
-rw-r--r--cmd-display-message.c2
-rw-r--r--cmd-down-pane.c2
-rw-r--r--cmd-find-window.c2
-rw-r--r--cmd-generic.c109
-rw-r--r--cmd-has-session.c2
-rw-r--r--cmd-if-shell.c25
-rw-r--r--cmd-kill-pane.c2
-rw-r--r--cmd-kill-server.c2
-rw-r--r--cmd-kill-session.c2
-rw-r--r--cmd-kill-window.c2
-rw-r--r--cmd-last-window.c2
-rw-r--r--cmd-link-window.c2
-rw-r--r--cmd-list-buffers.c2
-rw-r--r--cmd-list-clients.c2
-rw-r--r--cmd-list-commands.c2
-rw-r--r--cmd-list-keys.c2
-rw-r--r--cmd-list-sessions.c2
-rw-r--r--cmd-list-windows.c2
-rw-r--r--cmd-list.c35
-rw-r--r--cmd-load-buffer.c2
-rw-r--r--cmd-lock-server.c2
-rw-r--r--cmd-move-window.c2
-rw-r--r--cmd-new-session.c27
-rw-r--r--cmd-new-window.c27
-rw-r--r--cmd-next-layout.c2
-rw-r--r--cmd-next-window.c2
-rw-r--r--cmd-paste-buffer.c2
-rw-r--r--cmd-previous-layout.c2
-rw-r--r--cmd-previous-window.c2
-rw-r--r--cmd-refresh-client.c2
-rw-r--r--cmd-rename-session.c2
-rw-r--r--cmd-rename-window.c2
-rw-r--r--cmd-resize-pane.c2
-rw-r--r--cmd-respawn-window.c2
-rw-r--r--cmd-rotate-window.c2
-rw-r--r--cmd-save-buffer.c2
-rw-r--r--cmd-scroll-mode.c2
-rw-r--r--cmd-select-layout.c2
-rw-r--r--cmd-select-pane.c2
-rw-r--r--cmd-select-prompt.c2
-rw-r--r--cmd-select-window.c2
-rw-r--r--cmd-send-keys.c26
-rw-r--r--cmd-send-prefix.c2
-rw-r--r--cmd-server-info.c2
-rw-r--r--cmd-set-buffer.c2
-rw-r--r--cmd-set-option.c2
-rw-r--r--cmd-set-password.c23
-rw-r--r--cmd-set-window-option.c2
-rw-r--r--cmd-show-buffer.c2
-rw-r--r--cmd-show-options.c2
-rw-r--r--cmd-show-window-options.c2
-rw-r--r--cmd-source-file.c23
-rw-r--r--cmd-split-window.c25
-rw-r--r--cmd-start-server.c2
-rw-r--r--cmd-suspend-client.c2
-rw-r--r--cmd-swap-pane.c23
-rw-r--r--cmd-swap-window.c2
-rw-r--r--cmd-switch-client.c25
-rw-r--r--cmd-unbind-key.c21
-rw-r--r--cmd-unlink-window.c2
-rw-r--r--cmd-up-pane.c2
-rw-r--r--cmd.c140
-rw-r--r--server-fn.c11
-rw-r--r--server-msg.c93
-rw-r--r--tmux.c126
-rw-r--r--tmux.h58
82 files changed, 253 insertions, 780 deletions
diff --git a/client-fn.c b/client-fn.c
index 6fc590f..c0373bf 100644
--- a/client-fn.c
+++ b/client-fn.c
@@ -74,19 +74,3 @@ client_write_server(
if (buf != NULL && len > 0)
buffer_write(cctx->srv_out, buf, len);
}
-
-void
-client_write_server2(struct client_ctx *cctx,
- enum hdrtype type, void *buf1, size_t len1, void *buf2, size_t len2)
-{
- struct hdr hdr;
-
- hdr.type = type;
- hdr.size = len1 + len2;
- buffer_write(cctx->srv_out, &hdr, sizeof hdr);
-
- if (buf1 != NULL && len1 > 0)
- buffer_write(cctx->srv_out, buf1, len1);
- if (buf2 != NULL && len2 > 0)
- buffer_write(cctx->srv_out, buf2, len2);
-}
diff --git a/client-msg.c b/client-msg.c
index 6321af6..1453ee5 100644
--- a/client-msg.c
+++ b/client-msg.c
@@ -70,16 +70,15 @@ client_msg_dispatch(struct client_ctx *cctx)
int
client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx)
{
- char *errstr;
+ struct msg_print_data data;
- if (hdr->size == SIZE_MAX)
- fatalx("bad MSG_ERROR size");
+ if (hdr->size < sizeof data)
+ fatalx("bad MSG_PRINT size");
+ buffer_read(cctx->srv_in, &data, sizeof data);
- errstr = xmalloc(hdr->size + 1);
- buffer_read(cctx->srv_in, errstr, hdr->size);
- errstr[hdr->size] = '\0';
+ data.msg[(sizeof data.msg) - 1] = '\0';
+ cctx->errstr = xstrdup(data.msg);
- cctx->errstr = errstr;
return (-1);
}
diff --git a/client.c b/client.c
index 961d39d..5976983 100644
--- a/client.c
+++ b/client.c
@@ -44,8 +44,7 @@ client_init(char *path, struct client_ctx *cctx, int cmdflags, int flags)
struct winsize ws;
size_t size;
int mode;
- struct buffer *b;
- char *name;
+ char *name, *term;
#ifdef HAVE_SETPROCTITLE
char rpathbuf[MAXPATHLEN];
#endif
@@ -107,20 +106,24 @@ server_started:
data.flags = flags;
data.sx = ws.ws_col;
data.sy = ws.ws_row;
- *data.tty = '\0';
+
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
*data.cwd = '\0';
+ *data.term = '\0';
+ if ((term = getenv("TERM")) != NULL) {
+ if (strlcpy(data.term,
+ term, sizeof data.term) >= sizeof data.term)
+ *data.term = '\0';
+ }
+
+ *data.tty = '\0';
if ((name = ttyname(STDIN_FILENO)) == NULL)
fatal("ttyname failed");
if (strlcpy(data.tty, name, sizeof data.tty) >= sizeof data.tty)
fatalx("ttyname failed");
- b = buffer_create(BUFSIZ);
- cmd_send_string(b, getenv("TERM"));
- client_write_server2(cctx, MSG_IDENTIFY,
- &data, sizeof data, BUFFER_OUT(b), BUFFER_USED(b));
- buffer_destroy(b);
+ client_write_server(cctx, MSG_IDENTIFY, &data, sizeof data);
}
return (0);
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index ec3e43d..b395af1 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_attach_session_entry = {
cmd_target_init,
cmd_target_parse,
cmd_attach_session_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 7580932..2baf219 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -26,8 +26,6 @@
int cmd_bind_key_parse(struct cmd *, int, char **, char **);
int cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
-void cmd_bind_key_send(struct cmd *, struct buffer *);
-void cmd_bind_key_recv(struct cmd *, struct buffer *);
void cmd_bind_key_free(struct cmd *);
size_t cmd_bind_key_print(struct cmd *, char *, size_t);
@@ -44,8 +42,6 @@ const struct cmd_entry cmd_bind_key_entry = {
NULL,
cmd_bind_key_parse,
cmd_bind_key_exec,
- cmd_bind_key_send,
- cmd_bind_key_recv,
cmd_bind_key_free,
cmd_bind_key_print
};
@@ -114,25 +110,6 @@ cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
}
void
-cmd_bind_key_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_bind_key_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_list_send(data->cmdlist, b);
-}
-
-void
-cmd_bind_key_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_bind_key_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->cmdlist = cmd_list_recv(b);
-}
-
-void
cmd_bind_key_free(struct cmd *self)
{
struct cmd_bind_key_data *data = self->data;
diff --git a/cmd-break-pane.c b/cmd-break-pane.c
index a49c465..fefae11 100644
--- a/cmd-break-pane.c
+++ b/cmd-break-pane.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_break_pane_entry = {
cmd_pane_init,
cmd_pane_parse,
cmd_break_pane_exec,
- cmd_pane_send,
- cmd_pane_recv,
cmd_pane_free,
cmd_pane_print
};
diff --git a/cmd-choose-session.c b/cmd-choose-session.c
index 0ea8c85..5b3ae63 100644
--- a/cmd-choose-session.c
+++ b/cmd-choose-session.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_choose_session_entry = {
cmd_target_init,
cmd_target_parse,
cmd_choose_session_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-choose-window.c b/cmd-choose-window.c
index 6ae2c92..3f44775 100644
--- a/cmd-choose-window.c
+++ b/cmd-choose-window.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_choose_window_entry = {
cmd_target_init,
cmd_target_parse,
cmd_choose_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-clear-history.c b/cmd-clear-history.c
index c602838..207df5d 100644
--- a/cmd-clear-history.c
+++ b/cmd-clear-history.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_clear_history_entry = {
cmd_pane_init,
cmd_pane_parse,
cmd_clear_history_exec,
- cmd_pane_send,
- cmd_pane_recv,
cmd_pane_free,
cmd_pane_print
};
diff --git a/cmd-clock-mode.c b/cmd-clock-mode.c
index f19ccce..84a6d98 100644
--- a/cmd-clock-mode.c
+++ b/cmd-clock-mode.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_clock_mode_entry = {
cmd_target_init,
cmd_target_parse,
cmd_clock_mode_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index ed222fc..5c6305c 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -40,8 +40,6 @@ const struct cmd_entry cmd_command_prompt_entry = {
cmd_command_prompt_init,
cmd_target_parse,
cmd_command_prompt_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c
index b5e43f3..0cb7a35 100644
--- a/cmd-confirm-before.c
+++ b/cmd-confirm-before.c
@@ -38,8 +38,6 @@ const struct cmd_entry cmd_confirm_before_entry = {
cmd_confirm_before_init,
cmd_target_parse,
cmd_confirm_before_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-copy-buffer.c b/cmd-copy-buffer.c
index 533d8b2..6b77a33 100644
--- a/cmd-copy-buffer.c
+++ b/cmd-copy-buffer.c
@@ -26,8 +26,6 @@
int cmd_copy_buffer_parse(struct cmd *, int, char **, char **);
int cmd_copy_buffer_exec(struct cmd *, struct cmd_ctx *);
-void cmd_copy_buffer_send(struct cmd *, struct buffer *);
-void cmd_copy_buffer_recv(struct cmd *, struct buffer *);
void cmd_copy_buffer_free(struct cmd *);
void cmd_copy_buffer_init(struct cmd *, int);
size_t cmd_copy_buffer_print(struct cmd *, char *, size_t);
@@ -46,8 +44,6 @@ const struct cmd_entry cmd_copy_buffer_entry = {
cmd_copy_buffer_init,
cmd_copy_buffer_parse,
cmd_copy_buffer_exec,
- cmd_copy_buffer_send,
- cmd_copy_buffer_recv,
cmd_copy_buffer_free,
cmd_copy_buffer_print
};
@@ -161,27 +157,6 @@ cmd_copy_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_copy_buffer_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_copy_buffer_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->dst_session);
- cmd_send_string(b, data->src_session);
-}
-
-void
-cmd_copy_buffer_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_copy_buffer_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->dst_session = cmd_recv_string(b);
- data->src_session = cmd_recv_string(b);
-}
-
-void
cmd_copy_buffer_free(struct cmd *self)
{
struct cmd_copy_buffer_data *data = self->data;
diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c
index 12e46dd..f7212cb 100644
--- a/cmd-copy-mode.c
+++ b/cmd-copy-mode.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_copy_mode_entry = {
cmd_target_init,
cmd_target_parse,
cmd_copy_mode_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
NULL
};
diff --git a/cmd-delete-buffer.c b/cmd-delete-buffer.c
index e0d6d92..bc1c2c7 100644
--- a/cmd-delete-buffer.c
+++ b/cmd-delete-buffer.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_delete_buffer_entry = {
cmd_buffer_init,
cmd_buffer_parse,
cmd_delete_buffer_exec,
- cmd_buffer_send,
- cmd_buffer_recv,
cmd_buffer_free,
cmd_buffer_print
};
diff --git a/cmd-detach-client.c b/cmd-detach-client.c
index 39b3862..225578c 100644
--- a/cmd-detach-client.c
+++ b/cmd-detach-client.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_detach_client_entry = {
cmd_target_init,
cmd_target_parse,
cmd_detach_client_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-display-message.c b/cmd-display-message.c
index b86cf2e..000f338 100644
--- a/cmd-display-message.c
+++ b/cmd-display-message.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_display_message_entry = {
cmd_target_init,
cmd_target_parse,
cmd_display_message_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-down-pane.c b/cmd-down-pane.c
index f398923..d74c2d3 100644
--- a/cmd-down-pane.c
+++ b/cmd-down-pane.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_down_pane_entry = {
cmd_target_init,
cmd_target_parse,
cmd_down_pane_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-find-window.c b/cmd-find-window.c
index 19af5a9..793505f 100644
--- a/cmd-find-window.c
+++ b/cmd-find-window.c
@@ -38,8 +38,6 @@ const struct cmd_entry cmd_find_window_entry = {
cmd_target_init,
cmd_target_parse,
cmd_find_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-generic.c b/cmd-generic.c
index b0e1a6b..5c6628a 100644
--- a/cmd-generic.c
+++ b/cmd-generic.c
@@ -177,27 +177,6 @@ usage:
}
void
-cmd_target_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_target_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->target);
- cmd_send_string(b, data->arg);
-}
-
-void
-cmd_target_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_target_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->target = cmd_recv_string(b);
- data->arg = cmd_recv_string(b);
-}
-
-void
cmd_target_free(struct cmd *self)
{
struct cmd_target_data *data = self->data;
@@ -279,29 +258,6 @@ usage:
}
void
-cmd_srcdst_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_srcdst_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->src);
- cmd_send_string(b, data->dst);
- cmd_send_string(b, data->arg);
-}
-
-void
-cmd_srcdst_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_srcdst_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->src = cmd_recv_string(b);
- data->dst = cmd_recv_string(b);
- data->arg = cmd_recv_string(b);
-}
-
-void
cmd_srcdst_free(struct cmd *self)
{
struct cmd_srcdst_data *data = self->data;
@@ -395,27 +351,6 @@ error:
}
void
-cmd_buffer_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_buffer_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->target);
- cmd_send_string(b, data->arg);
-}
-
-void
-cmd_buffer_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_buffer_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->target = cmd_recv_string(b);
- data->arg = cmd_recv_string(b);
-}
-
-void
cmd_buffer_free(struct cmd *self)
{
struct cmd_buffer_data *data = self->data;
@@ -501,29 +436,6 @@ usage:
}
void
-cmd_option_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_option_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->target);
- cmd_send_string(b, data->option);
- cmd_send_string(b, data->value);
-}
-
-void
-cmd_option_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_option_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->target = cmd_recv_string(b);
- data->option = cmd_recv_string(b);
- data->value = cmd_recv_string(b);
-}
-
-void
cmd_option_free(struct cmd *self)
{
struct cmd_option_data *data = self->data;
@@ -618,27 +530,6 @@ error:
}
void
-cmd_pane_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_pane_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->target);
- cmd_send_string(b, data->arg);
-}
-
-void
-cmd_pane_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_pane_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->target = cmd_recv_string(b);
- data->arg = cmd_recv_string(b);
-}
-
-void
cmd_pane_free(struct cmd *self)
{
struct cmd_pane_data *data = self->data;
diff --git a/cmd-has-session.c b/cmd-has-session.c
index a428c42..3b3d70d 100644
--- a/cmd-has-session.c
+++ b/cmd-has-session.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_has_session_entry = {
cmd_target_init,
cmd_target_parse,
cmd_has_session_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index 0a53830..8b3ab0a 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -30,8 +30,6 @@
int cmd_if_shell_parse(struct cmd *, int, char **, char **);
int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
-void cmd_if_shell_send(struct cmd *, struct buffer *);
-void cmd_if_shell_recv(struct cmd *, struct buffer *);
void cmd_if_shell_free(struct cmd *);
void cmd_if_shell_init(struct cmd *, int);
size_t cmd_if_shell_print(struct cmd *, char *, size_t);
@@ -48,8 +46,6 @@ const struct cmd_entry cmd_if_shell_entry = {
cmd_if_shell_init,
cmd_if_shell_parse,
cmd_if_shell_exec,
- cmd_if_shell_send,
- cmd_if_shell_recv,
cmd_if_shell_free,
cmd_if_shell_print
};
@@ -127,27 +123,6 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_if_shell_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_if_shell_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->cmd);
- cmd_send_string(b, data->sh_cmd);
-}
-
-void
-cmd_if_shell_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_if_shell_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->cmd = cmd_recv_string(b);
- data->sh_cmd = cmd_recv_string(b);
-}
-
-void
cmd_if_shell_free(struct cmd *self)
{
struct cmd_if_shell_data *data = self->data;
diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c
index 0e40f33..2632506 100644
--- a/cmd-kill-pane.c
+++ b/cmd-kill-pane.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_kill_pane_entry = {
cmd_pane_init,
cmd_pane_parse,
cmd_kill_pane_exec,
- cmd_pane_send,
- cmd_pane_recv,
cmd_pane_free,
cmd_pane_print
};
diff --git a/cmd-kill-server.c b/cmd-kill-server.c
index a93b242..9bd7f38 100644
--- a/cmd-kill-server.c
+++ b/cmd-kill-server.c
@@ -37,8 +37,6 @@ const struct cmd_entry cmd_kill_server_entry = {
NULL,
cmd_kill_server_exec,
NULL,
- NULL,
- NULL,
NULL
};
diff --git a/cmd-kill-session.c b/cmd-kill-session.c
index 74b409a..9461441 100644
--- a/cmd-kill-session.c
+++ b/cmd-kill-session.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_kill_session_entry = {
cmd_target_init,
cmd_target_parse,
cmd_kill_session_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index a7ffba1..d8647f9 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_kill_window_entry = {
cmd_target_init,
cmd_target_parse,
cmd_kill_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-last-window.c b/cmd-last-window.c
index 0f6187c..bdfa5f9 100644
--- a/cmd-last-window.c
+++ b/cmd-last-window.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_last_window_entry = {
cmd_target_init,
cmd_target_parse,
cmd_last_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-link-window.c b/cmd-link-window.c
index 0a84683..56f7132 100644
--- a/cmd-link-window.c
+++ b/cmd-link-window.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_link_window_entry = {
cmd_srcdst_init,
cmd_srcdst_parse,
cmd_link_window_exec,
- cmd_srcdst_send,
- cmd_srcdst_recv,
cmd_srcdst_free,
cmd_srcdst_print
};
diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c
index b300cd4..6801b95 100644
--- a/cmd-list-buffers.c
+++ b/cmd-list-buffers.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_list_buffers_entry = {
cmd_target_init,
cmd_target_parse,
cmd_list_buffers_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-list-clients.c b/cmd-list-clients.c
index 05ecfa9..3b89b3b 100644
--- a/cmd-list-clients.c
+++ b/cmd-list-clients.c
@@ -37,8 +37,6 @@ const struct cmd_entry cmd_list_clients_entry = {
NULL,
cmd_list_clients_exec,
NULL,
- NULL,
- NULL,
NULL
};
diff --git a/cmd-list-commands.c b/cmd-list-commands.c
index a58219a..103eeb7 100644
--- a/cmd-list-commands.c
+++ b/cmd-list-commands.c
@@ -34,8 +34,6 @@ const struct cmd_entry cmd_list_commands_entry = {
NULL,
cmd_list_commands_exec,
NULL,
- NULL,
- NULL,
NULL
};
diff --git a/cmd-list-keys.c b/cmd-list-keys.c
index 40f67c6..d11dc1f 100644
--- a/cmd-list-keys.c
+++ b/cmd-list-keys.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_list_keys_entry = {
NULL,
cmd_list_keys_exec,
NULL,
- NULL,
- NULL,
NULL
};
diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c
index 392a2ef..fcb5e61 100644
--- a/cmd-list-sessions.c
+++ b/cmd-list-sessions.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_list_sessions_entry = {
NULL,
cmd_list_sessions_exec,
NULL,
- NULL,
- NULL,
NULL
};
diff --git a/cmd-list-windows.c b/cmd-list-windows.c
index a0a060d..5c1564b 100644
--- a/cmd-list-windows.c
+++ b/cmd-list-windows.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_list_windows_entry = {
cmd_target_init,
cmd_target_parse,
cmd_list_windows_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-list.c b/cmd-list.c
index 7620c53..733c30b 100644
--- a/cmd-list.c
+++ b/cmd-list.c
@@ -87,41 +87,6 @@ cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
}
void
-cmd_list_send(struct cmd_list *cmdlist, struct buffer *b)
-{
- struct cmd *cmd;
- u_int n;
-
- n = 0;
- TAILQ_FOREACH(cmd, cmdlist, qentry)
- n++;
-
- buffer_write(b, &n, sizeof n);
- TAILQ_FOREACH(cmd, cmdlist, qentry)
- cmd_send(cmd, b);
-}
-
-struct cmd_list *
-cmd_list_recv(struct buffer *b)
-{
- struct cmd_list *cmdlist;
- struct cmd *cmd;
- u_int n;
-
- buffer_read(b, &n, sizeof n);
-
- cmdlist = xmalloc(sizeof *cmdlist);
- TAILQ_INIT(cmdlist);
-
- while (n-- > 0) {
- cmd = cmd_recv(b);
- TAILQ_INSERT_TAIL(cmdlist, cmd, qentry);
- }
-
- return (cmdlist);
-}
-
-void
cmd_list_free(struct cmd_list *cmdlist)
{
struct cmd *cmd;
diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c
index 173f511..6d500f4 100644
--- a/cmd-load-buffer.c
+++ b/cmd-load-buffer.c
@@ -39,8 +39,6 @@ const struct cmd_entry cmd_load_buffer_entry = {
cmd_buffer_init,
cmd_buffer_parse,
cmd_load_buffer_exec,
- cmd_buffer_send,
- cmd_buffer_recv,
cmd_buffer_free,
cmd_buffer_print
};
diff --git a/cmd-lock-server.c b/cmd-lock-server.c
index 288e063..a9f3605 100644
--- a/cmd-lock-server.c
+++ b/cmd-lock-server.c
@@ -39,8 +39,6 @@ const struct cmd_entry cmd_lock_server_entry = {
cmd_lock_server_exec,
NULL,
NULL,
- NULL,
- NULL,
};
int
diff --git a/cmd-move-window.c b/cmd-move-window.c
index dcaf200..9ff77cd 100644
--- a/cmd-move-window.c
+++ b/cmd-move-window.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_move_window_entry = {
cmd_srcdst_init,
cmd_srcdst_parse,
cmd_move_window_exec,
- cmd_srcdst_send,
- cmd_srcdst_recv,
cmd_srcdst_free,
cmd_srcdst_print
};
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 812e3bb..ca6925c 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -26,8 +26,6 @@
int cmd_new_session_parse(struct cmd *, int, char **, char **);
int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
-void cmd_new_session_send(struct cmd *, struct buffer *);
-void cmd_new_session_recv(struct cmd *, struct buffer *);
void cmd_new_session_free(struct cmd *);
void cmd_new_session_init(struct cmd *, int);
size_t cmd_new_session_print(struct cmd *, char *, size_t);
@@ -46,8 +44,6 @@ const struct cmd_entry cmd_new_session_entry = {
cmd_new_session_init,
cmd_new_session_parse,
cmd_new_session_exec,
- cmd_new_session_send,
- cmd_new_session_recv,
cmd_new_session_free,
cmd_new_session_print
};
@@ -229,29 +225,6 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_new_session_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_new_session_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->newname);
- cmd_send_string(b, data->winname);
- cmd_send_string(b, data->cmd);
-}
-
-void
-cmd_new_session_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_new_session_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->newname = cmd_recv_string(b);
- data->winname = cmd_recv_string(b);
- data->cmd = cmd_recv_string(b);
-}
-
-void
cmd_new_session_free(struct cmd *self)
{
struct cmd_new_session_data *data = self->data;
diff --git a/cmd-new-window.c b/cmd-new-window.c
index aacb32c..1fd9739 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -28,8 +28,6 @@
int cmd_new_window_parse(struct cmd *, int, char **, char **);
int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
-void cmd_new_window_send(struct cmd *, struct buffer *);
-void cmd_new_window_recv(struct cmd *, struct buffer *);
void cmd_new_window_free(struct cmd *);
void cmd_new_window_init(struct cmd *, int);
size_t cmd_new_window_print(struct cmd *, char *, size_t);
@@ -49,8 +47,6 @@ const struct cmd_entry cmd_new_window_entry = {
cmd_new_window_init,
cmd_new_window_parse,
cmd_new_window_exec,
- cmd_new_window_send,
- cmd_new_window_recv,
cmd_new_window_free,
cmd_new_window_print
};
@@ -174,29 +170,6 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_new_window_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_new_window_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->target);
- cmd_send_string(b, data->name);
- cmd_send_string(b, data->cmd);
-}
-
-void
-cmd_new_window_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_new_window_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->target = cmd_recv_string(b);
- data->name = cmd_recv_string(b);
- data->cmd = cmd_recv_string(b);
-}
-
-void
cmd_new_window_free(struct cmd *self)
{
struct cmd_new_window_data *data = self->data;
diff --git a/cmd-next-layout.c b/cmd-next-layout.c
index a9fdd88..a8ba8d0 100644
--- a/cmd-next-layout.c
+++ b/cmd-next-layout.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_next_layout_entry = {
cmd_target_init,
cmd_target_parse,
cmd_next_layout_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-next-window.c b/cmd-next-window.c
index 81324f7..ef473bc 100644
--- a/cmd-next-window.c
+++ b/cmd-next-window.c
@@ -34,8 +34,6 @@ const struct cmd_entry cmd_next_window_entry = {
cmd_next_window_init,
cmd_target_parse,
cmd_next_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c
index 93647ed..a346b06 100644
--- a/cmd-paste-buffer.c
+++ b/cmd-paste-buffer.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_paste_buffer_entry = {
cmd_buffer_init,
cmd_buffer_parse,
cmd_paste_buffer_exec,
- cmd_buffer_send,
- cmd_buffer_recv,
cmd_buffer_free,
cmd_buffer_print
};
diff --git a/cmd-previous-layout.c b/cmd-previous-layout.c
index 35df367..b94329c 100644
--- a/cmd-previous-layout.c
+++ b/cmd-previous-layout.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_previous_layout_entry = {
cmd_target_init,
cmd_target_parse,
cmd_previous_layout_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-previous-window.c b/cmd-previous-window.c
index 42b7ed9..82950e9 100644
--- a/cmd-previous-window.c
+++ b/cmd-previous-window.c
@@ -34,8 +34,6 @@ const struct cmd_entry cmd_previous_window_entry = {
cmd_previous_window_init,
cmd_target_parse,
cmd_previous_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c
index 47c3f05..2eb936a 100644
--- a/cmd-refresh-client.c
+++ b/cmd-refresh-client.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_refresh_client_entry = {
cmd_target_init,
cmd_target_parse,
cmd_refresh_client_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-rename-session.c b/cmd-rename-session.c
index 7073ba1..f811e5c 100644
--- a/cmd-rename-session.c
+++ b/cmd-rename-session.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_rename_session_entry = {
cmd_target_init,
cmd_target_parse,
cmd_rename_session_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-rename-window.c b/cmd-rename-window.c
index 66aa74c..c34ec7a 100644
--- a/cmd-rename-window.c
+++ b/cmd-rename-window.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_rename_window_entry = {
cmd_target_init,
cmd_target_parse,
cmd_rename_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c
index e840326..9c0fc05 100644
--- a/cmd-resize-pane.c
+++ b/cmd-resize-pane.c
@@ -37,8 +37,6 @@ const struct cmd_entry cmd_resize_pane_entry = {
cmd_resize_pane_init,
cmd_pane_parse,
cmd_resize_pane_exec,
- cmd_pane_send,
- cmd_pane_recv,
cmd_pane_free,
cmd_pane_print
};
diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c
index 7deb233..bc966ef 100644
--- a/cmd-respawn-window.c
+++ b/cmd-respawn-window.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_respawn_window_entry = {
cmd_target_init,
cmd_target_parse,
cmd_respawn_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-rotate-window.c b/cmd-rotate-window.c
index 1761abb..87c6f83 100644
--- a/cmd-rotate-window.c
+++ b/cmd-rotate-window.c
@@ -34,8 +34,6 @@ const struct cmd_entry cmd_rotate_window_entry = {
cmd_rotate_window_init,
cmd_target_parse,
cmd_rotate_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c
index 54ad6a1..870d49d 100644
--- a/cmd-save-buffer.c
+++ b/cmd-save-buffer.c
@@ -37,8 +37,6 @@ const struct cmd_entry cmd_save_buffer_entry = {
cmd_buffer_init,
cmd_buffer_parse,
cmd_save_buffer_exec,
- cmd_buffer_send,
- cmd_buffer_recv,
cmd_buffer_free,
cmd_buffer_print
};
diff --git a/cmd-scroll-mode.c b/cmd-scroll-mode.c
index 74cb14a..31f29bb 100644
--- a/cmd-scroll-mode.c
+++ b/cmd-scroll-mode.c
@@ -34,8 +34,6 @@ const struct cmd_entry cmd_scroll_mode_entry = {
cmd_scroll_mode_init,
cmd_target_parse,
cmd_scroll_mode_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-select-layout.c b/cmd-select-layout.c
index 2e0369d..d17a144 100644
--- a/cmd-select-layout.c
+++ b/cmd-select-layout.c
@@ -34,8 +34,6 @@ const struct cmd_entry cmd_select_layout_entry = {
cmd_select_layout_init,
cmd_target_parse,
cmd_select_layout_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-select-pane.c b/cmd-select-pane.c
index 206491c..f04eb33 100644
--- a/cmd-select-pane.c
+++ b/cmd-select-pane.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_select_pane_entry = {
cmd_pane_init,
cmd_pane_parse,
cmd_select_pane_exec,
- cmd_pane_send,
- cmd_pane_recv,
cmd_pane_free,
cmd_pane_print
};
diff --git a/cmd-select-prompt.c b/cmd-select-prompt.c
index 422d8e8..d774855 100644
--- a/cmd-select-prompt.c
+++ b/cmd-select-prompt.c
@@ -37,8 +37,6 @@ const struct cmd_entry cmd_select_prompt_entry = {
cmd_target_init,
cmd_target_parse,
cmd_select_prompt_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-select-window.c b/cmd-select-window.c
index 4cb533f..0dfb5f0 100644
--- a/cmd-select-window.c
+++ b/cmd-select-window.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_select_window_entry = {
cmd_select_window_init,
cmd_target_parse,
cmd_select_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-send-keys.c b/cmd-send-keys.c
index 3c7be60..1e46cbc 100644
--- a/cmd-send-keys.c
+++ b/cmd-send-keys.c
@@ -28,8 +28,6 @@
int cmd_send_keys_parse(struct cmd *, int, char **, char **);
int cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
-void cmd_send_keys_send(struct cmd *, struct buffer *);
-void cmd_send_keys_recv(struct cmd *, struct buffer *);
void cmd_send_keys_free(struct cmd *);
size_t cmd_send_keys_print(struct cmd *, char *, size_t);
@@ -47,8 +45,6 @@ const struct cmd_entry cmd_send_keys_entry = {
NULL,
cmd_send_keys_parse,
cmd_send_keys_exec,
- cmd_send_keys_send,
- cmd_send_keys_recv,
cmd_send_keys_free,
cmd_send_keys_print
};
@@ -128,28 +124,6 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_send_keys_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_send_keys_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->target);
- buffer_write(b, data->keys, data->nkeys * sizeof *data->keys);
-}
-
-void
-cmd_send_keys_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_send_keys_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->target = cmd_recv_string(b);
- data->keys = xcalloc(data->nkeys, sizeof *data->keys);
- buffer_read(b, data->keys, data->nkeys * sizeof *data->keys);
-}
-
-void
cmd_send_keys_free(struct cmd *self)
{
struct cmd_send_keys_data *data = self->data;
diff --git a/cmd-send-prefix.c b/cmd-send-prefix.c
index 1d3d85f..bad623a 100644
--- a/cmd-send-prefix.c
+++ b/cmd-send-prefix.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_send_prefix_entry = {
cmd_target_init,
cmd_target_parse,
cmd_send_prefix_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-server-info.c b/cmd-server-info.c
index 3347006..f8def3a 100644
--- a/cmd-server-info.c
+++ b/cmd-server-info.c
@@ -40,8 +40,6 @@ const struct cmd_entry cmd_server_info_entry = {
NULL,
cmd_server_info_exec,
NULL,
- NULL,
- NULL,
NULL
};
diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c
index 974125b..608682a 100644
--- a/cmd-set-buffer.c
+++ b/cmd-set-buffer.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_set_buffer_entry = {
cmd_buffer_init,
cmd_buffer_parse,
cmd_set_buffer_exec,
- cmd_buffer_send,
- cmd_buffer_recv,
cmd_buffer_free,
cmd_buffer_print
};
diff --git a/cmd-set-option.c b/cmd-set-option.c
index a6e8f8f..f54140c 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_set_option_entry = {
NULL,
cmd_option_parse,
cmd_set_option_exec,
- cmd_option_send,
- cmd_option_recv,
cmd_option_free,
cmd_option_print
};
diff --git a/cmd-set-password.c b/cmd-set-password.c
index 95f82c4..ef66624 100644
--- a/cmd-set-password.c
+++ b/cmd-set-password.c
@@ -29,8 +29,6 @@
int cmd_set_password_parse(struct cmd *, int, char **, char **);
int cmd_set_password_exec(struct cmd *, struct cmd_ctx *);
-void cmd_set_password_send(struct cmd *, struct buffer *);
-void cmd_set_password_recv(struct cmd *, struct buffer *);
void cmd_set_password_free(struct cmd *);
void cmd_set_password_init(struct cmd *, int);
size_t cmd_set_password_print(struct cmd *, char *, size_t);
@@ -47,8 +45,6 @@ const struct cmd_entry cmd_set_password_entry = {
cmd_set_password_init,
cmd_set_password_parse,
cmd_set_password_exec,
- cmd_set_password_send,
- cmd_set_password_recv,
cmd_set_password_free,
cmd_set_password_print
};
@@ -123,25 +119,6 @@ cmd_set_password_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_set_password_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_set_password_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->password);
-}
-
-void
-cmd_set_password_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_set_password_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->password = cmd_recv_string(b);
-}
-
-void
cmd_set_password_free(struct cmd *self)
{
struct cmd_set_password_data *data = self->data;
diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c
index c3e993d..036758e 100644
--- a/cmd-set-window-option.c
+++ b/cmd-set-window-option.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_set_window_option_entry = {
NULL,
cmd_option_parse,
cmd_set_window_option_exec,
- cmd_option_send,
- cmd_option_recv,
cmd_option_free,
cmd_option_print
};
diff --git a/cmd-show-buffer.c b/cmd-show-buffer.c
index 70cf20a..4467513 100644
--- a/cmd-show-buffer.c
+++ b/cmd-show-buffer.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_show_buffer_entry = {
cmd_buffer_init,
cmd_buffer_parse,
cmd_show_buffer_exec,
- cmd_buffer_send,
- cmd_buffer_recv,
cmd_buffer_free,
cmd_buffer_print
};
diff --git a/cmd-show-options.c b/cmd-show-options.c
index f8229b8..85da590 100644
--- a/cmd-show-options.c
+++ b/cmd-show-options.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_show_options_entry = {
cmd_target_init,
cmd_target_parse,
cmd_show_options_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-show-window-options.c b/cmd-show-window-options.c
index ff4a0cd..498f05f 100644
--- a/cmd-show-window-options.c
+++ b/cmd-show-window-options.c
@@ -36,8 +36,6 @@ const struct cmd_entry cmd_show_window_options_entry = {
cmd_target_init,
cmd_target_parse,
cmd_show_window_options_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-source-file.c b/cmd-source-file.c
index b90507f..da608ed 100644
--- a/cmd-source-file.c
+++ b/cmd-source-file.c
@@ -26,8 +26,6 @@
int cmd_source_file_parse(struct cmd *, int, char **, char **);
int cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
-void cmd_source_file_send(struct cmd *, struct buffer *);
-void cmd_source_file_recv(struct cmd *, struct buffer *);
void cmd_source_file_free(struct cmd *);
void cmd_source_file_init(struct cmd *, int);
size_t cmd_source_file_print(struct cmd *, char *, size_t);
@@ -43,8 +41,6 @@ const struct cmd_entry cmd_source_file_entry = {
cmd_source_file_init,
cmd_source_file_parse,
cmd_source_file_exec,
- cmd_source_file_send,
- cmd_source_file_recv,
cmd_source_file_free,
cmd_source_file_print
};
@@ -104,25 +100,6 @@ cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_source_file_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_source_file_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->path);
-}
-
-void
-cmd_source_file_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_source_file_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->path = cmd_recv_string(b);
-}
-
-void
cmd_source_file_free(struct cmd *self)
{
struct cmd_source_file_data *data = self->data;
diff --git a/cmd-split-window.c b/cmd-split-window.c
index 02c20f8..5b35bfe 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -29,8 +29,6 @@
int cmd_split_window_parse(struct cmd *, int, char **, char **);
int cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
-void cmd_split_window_send(struct cmd *, struct buffer *);
-void cmd_split_window_recv(struct cmd *, struct buffer *);
void cmd_split_window_free(struct cmd *);
void cmd_split_window_init(struct cmd *, int);
size_t cmd_split_window_print(struct cmd *, char *, size_t);
@@ -51,8 +49,6 @@ const struct cmd_entry cmd_split_window_entry = {
cmd_split_window_init,
cmd_split_window_parse,
cmd_split_window_exec,
- cmd_split_window_send,
- cmd_split_window_recv,
cmd_split_window_free,
cmd_split_window_print
};
@@ -212,27 +208,6 @@ error:
}
void
-cmd_split_window_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_split_window_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->target);
- cmd_send_string(b, data->cmd);
-}
-
-void
-cmd_split_window_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_split_window_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->target = cmd_recv_string(b);
- data->cmd = cmd_recv_string(b);
-}
-
-void
cmd_split_window_free(struct cmd *self)
{
struct cmd_split_window_data *data = self->data;
diff --git a/cmd-start-server.c b/cmd-start-server.c
index 932582d..d58656a 100644
--- a/cmd-start-server.c
+++ b/cmd-start-server.c
@@ -34,8 +34,6 @@ const struct cmd_entry cmd_start_server_entry = {
NULL,
cmd_start_server_exec,
NULL,
- NULL,
- NULL,
NULL
};
diff --git a/cmd-suspend-client.c b/cmd-suspend-client.c
index f0146b7..0e0c186 100644
--- a/cmd-suspend-client.c
+++ b/cmd-suspend-client.c
@@ -41,8 +41,6 @@ const struct cmd_entry cmd_suspend_client_entry = {
cmd_target_init,
cmd_target_parse,
cmd_suspend_client_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c
index 2d1e6e4..f149099 100644
--- a/cmd-swap-pane.c
+++ b/cmd-swap-pane.c
@@ -28,8 +28,6 @@
int cmd_swap_pane_parse(struct cmd *, int, char **, char **);
int cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *);
-void cmd_swap_pane_send(struct cmd *, struct buffer *);
-void cmd_swap_pane_recv(struct cmd *, struct buffer *);
void cmd_swap_pane_free(struct cmd *);
void cmd_swap_pane_init(struct cmd *, int);
size_t cmd_swap_pane_print(struct cmd *, char *, size_t);
@@ -50,8 +48,6 @@ const struct cmd_entry cmd_swap_pane_entry = {
cmd_swap_pane_init,
cmd_swap_pane_parse,
cmd_swap_pane_exec,
- cmd_swap_pane_send,
- cmd_swap_pane_recv,
cmd_swap_pane_free,
cmd_swap_pane_print
};
@@ -235,25 +231,6 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_swap_pane_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_swap_pane_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->target);
-}
-
-void
-cmd_swap_pane_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_swap_pane_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->target = cmd_recv_string(b);
-}
-
-void
cmd_swap_pane_free(struct cmd *self)
{
struct cmd_swap_pane_data *data = self->data;
diff --git a/cmd-swap-window.c b/cmd-swap-window.c
index 8437c32..07de23c 100644
--- a/cmd-swap-window.c
+++ b/cmd-swap-window.c
@@ -35,8 +35,6 @@ const struct cmd_entry cmd_swap_window_entry = {
cmd_srcdst_init,
cmd_srcdst_parse,
cmd_swap_window_exec,
- cmd_srcdst_send,
- cmd_srcdst_recv,
cmd_srcdst_free,
cmd_srcdst_print
};
diff --git a/cmd-switch-client.c b/cmd-switch-client.c
index 6f25209..16ab957 100644
--- a/cmd-switch-client.c
+++ b/cmd-switch-client.c
@@ -29,8 +29,6 @@
int cmd_switch_client_parse(struct cmd *, int, char **, char **);
int cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
-void cmd_switch_client_send(struct cmd *, struct buffer *);
-void cmd_switch_client_recv(struct cmd *, struct buffer *);
void cmd_switch_client_free(struct cmd *);
size_t cmd_switch_client_print(struct cmd *, char *, size_t);
@@ -46,8 +44,6 @@ const struct cmd_entry cmd_switch_client_entry = {
NULL,
cmd_switch_client_parse,
cmd_switch_client_exec,
- cmd_switch_client_send,
- cmd_switch_client_recv,
cmd_switch_client_free,
cmd_switch_client_print
};
@@ -112,27 +108,6 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
}
void
-cmd_switch_client_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_switch_client_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->name);
- cmd_send_string(b, data->target);
-}
-
-void
-cmd_switch_client_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_switch_client_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
- data->name = cmd_recv_string(b);
- data->target = cmd_recv_string(b);
-}
-
-void
cmd_switch_client_free(struct cmd *self)
{
struct cmd_switch_client_data *data = self->data;
diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c
index 6f87dfa..b4d61d2 100644
--- a/cmd-unbind-key.c
+++ b/cmd-unbind-key.c
@@ -26,8 +26,6 @@
int cmd_unbind_key_parse(struct cmd *, int, char **, char **);
int cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
-void cmd_unbind_key_send(struct cmd *, struct buffer *);
-void cmd_unbind_key_recv(struct cmd *, struct buffer *);
void cmd_unbind_key_free(struct cmd *);
struct cmd_unbind_key_data {
@@ -41,8 +39,6 @@ const struct cmd_entry cmd_unbind_key_entry = {
NULL,
cmd_unbind_key_parse,
cmd_unbind_key_exec,
- cmd_unbind_key_send,
- cmd_unbind_key_recv,
cmd_unbind_key_free,
NULL
};
@@ -100,23 +96,6 @@ cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
}
void
-cmd_unbind_key_send(struct cmd *self, struct buffer *b)
-{
- struct cmd_unbind_key_data *data = self->data;
-
- buffer_write(b, data, sizeof *data);
-}
-
-void
-cmd_unbind_key_recv(struct cmd *self, struct buffer *b)
-{
- struct cmd_unbind_key_data *data;
-
- self->data = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
-}
-
-void
cmd_unbind_key_free(struct cmd *self)
{
struct cmd_unbind_key_data *data = self->data;
diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c
index d7067f7..68998fe 100644
--- a/cmd-unlink-window.c
+++ b/cmd-unlink-window.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_unlink_window_entry = {
cmd_target_init,
cmd_target_parse,
cmd_unlink_window_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd-up-pane.c b/cmd-up-pane.c
index e71e606..96e90a0 100644
--- a/cmd-up-pane.c
+++ b/cmd-up-pane.c
@@ -33,8 +33,6 @@ const struct cmd_entry cmd_up_pane_entry = {
cmd_target_init,
cmd_target_parse,
cmd_up_pane_exec,
- cmd_target_send,
- cmd_target_recv,
cmd_target_free,
cmd_target_print
};
diff --git a/cmd.c b/cmd.c
index 2753299..60cfb69 100644
--- a/cmd.c
+++ b/cmd.c
@@ -108,6 +108,64 @@ struct session *cmd_lookup_session(const char *, int *);
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
int cmd_lookup_index(struct session *, const char *, int *);
+int
+cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
+{
+ size_t arglen;
+ int i;
+
+ *buf = '\0';
+ for (i = 0; i < argc; i++) {
+ if (strlcpy(buf, argv[i], len) >= len)
+ return (-1);
+ arglen = strlen(argv[i]) + 1;
+ buf += arglen;
+ len -= arglen;
+ }
+
+ return (0);
+}
+
+int
+cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
+{
+ int i;
+ size_t arglen;
+
+ if (argc == 0)
+ return (0);
+ *argv = xcalloc(argc, sizeof **argv);
+
+ buf[len - 1] = '\0';
+ for (i = 0; i < argc; i++) {
+ if (len == 0) {
+ cmd_free_argv(argc, *argv);
+ return (-1);
+ }
+
+ arglen = strlen(buf) + 1;
+ (*argv)[i] = xstrdup(buf);
+ buf += arglen;
+ len -= arglen;
+ }
+
+ return (0);
+}
+
+void
+cmd_free_argv(int argc, char **argv)
+{
+ int i;
+
+ if (argc == 0)
+ return;
+ for (i = 0; i < argc; i++) {
+ if (argv[i] != NULL)
+ xfree(argv[i]);
+ }
+ xfree(argv);
+}
+
struct cmd *
cmd_parse(int argc, char **argv, char **cause)
{
@@ -204,53 +262,6 @@ cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx)
}
void
-cmd_send(struct cmd *cmd, struct buffer *b)
-{
- const struct cmd_entry **entryp;
- u_int n;
-
- n = 0;
- for (entryp = cmd_table; *entryp != NULL; entryp++) {
- if (*entryp == cmd->entry)
- break;
- n++;
- }
- if (*entryp == NULL)
- fatalx("command not found");
-
- buffer_write(b, &n, sizeof n);
-
- if (cmd->entry->send != NULL)
- cmd->entry->send(cmd, b);
-}
-
-struct cmd *
-cmd_recv(struct buffer *b)
-{
- const struct cmd_entry **entryp;
- struct cmd *cmd;
- u_int m, n;
-
- buffer_read(b, &m, sizeof m);
-
- n = 0;
- for (entryp = cmd_table; *entryp != NULL; entryp++) {
- if (n == m)
- break;
- n++;
- }
- if (*entryp == NULL)
- fatalx("command not found");
-
- cmd = xmalloc(sizeof *cmd);
- cmd->entry = *entryp;
-
- if (cmd->entry->recv != NULL)
- cmd->entry->recv(cmd, b);
- return (cmd);
-}
-
-void
cmd_free(struct cmd *cmd)
{
if (cmd->data != NULL && cmd->entry->free != NULL)
@@ -267,41 +278,6 @@ cmd_print(struct cmd *cmd, char *buf, size_t len)
return (cmd->entry->print(cmd, buf, len));
}
-void
-cmd_send_string(struct buffer *b, const char *s)
-{
- size_t n;
-
- if (s == NULL) {
- n = 0;
- buffer_write(b, &n, sizeof n);
- return;
- }
-
- n = strlen(s) + 1;
- buffer_write(b, &n, sizeof n);
-
- buffer_write(b, s, n);
-}
-
-char *
-cmd_recv_string(struct buffer *b)
-{
- char *s;
- size_t n;
-
- buffer_read(b, &n, sizeof n);
-
- if (n == 0)
- return (NULL);
-
- s = xmalloc(n);
- buffer_read(b, s, n);
- s[n - 1] = '\0';
-
- return (s);
-}
-
/*
* Figure out the current session. Use: 1) the current session, if the command
* context has one; 2) the session specified in the TMUX variable from the
diff --git a/server-fn.c b/server-fn.c
index e179f71..1dbe8fa 100644
--- a/server-fn.c
+++ b/server-fn.c
@@ -48,6 +48,15 @@ server_fill_environ(struct session *s)
}
void
+server_write_error(struct client *c, const char *msg)
+{
+ struct msg_print_data printdata;
+
+ strlcpy(printdata.msg, msg, sizeof printdata.msg);
+ server_write_client(c, MSG_ERROR, &printdata, sizeof printdata);
+}
+
+void
server_write_client(
struct client *c, enum hdrtype type, const void *buf, size_t len)
{
@@ -220,7 +229,7 @@ wrong:
password_failures++;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->prompt_buffer == NULL)
+ if (c == NULL || c->prompt_buffer == NULL)
continue;
*c->prompt_buffer = '\0';
diff --git a/server-msg.c b/server-msg.c
index 5d215d4..b7621b4 100644
--- a/server-msg.c
+++ b/server-msg.c
@@ -83,46 +83,43 @@ server_msg_dispatch(struct client *c)
void printflike2
server_msg_fn_command_error(struct cmd_ctx *ctx, const char *fmt, ...)
{
- va_list ap;
- char *msg;
+ struct msg_print_data data;
+ va_list ap;
va_start(ap, fmt);
- xvasprintf(&msg, fmt, ap);
+ xvsnprintf(data.msg, sizeof data.msg, fmt, ap);
va_end(ap);
- server_write_client(ctx->cmdclient, MSG_ERROR, msg, strlen(msg));
- xfree(msg);
+ server_write_client(ctx->cmdclient, MSG_ERROR, &data, sizeof data);
}
void printflike2
server_msg_fn_command_print(struct cmd_ctx *ctx, const char *fmt, ...)
{
- va_list ap;
- char *msg;
+ struct msg_print_data data;
+ va_list ap;
va_start(ap, fmt);
- xvasprintf(&msg, fmt, ap);
+ xvsnprintf(data.msg, sizeof data.msg, fmt, ap);
va_end(ap);
- server_write_client(ctx->cmdclient, MSG_PRINT, msg, strlen(msg));
- xfree(msg);
+ server_write_client(ctx->cmdclient, MSG_PRINT, &data, sizeof data);
}
void printflike2
server_msg_fn_command_info(struct cmd_ctx *ctx, const char *fmt, ...)
{
- va_list ap;
- char *msg;
+ struct msg_print_data data;
+ va_list ap;
if (be_quiet)
return;
va_start(ap, fmt);
- xvasprintf(&msg, fmt, ap);
+ xvsnprintf(data.msg, sizeof data.msg, fmt, ap);
va_end(ap);
- server_write_client(ctx->cmdclient, MSG_PRINT, msg, strlen(msg));
- xfree(msg);
+ server_write_client(ctx->cmdclient, MSG_PRINT, &data, sizeof data);
}
void
@@ -130,14 +127,15 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
{
struct msg_command_data data;
struct cmd_ctx ctx;
- struct cmd_list *cmdlist;
+ struct cmd_list *cmdlist = NULL;
struct cmd *cmd;
+ int argc;
+ char **argv, *cause;
if (hdr->size < sizeof data)
fatalx("bad MSG_COMMAND size");
buffer_read(c->in, &data, sizeof data);
- cmdlist = cmd_list_recv(c->in);
server_activity = time(NULL);
ctx.error = server_msg_fn_command_error;
@@ -150,15 +148,33 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
ctx.cmdclient = c;
+ argc = data.argc;
+ data.argv[(sizeof data.argv) - 1] = '\0';
+ if (cmd_unpack_argv(data.argv, sizeof data.argv, argc, &argv) != 0) {
+ server_msg_fn_command_error(&ctx, "command too long");
+ goto error;
+ }
+
+ if (argc == 0) {
+ argc = 1;
+ argv = xcalloc(1, sizeof *argv);
+ *argv = xstrdup("new-session");
+ }
+
+ if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
+ server_msg_fn_command_error(&ctx, "%s", cause);
+ cmd_free_argv(argc, argv);
+ goto error;
+ }
+ cmd_free_argv(argc, argv);
+
if (data.pid != -1) {
TAILQ_FOREACH(cmd, cmdlist, qentry) {
if (cmd->entry->flags & CMD_CANTNEST) {
server_msg_fn_command_error(&ctx,
"sessions should be nested with care. "
"unset $TMUX to force");
- cmd_list_free(cmdlist);
- server_write_client(c, MSG_EXIT, NULL, 0);
- return;
+ goto error;
}
}
}
@@ -166,27 +182,28 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
if (cmd_list_exec(cmdlist, &ctx) != 1)
server_write_client(c, MSG_EXIT, NULL, 0);
cmd_list_free(cmdlist);
+ return;
+
+error:
+ if (cmdlist != NULL)
+ cmd_list_free(cmdlist);
+ server_write_client(c, MSG_EXIT, NULL, 0);
}
void
server_msg_fn_identify(struct hdr *hdr, struct client *c)
{
struct msg_identify_data data;
- char *term;
if (hdr->size < sizeof data)
fatalx("bad MSG_IDENTIFY size");
buffer_read(c->in, &data, sizeof data);
- term = cmd_recv_string(c->in);
log_debug("identify msg from client: %u,%u (%d)",
data.sx, data.sy, data.version);
if (data.version != PROTOCOL_VERSION) {
-#define MSG "protocol version mismatch"
- server_write_client(c, MSG_ERROR, MSG, (sizeof MSG) - 1);
-#undef MSG
- server_write_client(c, MSG_EXIT, NULL, 0);
+ server_write_error(c, "protocol version mismatch");
return;
}
@@ -199,7 +216,8 @@ server_msg_fn_identify(struct hdr *hdr, struct client *c)
c->cwd = xstrdup(data.cwd);
data.tty[(sizeof data.tty) - 1] = '\0';
- tty_init(&c->tty, data.tty, term);
+ data.term[(sizeof data.term) - 1] = '\0';
+ tty_init(&c->tty, data.tty, data.term);
if (data.flags & IDENTIFY_UTF8)
c->tty.flags |= TTY_UTF8;
if (data.flags & IDENTIFY_256COLOURS)
@@ -209,9 +227,6 @@ server_msg_fn_identify(struct hdr *hdr, struct client *c)
if (data.flags & IDENTIFY_HASDEFAULTS)
c->tty.term_flags |= TERM_HASDEFAULTS;
- if (term != NULL)
- xfree(term);
-
c->flags |= CLIENT_TERMINAL;
}
@@ -262,24 +277,20 @@ server_msg_fn_exiting(struct hdr *hdr, struct client *c)
void
server_msg_fn_unlock(struct hdr *hdr, struct client *c)
{
- char *pass;
+ struct msg_unlock_data data;
- if (hdr->size == 0)
+ if (hdr->size != sizeof data)
fatalx("bad MSG_UNLOCK size");
- pass = cmd_recv_string(c->in);
+ buffer_read(c->in, &data, sizeof data);
log_debug("unlock msg from client");
- if (server_unlock(pass) != 0) {
-#define MSG "bad password"
- server_write_client(c, MSG_ERROR, MSG, (sizeof MSG) - 1);
-#undef MSG
- }
+ data.pass[(sizeof data.pass) - 1] = '\0';
+ if (server_unlock(data.pass) != 0)
+ server_write_error(c, "bad password");
+ memset(&data, 0, sizeof data);
server_write_client(c, MSG_EXIT, NULL, 0);
-
- memset(pass, 0, strlen(pass));
- xfree(pass);
}
void
diff --git a/tmux.c b/tmux.c
index 2f949c5..e09e552 100644
--- a/tmux.c
+++ b/tmux.c
@@ -62,6 +62,8 @@ char *socket_path;
__dead void usage(void);
char *makesockpath(const char *);
+int prepare_unlock(enum hdrtype *, void **, size_t *, int);
+int prepare_cmd(enum hdrtype *, void **, size_t *, int, char **);
#ifndef HAVE_PROGNAME
char *__progname = (char *) "tmux";
@@ -210,18 +212,69 @@ makesockpath(const char *label)
}
int
+prepare_unlock(enum hdrtype *msg, void **buf, size_t *len, int argc)
+{
+ static struct msg_unlock_data unlockdata;
+ char *pass;
+
+ if (argc != 0) {
+ log_warnx("can't specify a command when unlocking");
+ return (-1);
+ }
+
+ if ((pass = getpass("Password: ")) == NULL)
+ return (-1);
+
+ if (strlen(pass) >= sizeof unlockdata.pass) {
+ log_warnx("password too long");
+ return (-1);
+ }
+
+ strlcpy(unlockdata.pass, pass, sizeof unlockdata.pass);
+ memset(pass, 0, strlen(pass));
+
+ *buf = &unlockdata;
+ *len = sizeof unlockdata;
+
+ *msg = MSG_UNLOCK;
+ return (0);
+}
+
+int
+prepare_cmd(enum hdrtype *msg, void **buf, size_t *len, int argc, char **argv)
+{
+ static struct msg_command_data cmddata;
+
+ client_fill_session(&cmddata);
+
+ cmddata.argc = argc;
+ if (cmd_pack_argv(argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
+ log_warnx("command too long");
+ return (-1);
+ }
+
+ *buf = &cmddata;
+ *len = sizeof cmddata;
+
+ *msg = MSG_COMMAND;
+ return (0);
+}
+
+int
main(int argc, char **argv)
{
struct client_ctx cctx;
- struct msg_command_data cmddata;
- struct buffer *b;
struct cmd_list *cmdlist;
struct cmd *cmd;
struct pollfd pfd;
+ enum hdrtype msg;
struct hdr hdr;
struct passwd *pw;
- char *s, *path, *label, *cause, *home, *pass = NULL;
+ struct msg_print_data printdata;
+ char *s, *path, *label, *home, *cause;
char cwd[MAXPATHLEN];
+ void *buf;
+ size_t len;
int retcode, opt, flags, unlock, cmdflags = 0;
unlock = flags = 0;
@@ -373,7 +426,7 @@ main(int argc, char **argv)
exit(1);
}
}
-
+
if (label == NULL)
label = xstrdup("default");
if (path == NULL && (path = makesockpath(label)) == NULL) {
@@ -392,36 +445,35 @@ main(int argc, char **argv)
options_set_string(&global_s_options, "default-path", "%s", cwd);
if (unlock) {
- if (argc != 0) {
- log_warnx("can't specify a command when unlocking");
+ if (prepare_unlock(&msg, &buf, &len, argc) != 0)
exit(1);
- }
- cmdlist = NULL;
- if ((pass = getpass("Password: ")) == NULL)
+ } else {
+ if (prepare_cmd(&msg, &buf, &len, argc, argv) != 0)
exit(1);
+ }
+
+ if (unlock)
cmdflags &= ~CMD_STARTSERVER;
- } else {
- if (argc == 0) {
- cmd = xmalloc(sizeof *cmd);
- cmd->entry = &cmd_new_session_entry;
- cmd->entry->init(cmd, 0);
-
- cmdlist = xmalloc(sizeof *cmdlist);
- TAILQ_INIT(cmdlist);
- TAILQ_INSERT_HEAD(cmdlist, cmd, qentry);
- } else {
- cmdlist = cmd_list_parse(argc, argv, &cause);
- if (cmdlist == NULL) {
- log_warnx("%s", cause);
- exit(1);
- }
+ else if (argc == 0)
+ cmdflags |= CMD_STARTSERVER;
+ else {
+ /*
+ * It sucks parsing the command string twice (in client and
+ * later in server) but it is necessary to get the start server
+ * flag.
+ */
+ if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
+ log_warnx("%s", cause);
+ exit(1);
}
+ cmdflags &= ~CMD_STARTSERVER;
TAILQ_FOREACH(cmd, cmdlist, qentry) {
if (cmd->entry->flags & CMD_STARTSERVER) {
cmdflags |= CMD_STARTSERVER;
break;
}
}
+ cmd_list_free(cmdlist);
}
memset(&cctx, 0, sizeof cctx);
@@ -429,20 +481,8 @@ main(int argc, char **argv)
exit(1);
xfree(path);
- b = buffer_create(BUFSIZ);
- if (unlock) {
- cmd_send_string(b, pass);
- memset(pass, 0, strlen(pass));
- client_write_server(
- &cctx, MSG_UNLOCK, BUFFER_OUT(b), BUFFER_USED(b));
- } else {
- cmd_list_send(cmdlist, b);
- cmd_list_free(cmdlist);
- client_fill_session(&cmddata);
- client_write_server2(&cctx, MSG_COMMAND,
- &cmddata, sizeof cmddata, BUFFER_OUT(b), BUFFER_USED(b));
- }
- buffer_destroy(b);
+ client_write_server(&cctx, msg, buf, len);
+ memset(buf, 0, len);
retcode = 0;
for (;;) {
@@ -476,12 +516,12 @@ main(int argc, char **argv)
retcode = 1;
/* FALLTHROUGH */
case MSG_PRINT:
- if (hdr.size > INT_MAX - 1)
+ if (hdr.size < sizeof printdata)
fatalx("bad MSG_PRINT size");
- log_info("%.*s",
- (int) hdr.size, BUFFER_OUT(cctx.srv_in));
- if (hdr.size != 0)
- buffer_remove(cctx.srv_in, hdr.size);
+ buffer_read(cctx.srv_in, &printdata, sizeof printdata);
+
+ printdata.msg[(sizeof printdata.msg) - 1] = '\0';
+ log_info("%s", printdata.msg);
goto restart;
case MSG_READY:
retcode = client_main(&cctx);
diff --git a/tmux.h b/tmux.h
index 4fe1c12..0a7a474 100644
--- a/tmux.h
+++ b/tmux.h
@@ -21,7 +21,7 @@
#include "config.h"
-#define PROTOCOL_VERSION -14
+#define PROTOCOL_VERSION -15
#include <sys/param.h>
#include <sys/time.h>
@@ -61,6 +61,14 @@ extern char *__progname;
/* Maximum poll timeout (when attached). */
#define POLL_TIMEOUT 50
+/*
+ * Maximum sizes of strings in message data. Don't forget to bump
+ * PROTOCOL_VERSION if any of these change!
+ */
+#define COMMAND_LENGTH 2048 /* packed argv size */
+#define TERMINAL_LENGTH 128 /* length of TERM environment variable */
+#define PRINT_LENGTH 512 /* printed error/message size */
+
/* Fatal errors. */
#define fatal(msg) log_fatal("%s: %s", __func__, msg);
#define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
@@ -292,17 +300,29 @@ enum hdrtype {
MSG_WAKEUP,
};
-/* Message header structure. */
+/*
+ * Message header and data.
+ *
+ * Don't forget to bump PROTOCOL_VERSION if any of these change!
+ *
+ * Changing sizeof (struct hdr) or sizeof (struct msg_identify_data) will make
+ * the tmux client hang even if the protocol version is bumped.
+ */
struct hdr {
enum hdrtype type;
size_t size;
};
+struct msg_print_data {
+ char msg[PRINT_LENGTH];
+};
+
struct msg_command_data {
pid_t pid; /* pid from $TMUX or -1 */
u_int idx; /* index from $TMUX */
- size_t namelen;
+ int argc;
+ char argv[COMMAND_LENGTH];
};
struct msg_identify_data {
@@ -311,6 +331,8 @@ struct msg_identify_data {
char cwd[MAXPATHLEN];
+ char term[TERMINAL_LENGTH];
+
#define IDENTIFY_UTF8 0x1
#define IDENTIFY_256COLOURS 0x2
#define IDENTIFY_88COLOURS 0x4
@@ -319,8 +341,6 @@ struct msg_identify_data {
u_int sx;
u_int sy;
-
- size_t termlen;
};
struct msg_resize_data {
@@ -328,6 +348,10 @@ struct msg_resize_data {
u_int sy;
};
+struct msg_unlock_data {
+ char pass[PASS_MAX];
+};
+
/* Editing keys. */
enum mode_key_cmd {
MODEKEYCMD_BACKSPACE = 0x1000,
@@ -906,8 +930,6 @@ struct cmd_entry {
void (*init)(struct cmd *, int);
int (*parse)(struct cmd *, int, char **, char **);
int (*exec)(struct cmd *, struct cmd_ctx *);
- void (*send)(struct cmd *, struct buffer *);
- void (*recv)(struct cmd *, struct buffer *);
void (*free)(struct cmd *);
size_t (*print)(struct cmd *, char *, size_t);
};
@@ -1112,14 +1134,13 @@ int paste_replace(struct paste_stack *, u_int, char *);
void clock_draw(struct screen_write_ctx *, u_int, int);
/* cmd.c */
+int cmd_pack_argv(int, char **, char *, size_t);
+int cmd_unpack_argv(char *, size_t, int, char ***);
+void cmd_free_argv(int, char **);
struct cmd *cmd_parse(int, char **, char **);
int cmd_exec(struct cmd *, struct cmd_ctx *);
-void cmd_send(struct cmd *, struct buffer *);
-struct cmd *cmd_recv(struct buffer *);
void cmd_free(struct cmd *);
size_t cmd_print(struct cmd *, char *, size_t);
-void cmd_send_string(struct buffer *, const char *);
-char *cmd_recv_string(struct buffer *);
struct session *cmd_current_session(struct cmd_ctx *);
struct client *cmd_find_client(struct cmd_ctx *, const char *);
struct session *cmd_find_session(struct cmd_ctx *, const char *);
@@ -1204,8 +1225,6 @@ extern const struct cmd_entry cmd_up_pane_entry;
/* cmd-list.c */
struct cmd_list *cmd_list_parse(int, char **, char **);
int cmd_list_exec(struct cmd_list *, struct cmd_ctx *);
-void cmd_list_send(struct cmd_list *, struct buffer *);
-struct cmd_list *cmd_list_recv(struct buffer *);
void cmd_list_free(struct cmd_list *);
size_t cmd_list_print(struct cmd_list *, char *, size_t);
@@ -1219,8 +1238,6 @@ size_t cmd_prarg(char *, size_t, const char *, char *);
#define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
void cmd_target_init(struct cmd *, int);
int cmd_target_parse(struct cmd *, int, char **, char **);
-void cmd_target_send(struct cmd *, struct buffer *);
-void cmd_target_recv(struct cmd *, struct buffer *);
void cmd_target_free(struct cmd *);
size_t cmd_target_print(struct cmd *, char *, size_t);
#define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
@@ -1228,8 +1245,6 @@ size_t cmd_target_print(struct cmd *, char *, size_t);
#define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
void cmd_srcdst_init(struct cmd *, int);
int cmd_srcdst_parse(struct cmd *, int, char **, char **);
-void cmd_srcdst_send(struct cmd *, struct buffer *);
-void cmd_srcdst_recv(struct cmd *, struct buffer *);
void cmd_srcdst_free(struct cmd *);
size_t cmd_srcdst_print(struct cmd *, char *, size_t);
#define CMD_BUFFER_WINDOW_USAGE "[-b buffer-index] [-t target-window]"
@@ -1237,8 +1252,6 @@ size_t cmd_srcdst_print(struct cmd *, char *, size_t);
#define CMD_BUFFER_CLIENT_USAGE "[-b buffer-index] [-t target-client]"
void cmd_buffer_init(struct cmd *, int);
int cmd_buffer_parse(struct cmd *, int, char **, char **);
-void cmd_buffer_send(struct cmd *, struct buffer *);
-void cmd_buffer_recv(struct cmd *, struct buffer *);
void cmd_buffer_free(struct cmd *);
size_t cmd_buffer_print(struct cmd *, char *, size_t);
#define CMD_OPTION_WINDOW_USAGE "[-gu] [-t target-window] option [value]"
@@ -1246,8 +1259,6 @@ size_t cmd_buffer_print(struct cmd *, char *, size_t);
#define CMD_OPTION_CLIENT_USAGE "[-gu] [-t target-client] option [value]"
void cmd_option_init(struct cmd *, int);
int cmd_option_parse(struct cmd *, int, char **, char **);
-void cmd_option_send(struct cmd *, struct buffer *);
-void cmd_option_recv(struct cmd *, struct buffer *);
void cmd_option_free(struct cmd *);
size_t cmd_option_print(struct cmd *, char *, size_t);
#define CMD_PANE_WINDOW_USAGE "[-t target-window] [-p pane-index]"
@@ -1255,8 +1266,6 @@ size_t cmd_option_print(struct cmd *, char *, size_t);
#define CMD_PANE_CLIENT_USAGE "[-t target-client] [-p pane-index]"
void cmd_pane_init(struct cmd *, int);
int cmd_pane_parse(struct cmd *, int, char **, char **);
-void cmd_pane_send(struct cmd *, struct buffer *);
-void cmd_pane_recv(struct cmd *, struct buffer *);
void cmd_pane_free(struct cmd *);
size_t cmd_pane_print(struct cmd *, char *, size_t);
@@ -1269,8 +1278,6 @@ int client_msg_dispatch(struct client_ctx *);
/* client-fn.c */
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_session(struct msg_command_data *);
/* key-bindings.c */
@@ -1302,6 +1309,7 @@ int server_msg_dispatch(struct client *);
/* server-fn.c */
const char **server_fill_environ(struct session *);
+void server_write_error(struct client *, const char *);
void server_write_client(
struct client *, enum hdrtype, const void *, size_t);
void server_write_session(