mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-08 09:14:22 +01:00
Pass current directory as a string rather than a file descriptor because
pledge doesn't let us pass directory file descriptors.
This commit is contained in:
parent
9c601ebde8
commit
174a2ad731
18
client.c
18
client.c
@ -55,7 +55,7 @@ int client_attached;
|
|||||||
__dead void client_exec(const char *);
|
__dead void client_exec(const char *);
|
||||||
int client_get_lock(char *);
|
int client_get_lock(char *);
|
||||||
int client_connect(struct event_base *, char *, int);
|
int client_connect(struct event_base *, char *, int);
|
||||||
void client_send_identify(const char *, int);
|
void client_send_identify(const char *, const char *);
|
||||||
int client_write_one(enum msgtype, int, const void *, size_t);
|
int client_write_one(enum msgtype, int, const void *, size_t);
|
||||||
int client_write_server(enum msgtype, const void *, size_t);
|
int client_write_server(enum msgtype, const void *, size_t);
|
||||||
void client_update_event(void);
|
void client_update_event(void);
|
||||||
@ -214,11 +214,11 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
struct msg_command_data *data;
|
struct msg_command_data *data;
|
||||||
int cmdflags, fd, i, cwd;
|
int cmdflags, fd, i;
|
||||||
const char* ttynam;
|
const char *ttynam, *cwd;
|
||||||
pid_t ppid;
|
pid_t ppid;
|
||||||
enum msgtype msg;
|
enum msgtype msg;
|
||||||
char *cause;
|
char *cause, path[PATH_MAX];
|
||||||
struct termios tio, saved_tio;
|
struct termios tio, saved_tio;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
@ -275,8 +275,8 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Save these before pledge(). */
|
/* Save these before pledge(). */
|
||||||
if ((cwd = open(".", O_RDONLY)) == -1)
|
if ((cwd = getcwd(path, sizeof path)) == NULL)
|
||||||
cwd = open("/", O_RDONLY);
|
cwd = "/";
|
||||||
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
||||||
ttynam = "";
|
ttynam = "";
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Send identify messages. */
|
/* Send identify messages. */
|
||||||
client_send_identify(ttynam, cwd); /* closes cwd */
|
client_send_identify(ttynam, cwd);
|
||||||
|
|
||||||
/* Send first command. */
|
/* Send first command. */
|
||||||
if (msg == MSG_COMMAND) {
|
if (msg == MSG_COMMAND) {
|
||||||
@ -380,7 +380,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
|
|
||||||
/* Send identify messages to server. */
|
/* Send identify messages to server. */
|
||||||
void
|
void
|
||||||
client_send_identify(const char *ttynam, int cwd)
|
client_send_identify(const char *ttynam, const char *cwd)
|
||||||
{
|
{
|
||||||
const char *s;
|
const char *s;
|
||||||
char **ss;
|
char **ss;
|
||||||
@ -395,7 +395,7 @@ client_send_identify(const char *ttynam, int cwd)
|
|||||||
client_write_one(MSG_IDENTIFY_TERM, -1, s, strlen(s) + 1);
|
client_write_one(MSG_IDENTIFY_TERM, -1, s, strlen(s) + 1);
|
||||||
|
|
||||||
client_write_one(MSG_IDENTIFY_TTYNAME, -1, ttynam, strlen(ttynam) + 1);
|
client_write_one(MSG_IDENTIFY_TTYNAME, -1, ttynam, strlen(ttynam) + 1);
|
||||||
client_write_one(MSG_IDENTIFY_CWD, cwd, NULL, 0);
|
client_write_one(MSG_IDENTIFY_CWD, -1, cwd, strlen(cwd) + 1);
|
||||||
|
|
||||||
if ((fd = dup(STDIN_FILENO)) == -1)
|
if ((fd = dup(STDIN_FILENO)) == -1)
|
||||||
fatal("dup failed");
|
fatal("dup failed");
|
||||||
|
@ -1166,9 +1166,10 @@ server_client_msg_identify(struct client *c, struct imsg *imsg)
|
|||||||
c->ttyname = xstrdup(data);
|
c->ttyname = xstrdup(data);
|
||||||
break;
|
break;
|
||||||
case MSG_IDENTIFY_CWD:
|
case MSG_IDENTIFY_CWD:
|
||||||
if (datalen != 0)
|
if (datalen == 0 || data[datalen - 1] != '\0')
|
||||||
fatalx("bad MSG_IDENTIFY_CWD size");
|
fatalx("bad MSG_IDENTIFY_CWD string");
|
||||||
c->cwd = imsg->fd;
|
if ((c->cwd = open(data, O_RDONLY)) == -1)
|
||||||
|
c->cwd = open("/", O_RDONLY);
|
||||||
break;
|
break;
|
||||||
case MSG_IDENTIFY_STDIN:
|
case MSG_IDENTIFY_STDIN:
|
||||||
if (datalen != 0)
|
if (datalen != 0)
|
||||||
|
3
tmux.h
3
tmux.h
@ -395,11 +395,12 @@ enum msgtype {
|
|||||||
MSG_IDENTIFY_FLAGS = 100,
|
MSG_IDENTIFY_FLAGS = 100,
|
||||||
MSG_IDENTIFY_TERM,
|
MSG_IDENTIFY_TERM,
|
||||||
MSG_IDENTIFY_TTYNAME,
|
MSG_IDENTIFY_TTYNAME,
|
||||||
MSG_IDENTIFY_CWD,
|
MSG_IDENTIFY_OLDCWD, /* unused */
|
||||||
MSG_IDENTIFY_STDIN,
|
MSG_IDENTIFY_STDIN,
|
||||||
MSG_IDENTIFY_ENVIRON,
|
MSG_IDENTIFY_ENVIRON,
|
||||||
MSG_IDENTIFY_DONE,
|
MSG_IDENTIFY_DONE,
|
||||||
MSG_IDENTIFY_CLIENTPID,
|
MSG_IDENTIFY_CLIENTPID,
|
||||||
|
MSG_IDENTIFY_CWD,
|
||||||
|
|
||||||
MSG_COMMAND = 200,
|
MSG_COMMAND = 200,
|
||||||
MSG_DETACH,
|
MSG_DETACH,
|
||||||
|
Loading…
Reference in New Issue
Block a user