mirror of
https://github.com/tmate-io/tmate.git
synced 2025-02-17 02:41:07 +01:00
Replication of bind/unbind commands
This commit is contained in:
parent
839c4e3dd9
commit
35daf6d805
@ -23,6 +23,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#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) {
|
||||
|
5
server.c
5
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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,3 @@
|
||||
#include <time.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
5
tmate.h
5
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,
|
||||
|
Loading…
Reference in New Issue
Block a user