mirror of
https://github.com/tmux/tmux.git
synced 2025-01-15 05:09:04 +00:00
Similarly for MSG_COMMAND - allow full imsg limit not arbitrary 2048.
This commit is contained in:
parent
a0404b6902
commit
10c38436aa
148
client.c
148
client.c
@ -54,7 +54,8 @@ int client_get_lock(char *);
|
|||||||
int client_connect(char *, int);
|
int client_connect(char *, int);
|
||||||
void client_send_identify(int);
|
void client_send_identify(int);
|
||||||
void client_send_environ(void);
|
void client_send_environ(void);
|
||||||
void client_write_server(enum msgtype, void *, size_t);
|
int client_write_one(enum msgtype, int, const void *, size_t);
|
||||||
|
int client_write_server(enum msgtype, const void *, size_t);
|
||||||
void client_update_event(void);
|
void client_update_event(void);
|
||||||
void client_signal(int, short, void *);
|
void client_signal(int, short, void *);
|
||||||
void client_stdin_callback(int, short, void *);
|
void client_stdin_callback(int, short, void *);
|
||||||
@ -165,12 +166,13 @@ client_main(int argc, char **argv, int flags)
|
|||||||
{
|
{
|
||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct msg_command_data cmddata;
|
struct msg_command_data *data;
|
||||||
int cmdflags, fd;
|
int cmdflags, fd, i;
|
||||||
pid_t ppid;
|
pid_t ppid;
|
||||||
enum msgtype msg;
|
enum msgtype msg;
|
||||||
char *cause;
|
char *cause;
|
||||||
struct termios tio, saved_tio;
|
struct termios tio, saved_tio;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
/* Set up the initial command. */
|
/* Set up the initial command. */
|
||||||
cmdflags = 0;
|
cmdflags = 0;
|
||||||
@ -234,7 +236,7 @@ client_main(int argc, char **argv, int flags)
|
|||||||
setblocking(STDIN_FILENO, 0);
|
setblocking(STDIN_FILENO, 0);
|
||||||
event_set(&client_stdin, STDIN_FILENO, EV_READ|EV_PERSIST,
|
event_set(&client_stdin, STDIN_FILENO, EV_READ|EV_PERSIST,
|
||||||
client_stdin_callback, NULL);
|
client_stdin_callback, NULL);
|
||||||
if (flags & IDENTIFY_TERMIOS) {
|
if (flags & CLIENT_CONTROLCONTROL) {
|
||||||
if (tcgetattr(STDIN_FILENO, &saved_tio) != 0) {
|
if (tcgetattr(STDIN_FILENO, &saved_tio) != 0) {
|
||||||
fprintf(stderr, "tcgetattr failed: %s\n",
|
fprintf(stderr, "tcgetattr failed: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
@ -261,19 +263,32 @@ client_main(int argc, char **argv, int flags)
|
|||||||
|
|
||||||
/* Send first command. */
|
/* Send first command. */
|
||||||
if (msg == MSG_COMMAND) {
|
if (msg == MSG_COMMAND) {
|
||||||
|
/* How big is the command? */
|
||||||
|
size = 0;
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
size += strlen(argv[i]) + 1;
|
||||||
|
data = xmalloc((sizeof *data) + size);
|
||||||
|
|
||||||
/* Fill in command line arguments. */
|
/* Fill in command line arguments. */
|
||||||
cmddata.pid = environ_pid;
|
data->pid = environ_pid;
|
||||||
cmddata.session_id = environ_session_id;
|
data->session_id = environ_session_id;
|
||||||
|
|
||||||
/* Prepare command for server. */
|
/* Prepare command for server. */
|
||||||
cmddata.argc = argc;
|
data->argc = argc;
|
||||||
if (cmd_pack_argv(
|
if (cmd_pack_argv(argc, argv, (char*)(data + 1), size) != 0) {
|
||||||
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
|
|
||||||
fprintf(stderr, "command too long\n");
|
fprintf(stderr, "command too long\n");
|
||||||
|
free(data);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
size += sizeof *data;
|
||||||
|
|
||||||
client_write_server(msg, &cmddata, sizeof cmddata);
|
/* Send the command. */
|
||||||
|
if (client_write_server(msg, data, size) != 0) {
|
||||||
|
fprintf(stderr, "failed to send command\n");
|
||||||
|
free(data);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
free(data);
|
||||||
} else if (msg == MSG_SHELL)
|
} else if (msg == MSG_SHELL)
|
||||||
client_write_server(msg, NULL, 0);
|
client_write_server(msg, NULL, 0);
|
||||||
|
|
||||||
@ -289,14 +304,12 @@ client_main(int argc, char **argv, int flags)
|
|||||||
ppid = getppid();
|
ppid = getppid();
|
||||||
if (client_exittype == MSG_DETACHKILL && ppid > 1)
|
if (client_exittype == MSG_DETACHKILL && ppid > 1)
|
||||||
kill(ppid, SIGHUP);
|
kill(ppid, SIGHUP);
|
||||||
} else if (flags & IDENTIFY_TERMIOS) {
|
} else if (flags & CLIENT_CONTROLCONTROL) {
|
||||||
if (flags & IDENTIFY_CONTROL) {
|
if (client_exitreason != CLIENT_EXIT_NONE)
|
||||||
if (client_exitreason != CLIENT_EXIT_NONE)
|
printf("%%exit %s\n", client_exit_message());
|
||||||
printf("%%exit %s\n", client_exit_message());
|
else
|
||||||
else
|
printf("%%exit\n");
|
||||||
printf("%%exit\n");
|
printf("\033\\");
|
||||||
printf("\033\\");
|
|
||||||
}
|
|
||||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
||||||
}
|
}
|
||||||
setblocking(STDIN_FILENO, 1);
|
setblocking(STDIN_FILENO, 1);
|
||||||
@ -342,12 +355,29 @@ client_send_environ(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a message to the server without a file descriptor. */
|
/* Helper to send one message. */
|
||||||
void
|
int
|
||||||
client_write_server(enum msgtype type, void *buf, size_t len)
|
client_write_one(enum msgtype type, int fd, const void *buf, size_t len)
|
||||||
{
|
{
|
||||||
imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
|
int retval;
|
||||||
client_update_event();
|
|
||||||
|
retval = imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, fd,
|
||||||
|
(void*)buf, len);
|
||||||
|
if (retval != 1)
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write a message to the server without a file descriptor. */
|
||||||
|
int
|
||||||
|
client_write_server(enum msgtype type, const void *buf, size_t len)
|
||||||
|
{
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
retval = client_write_one(type, -1, buf, len);
|
||||||
|
if (retval == 0)
|
||||||
|
client_update_event();
|
||||||
|
return (retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update client event based on whether it needs to read or read and write. */
|
/* Update client event based on whether it needs to read or read and write. */
|
||||||
@ -481,33 +511,33 @@ client_write(int fd, const char *data, size_t size)
|
|||||||
|
|
||||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||||
int
|
int
|
||||||
client_dispatch_wait(void *data)
|
client_dispatch_wait(void *data0)
|
||||||
{
|
{
|
||||||
struct imsg imsg;
|
struct imsg imsg;
|
||||||
ssize_t n, datalen;
|
char *data;
|
||||||
struct msg_shell_data shelldata;
|
ssize_t n, datalen;
|
||||||
struct msg_exit_data exitdata;
|
struct msg_stdout_data stdoutdata;
|
||||||
struct msg_stdout_data stdoutdata;
|
struct msg_stderr_data stderrdata;
|
||||||
struct msg_stderr_data stderrdata;
|
int retval;
|
||||||
const char *shellcmd = data;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
||||||
fatalx("imsg_get failed");
|
fatalx("imsg_get failed");
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
data = imsg.data;
|
||||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
log_debug("got %d from server", imsg.hdr.type);
|
log_debug("got %d from server", imsg.hdr.type);
|
||||||
switch (imsg.hdr.type) {
|
switch (imsg.hdr.type) {
|
||||||
case MSG_EXIT:
|
case MSG_EXIT:
|
||||||
case MSG_SHUTDOWN:
|
case MSG_SHUTDOWN:
|
||||||
if (datalen != sizeof exitdata) {
|
if (datalen != sizeof retval && datalen != 0)
|
||||||
if (datalen != 0)
|
fatalx("bad MSG_EXIT size");
|
||||||
fatalx("bad MSG_EXIT size");
|
if (datalen == sizeof retval) {
|
||||||
} else {
|
memcpy(&retval, data, sizeof retval);
|
||||||
memcpy(&exitdata, imsg.data, sizeof exitdata);
|
client_exitval = retval;
|
||||||
client_exitval = exitdata.retcode;
|
|
||||||
}
|
}
|
||||||
imsg_free(&imsg);
|
imsg_free(&imsg);
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -527,17 +557,19 @@ client_dispatch_wait(void *data)
|
|||||||
break;
|
break;
|
||||||
case MSG_STDOUT:
|
case MSG_STDOUT:
|
||||||
if (datalen != sizeof stdoutdata)
|
if (datalen != sizeof stdoutdata)
|
||||||
fatalx("bad MSG_STDOUT");
|
fatalx("bad MSG_STDOUT size");
|
||||||
memcpy(&stdoutdata, imsg.data, sizeof stdoutdata);
|
memcpy(&stdoutdata, data, sizeof stdoutdata);
|
||||||
|
|
||||||
client_write(STDOUT_FILENO, stdoutdata.data, stdoutdata.size);
|
client_write(STDOUT_FILENO, stdoutdata.data,
|
||||||
|
stdoutdata.size);
|
||||||
break;
|
break;
|
||||||
case MSG_STDERR:
|
case MSG_STDERR:
|
||||||
if (datalen != sizeof stderrdata)
|
if (datalen != sizeof stderrdata)
|
||||||
fatalx("bad MSG_STDERR");
|
fatalx("bad MSG_STDERR size");
|
||||||
memcpy(&stderrdata, imsg.data, sizeof stderrdata);
|
memcpy(&stderrdata, data, sizeof stderrdata);
|
||||||
|
|
||||||
client_write(STDERR_FILENO, stderrdata.data, stderrdata.size);
|
client_write(STDERR_FILENO, stderrdata.data,
|
||||||
|
stderrdata.size);
|
||||||
break;
|
break;
|
||||||
case MSG_VERSION:
|
case MSG_VERSION:
|
||||||
if (datalen != 0)
|
if (datalen != 0)
|
||||||
@ -551,14 +583,11 @@ client_dispatch_wait(void *data)
|
|||||||
imsg_free(&imsg);
|
imsg_free(&imsg);
|
||||||
return (-1);
|
return (-1);
|
||||||
case MSG_SHELL:
|
case MSG_SHELL:
|
||||||
if (datalen != sizeof shelldata)
|
if (data[datalen - 1] != '\0')
|
||||||
fatalx("bad MSG_SHELL size");
|
fatalx("bad MSG_SHELL string");
|
||||||
memcpy(&shelldata, imsg.data, sizeof shelldata);
|
|
||||||
shelldata.shell[(sizeof shelldata.shell) - 1] = '\0';
|
|
||||||
|
|
||||||
clear_signals(0);
|
clear_signals(0);
|
||||||
|
shell_exec(data, data0);
|
||||||
shell_exec(shelldata.shell, shellcmd);
|
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case MSG_DETACH:
|
case MSG_DETACH:
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
@ -578,16 +607,18 @@ client_dispatch_wait(void *data)
|
|||||||
int
|
int
|
||||||
client_dispatch_attached(void)
|
client_dispatch_attached(void)
|
||||||
{
|
{
|
||||||
struct imsg imsg;
|
struct imsg imsg;
|
||||||
struct msg_lock_data lockdata;
|
struct sigaction sigact;
|
||||||
struct sigaction sigact;
|
char *data;
|
||||||
ssize_t n, datalen;
|
ssize_t n, datalen;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
|
||||||
fatalx("imsg_get failed");
|
fatalx("imsg_get failed");
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
data = imsg.data;
|
||||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
log_debug("got %d from server", imsg.hdr.type);
|
log_debug("got %d from server", imsg.hdr.type);
|
||||||
@ -605,8 +636,7 @@ client_dispatch_attached(void)
|
|||||||
client_write_server(MSG_EXITING, NULL, 0);
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case MSG_EXIT:
|
case MSG_EXIT:
|
||||||
if (datalen != 0 &&
|
if (datalen != 0 && datalen != sizeof (int))
|
||||||
datalen != sizeof (struct msg_exit_data))
|
|
||||||
fatalx("bad MSG_EXIT size");
|
fatalx("bad MSG_EXIT size");
|
||||||
|
|
||||||
client_write_server(MSG_EXITING, NULL, 0);
|
client_write_server(MSG_EXITING, NULL, 0);
|
||||||
@ -639,12 +669,10 @@ client_dispatch_attached(void)
|
|||||||
kill(getpid(), SIGTSTP);
|
kill(getpid(), SIGTSTP);
|
||||||
break;
|
break;
|
||||||
case MSG_LOCK:
|
case MSG_LOCK:
|
||||||
if (datalen != sizeof lockdata)
|
if (data[datalen - 1] != '\0')
|
||||||
fatalx("bad MSG_LOCK size");
|
fatalx("bad MSG_LOCK string");
|
||||||
memcpy(&lockdata, imsg.data, sizeof lockdata);
|
|
||||||
|
|
||||||
lockdata.cmd[(sizeof lockdata.cmd) - 1] = '\0';
|
system(data);
|
||||||
system(lockdata.cmd);
|
|
||||||
client_write_server(MSG_UNLOCK, NULL, 0);
|
client_write_server(MSG_UNLOCK, NULL, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -40,7 +40,7 @@ void server_client_reset_state(struct client *);
|
|||||||
int server_client_assume_paste(struct session *);
|
int server_client_assume_paste(struct session *);
|
||||||
|
|
||||||
int server_client_msg_dispatch(struct client *);
|
int server_client_msg_dispatch(struct client *);
|
||||||
void server_client_msg_command(struct client *, struct msg_command_data *);
|
void server_client_msg_command(struct client *, struct imsg *);
|
||||||
void server_client_msg_identify(
|
void server_client_msg_identify(
|
||||||
struct client *, struct msg_identify_data *, int);
|
struct client *, struct msg_identify_data *, int);
|
||||||
void server_client_msg_shell(struct client *);
|
void server_client_msg_shell(struct client *);
|
||||||
@ -695,8 +695,6 @@ server_client_repeat_timer(unused int fd, unused short events, void *data)
|
|||||||
void
|
void
|
||||||
server_client_check_exit(struct client *c)
|
server_client_check_exit(struct client *c)
|
||||||
{
|
{
|
||||||
struct msg_exit_data exitdata;
|
|
||||||
|
|
||||||
if (!(c->flags & CLIENT_EXIT))
|
if (!(c->flags & CLIENT_EXIT))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -707,9 +705,7 @@ server_client_check_exit(struct client *c)
|
|||||||
if (EVBUFFER_LENGTH(c->stderr_data) != 0)
|
if (EVBUFFER_LENGTH(c->stderr_data) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
exitdata.retcode = c->retcode;
|
server_write_client(c, MSG_EXIT, &c->retval, sizeof c->retval);
|
||||||
server_write_client(c, MSG_EXIT, &exitdata, sizeof exitdata);
|
|
||||||
|
|
||||||
c->flags &= ~CLIENT_EXIT;
|
c->flags &= ~CLIENT_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -790,10 +786,10 @@ int
|
|||||||
server_client_msg_dispatch(struct client *c)
|
server_client_msg_dispatch(struct client *c)
|
||||||
{
|
{
|
||||||
struct imsg imsg;
|
struct imsg imsg;
|
||||||
struct msg_command_data commanddata;
|
|
||||||
struct msg_identify_data identifydata;
|
struct msg_identify_data identifydata;
|
||||||
struct msg_environ_data environdata;
|
struct msg_environ_data environdata;
|
||||||
struct msg_stdin_data stdindata;
|
struct msg_stdin_data stdindata;
|
||||||
|
const char *data;
|
||||||
ssize_t n, datalen;
|
ssize_t n, datalen;
|
||||||
|
|
||||||
if ((n = imsg_read(&c->ibuf)) == -1 || n == 0)
|
if ((n = imsg_read(&c->ibuf)) == -1 || n == 0)
|
||||||
@ -804,6 +800,8 @@ server_client_msg_dispatch(struct client *c)
|
|||||||
return (-1);
|
return (-1);
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
data = imsg.data;
|
||||||
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
|
||||||
if (imsg.hdr.peerid != PROTOCOL_VERSION) {
|
if (imsg.hdr.peerid != PROTOCOL_VERSION) {
|
||||||
@ -815,13 +813,6 @@ server_client_msg_dispatch(struct client *c)
|
|||||||
|
|
||||||
log_debug("got %d from client %d", imsg.hdr.type, c->ibuf.fd);
|
log_debug("got %d from client %d", imsg.hdr.type, c->ibuf.fd);
|
||||||
switch (imsg.hdr.type) {
|
switch (imsg.hdr.type) {
|
||||||
case MSG_COMMAND:
|
|
||||||
if (datalen != sizeof commanddata)
|
|
||||||
fatalx("bad MSG_COMMAND size");
|
|
||||||
memcpy(&commanddata, imsg.data, sizeof commanddata);
|
|
||||||
|
|
||||||
server_client_msg_command(c, &commanddata);
|
|
||||||
break;
|
|
||||||
case MSG_IDENTIFY:
|
case MSG_IDENTIFY:
|
||||||
if (datalen != sizeof identifydata)
|
if (datalen != sizeof identifydata)
|
||||||
fatalx("bad MSG_IDENTIFY size");
|
fatalx("bad MSG_IDENTIFY size");
|
||||||
@ -829,10 +820,13 @@ server_client_msg_dispatch(struct client *c)
|
|||||||
|
|
||||||
server_client_msg_identify(c, &identifydata, imsg.fd);
|
server_client_msg_identify(c, &identifydata, imsg.fd);
|
||||||
break;
|
break;
|
||||||
|
case MSG_COMMAND:
|
||||||
|
server_client_msg_command(c, &imsg);
|
||||||
|
break;
|
||||||
case MSG_STDIN:
|
case MSG_STDIN:
|
||||||
if (datalen != sizeof stdindata)
|
if (datalen != sizeof stdindata)
|
||||||
fatalx("bad MSG_STDIN size");
|
fatalx("bad MSG_STDIN size");
|
||||||
memcpy(&stdindata, imsg.data, sizeof stdindata);
|
memcpy(&stdindata, data, sizeof stdindata);
|
||||||
|
|
||||||
if (c->stdin_callback == NULL)
|
if (c->stdin_callback == NULL)
|
||||||
break;
|
break;
|
||||||
@ -907,15 +901,26 @@ server_client_msg_dispatch(struct client *c)
|
|||||||
|
|
||||||
/* Handle command message. */
|
/* Handle command message. */
|
||||||
void
|
void
|
||||||
server_client_msg_command(struct client *c, struct msg_command_data *data)
|
server_client_msg_command(struct client *c, struct imsg *imsg)
|
||||||
{
|
{
|
||||||
struct cmd_list *cmdlist = NULL;
|
struct msg_command_data data;
|
||||||
int argc;
|
char *buf;
|
||||||
char **argv, *cause;
|
size_t len;
|
||||||
|
struct cmd_list *cmdlist = NULL;
|
||||||
|
int argc;
|
||||||
|
char **argv, *cause;
|
||||||
|
|
||||||
argc = data->argc;
|
if (imsg->hdr.len - IMSG_HEADER_SIZE < sizeof data)
|
||||||
data->argv[(sizeof data->argv) - 1] = '\0';
|
fatalx("bad MSG_COMMAND size");
|
||||||
if (cmd_unpack_argv(data->argv, sizeof data->argv, argc, &argv) != 0) {
|
memcpy(&data, imsg->data, sizeof data);
|
||||||
|
|
||||||
|
buf = (char*)imsg->data + sizeof data;
|
||||||
|
len = imsg->hdr.len - IMSG_HEADER_SIZE - sizeof data;
|
||||||
|
if (len > 0 && buf[len - 1] != '\0')
|
||||||
|
fatalx("bad MSG_COMMAND string");
|
||||||
|
|
||||||
|
argc = data.argc;
|
||||||
|
if (cmd_unpack_argv(buf, len, argc, &argv) != 0) {
|
||||||
cmdq_error(c->cmdq, "command too long");
|
cmdq_error(c->cmdq, "command too long");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -954,12 +959,12 @@ server_client_msg_identify(
|
|||||||
if (*data->cwd != '\0')
|
if (*data->cwd != '\0')
|
||||||
c->cwd = xstrdup(data->cwd);
|
c->cwd = xstrdup(data->cwd);
|
||||||
|
|
||||||
if (data->flags & IDENTIFY_CONTROL) {
|
if (data->flags & CLIENT_CONTROL) {
|
||||||
c->stdin_callback = control_callback;
|
c->stdin_callback = control_callback;
|
||||||
evbuffer_free(c->stderr_data);
|
evbuffer_free(c->stderr_data);
|
||||||
c->stderr_data = c->stdout_data;
|
c->stderr_data = c->stdout_data;
|
||||||
c->flags |= CLIENT_CONTROL;
|
c->flags |= CLIENT_CONTROL;
|
||||||
if (data->flags & IDENTIFY_TERMIOS)
|
if (data->flags & CLIENT_CONTROLCONTROL)
|
||||||
evbuffer_add_printf(c->stdout_data, "\033P1000p");
|
evbuffer_add_printf(c->stdout_data, "\033P1000p");
|
||||||
server_write_client(c, MSG_STDIN, NULL, 0);
|
server_write_client(c, MSG_STDIN, NULL, 0);
|
||||||
|
|
||||||
@ -978,14 +983,14 @@ server_client_msg_identify(
|
|||||||
}
|
}
|
||||||
data->term[(sizeof data->term) - 1] = '\0';
|
data->term[(sizeof data->term) - 1] = '\0';
|
||||||
tty_init(&c->tty, c, fd, data->term);
|
tty_init(&c->tty, c, fd, data->term);
|
||||||
if (data->flags & IDENTIFY_UTF8)
|
if (data->flags & CLIENT_UTF8)
|
||||||
c->tty.flags |= TTY_UTF8;
|
c->tty.flags |= TTY_UTF8;
|
||||||
if (data->flags & IDENTIFY_256COLOURS)
|
if (data->flags & CLIENT_256COLOURS)
|
||||||
c->tty.term_flags |= TERM_256COLOURS;
|
c->tty.term_flags |= TERM_256COLOURS;
|
||||||
|
|
||||||
tty_resize(&c->tty);
|
tty_resize(&c->tty);
|
||||||
|
|
||||||
if (!(data->flags & IDENTIFY_CONTROL))
|
if (!(data->flags & CLIENT_CONTROL))
|
||||||
c->flags |= CLIENT_TERMINAL;
|
c->flags |= CLIENT_TERMINAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -993,16 +998,12 @@ server_client_msg_identify(
|
|||||||
void
|
void
|
||||||
server_client_msg_shell(struct client *c)
|
server_client_msg_shell(struct client *c)
|
||||||
{
|
{
|
||||||
struct msg_shell_data data;
|
const char *shell;
|
||||||
const char *shell;
|
|
||||||
|
|
||||||
shell = options_get_string(&global_s_options, "default-shell");
|
shell = options_get_string(&global_s_options, "default-shell");
|
||||||
|
|
||||||
if (*shell == '\0' || areshell(shell))
|
if (*shell == '\0' || areshell(shell))
|
||||||
shell = _PATH_BSHELL;
|
shell = _PATH_BSHELL;
|
||||||
if (strlcpy(data.shell, shell, sizeof data.shell) >= sizeof data.shell)
|
server_write_client(c, MSG_SHELL, shell, strlen(shell) + 1);
|
||||||
strlcpy(data.shell, _PATH_BSHELL, sizeof data.shell);
|
|
||||||
|
|
||||||
server_write_client(c, MSG_SHELL, &data, sizeof data);
|
|
||||||
c->flags |= CLIENT_BAD; /* it will die after exec */
|
c->flags |= CLIENT_BAD; /* it will die after exec */
|
||||||
}
|
}
|
||||||
|
@ -235,9 +235,7 @@ server_lock_session(struct session *s)
|
|||||||
void
|
void
|
||||||
server_lock_client(struct client *c)
|
server_lock_client(struct client *c)
|
||||||
{
|
{
|
||||||
const char *cmd;
|
const char *cmd;
|
||||||
size_t cmdlen;
|
|
||||||
struct msg_lock_data lockdata;
|
|
||||||
|
|
||||||
if (c->flags & CLIENT_CONTROL)
|
if (c->flags & CLIENT_CONTROL)
|
||||||
return;
|
return;
|
||||||
@ -246,8 +244,7 @@ server_lock_client(struct client *c)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
cmd = options_get_string(&c->session->options, "lock-command");
|
cmd = options_get_string(&c->session->options, "lock-command");
|
||||||
cmdlen = strlcpy(lockdata.cmd, cmd, sizeof lockdata.cmd);
|
if (strlen(cmd) + 1 > MAX_IMSGSIZE - IMSG_HEADER_SIZE)
|
||||||
if (cmdlen >= sizeof lockdata.cmd)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tty_stop_tty(&c->tty);
|
tty_stop_tty(&c->tty);
|
||||||
@ -256,7 +253,7 @@ server_lock_client(struct client *c)
|
|||||||
tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_E3));
|
tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_E3));
|
||||||
|
|
||||||
c->flags |= CLIENT_SUSPENDED;
|
c->flags |= CLIENT_SUSPENDED;
|
||||||
server_write_client(c, MSG_LOCK, &lockdata, sizeof lockdata);
|
server_write_client(c, MSG_LOCK, cmd, strlen(cmd) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
82
tmux.h
82
tmux.h
@ -19,7 +19,7 @@
|
|||||||
#ifndef TMUX_H
|
#ifndef TMUX_H
|
||||||
#define TMUX_H
|
#define TMUX_H
|
||||||
|
|
||||||
#define PROTOCOL_VERSION 7
|
#define PROTOCOL_VERSION 8
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -62,7 +62,6 @@ extern char **environ;
|
|||||||
* Maximum sizes of strings in message data. Don't forget to bump
|
* Maximum sizes of strings in message data. Don't forget to bump
|
||||||
* PROTOCOL_VERSION if any of these change!
|
* PROTOCOL_VERSION if any of these change!
|
||||||
*/
|
*/
|
||||||
#define COMMAND_LENGTH 2048 /* packed argv size */
|
|
||||||
#define TERMINAL_LENGTH 128 /* length of TERM environment variable */
|
#define TERMINAL_LENGTH 128 /* length of TERM environment variable */
|
||||||
#define ENVIRON_LENGTH 1024 /* environment variable length */
|
#define ENVIRON_LENGTH 1024 /* environment variable length */
|
||||||
|
|
||||||
@ -437,27 +436,36 @@ ARRAY_DECL(causelist, char *);
|
|||||||
|
|
||||||
/* Message codes. */
|
/* Message codes. */
|
||||||
enum msgtype {
|
enum msgtype {
|
||||||
MSG_COMMAND,
|
MSG_VERSION = 12,
|
||||||
|
|
||||||
|
MSG_IDENTIFY_FLAGS = 100,
|
||||||
|
MSG_IDENTIFY_TERM,
|
||||||
|
MSG_IDENTIFY_TTYNAME,
|
||||||
|
MSG_IDENTIFY_CWD,
|
||||||
|
MSG_IDENTIFY_STDIN,
|
||||||
|
MSG_IDENTIFY_ENVIRON,
|
||||||
|
MSG_IDENTIFY_DONE,
|
||||||
|
|
||||||
|
MSG_COMMAND = 200,
|
||||||
MSG_DETACH,
|
MSG_DETACH,
|
||||||
MSG_ERROR,
|
MSG_DETACHKILL,
|
||||||
MSG_EXIT,
|
MSG_EXIT,
|
||||||
MSG_EXITED,
|
MSG_EXITED,
|
||||||
MSG_EXITING,
|
MSG_EXITING,
|
||||||
MSG_IDENTIFY,
|
MSG_LOCK,
|
||||||
MSG_STDIN,
|
|
||||||
MSG_READY,
|
MSG_READY,
|
||||||
MSG_RESIZE,
|
MSG_RESIZE,
|
||||||
MSG_SHUTDOWN,
|
|
||||||
MSG_SUSPEND,
|
|
||||||
MSG_VERSION,
|
|
||||||
MSG_WAKEUP,
|
|
||||||
MSG_ENVIRON,
|
|
||||||
MSG_UNLOCK,
|
|
||||||
MSG_LOCK,
|
|
||||||
MSG_SHELL,
|
MSG_SHELL,
|
||||||
|
MSG_SHUTDOWN,
|
||||||
MSG_STDERR,
|
MSG_STDERR,
|
||||||
|
MSG_STDIN,
|
||||||
MSG_STDOUT,
|
MSG_STDOUT,
|
||||||
MSG_DETACHKILL
|
MSG_SUSPEND,
|
||||||
|
MSG_UNLOCK,
|
||||||
|
MSG_WAKEUP,
|
||||||
|
|
||||||
|
MSG_IDENTIFY = 300,
|
||||||
|
MSG_ENVIRON
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -466,42 +474,23 @@ enum msgtype {
|
|||||||
* Don't forget to bump PROTOCOL_VERSION if any of these change!
|
* Don't forget to bump PROTOCOL_VERSION if any of these change!
|
||||||
*/
|
*/
|
||||||
struct msg_command_data {
|
struct msg_command_data {
|
||||||
pid_t pid; /* from $TMUX or -1 */
|
pid_t pid; /* from $TMUX or -1 */
|
||||||
int session_id; /* from $TMUX or -1 */
|
int session_id; /* from $TMUX or -1 */
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
char argv[COMMAND_LENGTH];
|
}; /* followed by packed argv */
|
||||||
};
|
|
||||||
|
|
||||||
struct msg_identify_data {
|
struct msg_identify_data {
|
||||||
char cwd[MAXPATHLEN];
|
char cwd[MAXPATHLEN];
|
||||||
|
|
||||||
char term[TERMINAL_LENGTH];
|
char term[TERMINAL_LENGTH];
|
||||||
|
|
||||||
#define IDENTIFY_UTF8 0x1
|
|
||||||
#define IDENTIFY_256COLOURS 0x2
|
|
||||||
/* 0x4 unused */
|
|
||||||
#define IDENTIFY_CONTROL 0x8
|
|
||||||
#define IDENTIFY_TERMIOS 0x10
|
|
||||||
int flags;
|
int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct msg_lock_data {
|
|
||||||
char cmd[COMMAND_LENGTH];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct msg_environ_data {
|
struct msg_environ_data {
|
||||||
char var[ENVIRON_LENGTH];
|
char var[ENVIRON_LENGTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct msg_shell_data {
|
|
||||||
char shell[MAXPATHLEN];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct msg_exit_data {
|
|
||||||
int retcode;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct msg_stdin_data {
|
struct msg_stdin_data {
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
char data[BUFSIZ];
|
char data[BUFSIZ];
|
||||||
@ -1294,8 +1283,9 @@ RB_HEAD(status_out_tree, status_out);
|
|||||||
/* Client connection. */
|
/* Client connection. */
|
||||||
struct client {
|
struct client {
|
||||||
struct imsgbuf ibuf;
|
struct imsgbuf ibuf;
|
||||||
|
|
||||||
struct event event;
|
struct event event;
|
||||||
int retcode;
|
int retval;
|
||||||
|
|
||||||
struct timeval creation_time;
|
struct timeval creation_time;
|
||||||
struct timeval activity_time;
|
struct timeval activity_time;
|
||||||
@ -1326,7 +1316,7 @@ struct client {
|
|||||||
#define CLIENT_EXIT 0x4
|
#define CLIENT_EXIT 0x4
|
||||||
#define CLIENT_REDRAW 0x8
|
#define CLIENT_REDRAW 0x8
|
||||||
#define CLIENT_STATUS 0x10
|
#define CLIENT_STATUS 0x10
|
||||||
#define CLIENT_REPEAT 0x20 /* allow command to repeat within repeat time */
|
#define CLIENT_REPEAT 0x20
|
||||||
#define CLIENT_SUSPENDED 0x40
|
#define CLIENT_SUSPENDED 0x40
|
||||||
#define CLIENT_BAD 0x80
|
#define CLIENT_BAD 0x80
|
||||||
#define CLIENT_IDENTIFY 0x100
|
#define CLIENT_IDENTIFY 0x100
|
||||||
@ -1335,7 +1325,11 @@ struct client {
|
|||||||
#define CLIENT_READONLY 0x800
|
#define CLIENT_READONLY 0x800
|
||||||
#define CLIENT_REDRAWWINDOW 0x1000
|
#define CLIENT_REDRAWWINDOW 0x1000
|
||||||
#define CLIENT_CONTROL 0x2000
|
#define CLIENT_CONTROL 0x2000
|
||||||
#define CLIENT_FOCUSED 0x4000
|
#define CLIENT_CONTROLCONTROL 0x4000
|
||||||
|
#define CLIENT_FOCUSED 0x8000
|
||||||
|
#define CLIENT_UTF8 0x10000
|
||||||
|
#define CLIENT_256COLOURS 0x20000
|
||||||
|
#define CLIENT_IDENTIFIED 0x40000
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
struct event identify_timer;
|
struct event identify_timer;
|
||||||
@ -1925,10 +1919,10 @@ void server_window_loop(void);
|
|||||||
/* server-fn.c */
|
/* server-fn.c */
|
||||||
void server_fill_environ(struct session *, struct environ *);
|
void server_fill_environ(struct session *, struct environ *);
|
||||||
void server_write_ready(struct client *);
|
void server_write_ready(struct client *);
|
||||||
int server_write_client(
|
int server_write_client(struct client *, enum msgtype, const void *,
|
||||||
struct client *, enum msgtype, const void *, size_t);
|
size_t);
|
||||||
void server_write_session(
|
void server_write_session(struct session *, enum msgtype, const void *,
|
||||||
struct session *, enum msgtype, const void *, size_t);
|
size_t);
|
||||||
void server_redraw_client(struct client *);
|
void server_redraw_client(struct client *);
|
||||||
void server_status_client(struct client *);
|
void server_status_client(struct client *);
|
||||||
void server_redraw_session(struct session *);
|
void server_redraw_session(struct session *);
|
||||||
|
Loading…
Reference in New Issue
Block a user