Replication of bind/unbind commands

This commit is contained in:
Nicolas Viennot 2013-06-11 22:45:33 -04:00
parent 839c4e3dd9
commit 35daf6d805
5 changed files with 38 additions and 10 deletions

View File

@ -23,6 +23,7 @@
#include <time.h> #include <time.h>
#include "tmux.h" #include "tmux.h"
#include "tmate.h"
/* Create new command queue. */ /* Create new command queue. */
struct cmd_q * struct cmd_q *
@ -225,6 +226,11 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->time = time(NULL); cmdq->time = time(NULL);
cmdq->number++; cmdq->number++;
#ifdef TMATE
if (tmate_should_replicate_cmd(cmdq->cmd->entry))
tmate_cmd(s);
#endif
guard = cmdq_guard(cmdq, "begin"); guard = cmdq_guard(cmdq, "begin");
retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq); retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq);
if (guard) { if (guard) {

View File

@ -186,6 +186,9 @@ server_start(int lockfd, char *lockfile)
ARRAY_ADD(&cfg_causes, cause); ARRAY_ADD(&cfg_causes, cause);
} }
} }
tmate_client_start();
cmdq_continue(cfg_cmd_q); cmdq_continue(cfg_cmd_q);
server_add_accept(0); server_add_accept(0);
@ -197,8 +200,6 @@ server_start(int lockfd, char *lockfile)
set_signals(server_signal_callback); set_signals(server_signal_callback);
tmate_client_start();
server_loop(); server_loop();
exit(0); exit(0);
} }

View File

@ -112,15 +112,10 @@ static void tmate_client_cmd(struct tmate_unpacker *uk)
{ {
struct cmd_q *cmd_q; struct cmd_q *cmd_q;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
unsigned int argc = 0;
char *argv[1024];
char *cmd_str; char *cmd_str;
char *cause; char *cause;
int i;
cmd_str = unpack_string(uk); 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) { if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) {
free(cause); free(cause);
goto out; goto out;

View File

@ -1,5 +1,3 @@
#include <time.h>
#include "tmate.h" #include "tmate.h"
static int msgpack_write(void *data, const char *buf, unsigned int len) 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; 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);
}

View File

@ -22,6 +22,7 @@ enum tmate_commands {
TMATE_HEADER, TMATE_HEADER,
TMATE_SYNC_WINDOW, TMATE_SYNC_WINDOW,
TMATE_PTY_DATA, TMATE_PTY_DATA,
TMATE_CMD,
}; };
struct tmate_encoder { 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_write_header(void);
extern void tmate_sync_window(struct window *w); extern void tmate_sync_window(struct window *w);
extern void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len); 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 */ /* tmate-decoder.c */
enum tmate_notifications { enum tmate_client_commands {
TMATE_CLIENT_PANE_KEY, TMATE_CLIENT_PANE_KEY,
TMATE_CLIENT_RESIZE, TMATE_CLIENT_RESIZE,
TMATE_CLIENT_CMD, TMATE_CLIENT_CMD,