mirror of
https://github.com/tmux/tmux.git
synced 2025-09-08 23:24:18 +00:00
Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@. This includes another protocol version increase (the last for now) so again restart the tmux server before upgrading.
This commit is contained in:
25
server-msg.c
25
server-msg.c
@ -20,6 +20,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <paths.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@ -29,6 +30,7 @@
|
||||
|
||||
void server_msg_command(struct client *, struct msg_command_data *);
|
||||
void server_msg_identify(struct client *, struct msg_identify_data *, int);
|
||||
void server_msg_shell(struct client *);
|
||||
|
||||
void printflike2 server_msg_command_error(struct cmd_ctx *, const char *, ...);
|
||||
void printflike2 server_msg_command_print(struct cmd_ctx *, const char *, ...);
|
||||
@ -113,6 +115,12 @@ server_msg_dispatch(struct client *c)
|
||||
if (strchr(environdata.var, '=') != NULL)
|
||||
environ_put(&c->environ, environdata.var);
|
||||
break;
|
||||
case MSG_SHELL:
|
||||
if (datalen != 0)
|
||||
fatalx("bad MSG_SHELL size");
|
||||
|
||||
server_msg_shell(c);
|
||||
break;
|
||||
default:
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
@ -248,3 +256,20 @@ server_msg_identify(struct client *c, struct msg_identify_data *data, int fd)
|
||||
|
||||
c->flags |= CLIENT_TERMINAL;
|
||||
}
|
||||
|
||||
void
|
||||
server_msg_shell(struct client *c)
|
||||
{
|
||||
struct msg_shell_data data;
|
||||
const char *shell;
|
||||
|
||||
shell = options_get_string(&global_s_options, "default-shell");
|
||||
|
||||
if (*shell == '\0' || areshell(shell))
|
||||
shell = _PATH_BSHELL;
|
||||
if (strlcpy(data.shell, shell, sizeof data.shell) >= sizeof data.shell)
|
||||
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 */
|
||||
}
|
||||
|
Reference in New Issue
Block a user