From 35daf6d8058a3ee68b6007df1d594323cde9debe Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Tue, 11 Jun 2013 22:45:33 -0400 Subject: [PATCH] Replication of bind/unbind commands --- cmd-queue.c | 6 ++++++ server.c | 5 +++-- tmate-decoder.c | 5 ----- tmate-encoder.c | 27 +++++++++++++++++++++++++-- tmate.h | 5 ++++- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/cmd-queue.c b/cmd-queue.c index c5f75f40..8a274305 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -23,6 +23,7 @@ #include #include "tmux.h" +#include "tmate.h" /* Create new command queue. */ struct cmd_q * @@ -225,6 +226,11 @@ cmdq_continue(struct cmd_q *cmdq) cmdq->time = time(NULL); cmdq->number++; +#ifdef TMATE + if (tmate_should_replicate_cmd(cmdq->cmd->entry)) + tmate_cmd(s); +#endif + guard = cmdq_guard(cmdq, "begin"); retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq); if (guard) { diff --git a/server.c b/server.c index 352255f7..6a636825 100644 --- a/server.c +++ b/server.c @@ -186,6 +186,9 @@ server_start(int lockfd, char *lockfile) ARRAY_ADD(&cfg_causes, cause); } } + + tmate_client_start(); + cmdq_continue(cfg_cmd_q); server_add_accept(0); @@ -197,8 +200,6 @@ server_start(int lockfd, char *lockfile) set_signals(server_signal_callback); - tmate_client_start(); - server_loop(); exit(0); } diff --git a/tmate-decoder.c b/tmate-decoder.c index 774c8c0d..1abe700e 100644 --- a/tmate-decoder.c +++ b/tmate-decoder.c @@ -112,15 +112,10 @@ static void tmate_client_cmd(struct tmate_unpacker *uk) { struct cmd_q *cmd_q; struct cmd_list *cmdlist; - unsigned int argc = 0; - char *argv[1024]; char *cmd_str; char *cause; - int i; cmd_str = unpack_string(uk); - tmate_debug("received command from remote client: %s", cmd_str); - if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) { free(cause); goto out; diff --git a/tmate-encoder.c b/tmate-encoder.c index a4449e5c..6995371c 100644 --- a/tmate-encoder.c +++ b/tmate-encoder.c @@ -1,5 +1,3 @@ -#include - #include "tmate.h" static int msgpack_write(void *data, const char *buf, unsigned int len) @@ -87,3 +85,28 @@ void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len) len -= to_write; } } + +static const struct cmd_entry *replicated_cmds[] = { + &cmd_bind_key_entry, + &cmd_unbind_key_entry, + &cmd_set_option_entry, + &cmd_set_window_option_entry, + NULL +}; + +int tmate_should_replicate_cmd(const struct cmd_entry *cmd) +{ + const struct cmd_entry **ptr; + + for (ptr = replicated_cmds; *ptr; ptr++) + if (*ptr == cmd) + return 1; + return 0; +} + +void tmate_cmd(const char *cmd) +{ + pack(array, 2); + pack(int, TMATE_CMD); + pack(string, cmd); +} diff --git a/tmate.h b/tmate.h index a9caf337..13defe29 100644 --- a/tmate.h +++ b/tmate.h @@ -22,6 +22,7 @@ enum tmate_commands { TMATE_HEADER, TMATE_SYNC_WINDOW, TMATE_PTY_DATA, + TMATE_CMD, }; struct tmate_encoder { @@ -35,10 +36,12 @@ extern void tmate_encoder_init(struct tmate_encoder *encoder); extern void tmate_write_header(void); extern void tmate_sync_window(struct window *w); extern void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len); +extern int tmate_should_replicate_cmd(const struct cmd_entry *cmd); +extern void tmate_cmd(const char *cmd); /* tmate-decoder.c */ -enum tmate_notifications { +enum tmate_client_commands { TMATE_CLIENT_PANE_KEY, TMATE_CLIENT_RESIZE, TMATE_CLIENT_CMD,