mirror of
https://github.com/tmux/tmux.git
synced 2025-01-13 03:48:51 +00:00
Shell command from -c doesn't have to be global, pass it as an argument.
This commit is contained in:
parent
dca93c56e0
commit
3ff46b2e43
26
client.c
26
client.c
@ -53,7 +53,7 @@ enum msgtype client_exittype;
|
|||||||
const char *client_exitsession;
|
const char *client_exitsession;
|
||||||
int client_attached;
|
int client_attached;
|
||||||
|
|
||||||
__dead void client_exec(const char *);
|
__dead void client_exec(const char *,const char *);
|
||||||
int client_get_lock(char *);
|
int client_get_lock(char *);
|
||||||
int client_connect(struct event_base *, const char *, int);
|
int client_connect(struct event_base *, const char *, int);
|
||||||
void client_send_identify(const char *, const char *);
|
void client_send_identify(const char *, const char *);
|
||||||
@ -62,7 +62,7 @@ void client_write(int, const char *, size_t);
|
|||||||
void client_signal(int);
|
void client_signal(int);
|
||||||
void client_dispatch(struct imsg *, void *);
|
void client_dispatch(struct imsg *, void *);
|
||||||
void client_dispatch_attached(struct imsg *);
|
void client_dispatch_attached(struct imsg *);
|
||||||
void client_dispatch_wait(struct imsg *);
|
void client_dispatch_wait(struct imsg *, const char *);
|
||||||
const char *client_exit_message(void);
|
const char *client_exit_message(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -213,7 +213,8 @@ client_exit_message(void)
|
|||||||
|
|
||||||
/* Client main loop. */
|
/* Client main loop. */
|
||||||
int
|
int
|
||||||
client_main(struct event_base *base, int argc, char **argv, int flags)
|
client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||||
|
const char *shellcmd)
|
||||||
{
|
{
|
||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
@ -234,7 +235,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
|
|
||||||
/* Set up the initial command. */
|
/* Set up the initial command. */
|
||||||
cmdflags = 0;
|
cmdflags = 0;
|
||||||
if (shell_cmd != NULL) {
|
if (shellcmd != NULL) {
|
||||||
msg = MSG_SHELL;
|
msg = MSG_SHELL;
|
||||||
cmdflags = CMD_STARTSERVER;
|
cmdflags = CMD_STARTSERVER;
|
||||||
} else if (argc == 0) {
|
} else if (argc == 0) {
|
||||||
@ -276,7 +277,8 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
|||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
client_peer = proc_add_peer(client_proc, fd, client_dispatch, NULL);
|
client_peer = proc_add_peer(client_proc, fd, client_dispatch,
|
||||||
|
(void *)shellcmd);
|
||||||
|
|
||||||
/* Save these before pledge(). */
|
/* Save these before pledge(). */
|
||||||
if ((cwd = getcwd(path, sizeof path)) == NULL) {
|
if ((cwd = getcwd(path, sizeof path)) == NULL) {
|
||||||
@ -450,12 +452,12 @@ client_write(int fd, const char *data, size_t size)
|
|||||||
|
|
||||||
/* Run command in shell; used for -c. */
|
/* Run command in shell; used for -c. */
|
||||||
__dead void
|
__dead void
|
||||||
client_exec(const char *shell)
|
client_exec(const char *shell, const char *shellcmd)
|
||||||
{
|
{
|
||||||
const char *name, *ptr;
|
const char *name, *ptr;
|
||||||
char *argv0;
|
char *argv0;
|
||||||
|
|
||||||
log_debug("shell %s, command %s", shell, shell_cmd);
|
log_debug("shell %s, command %s", shell, shellcmd);
|
||||||
|
|
||||||
ptr = strrchr(shell, '/');
|
ptr = strrchr(shell, '/');
|
||||||
if (ptr != NULL && *(ptr + 1) != '\0')
|
if (ptr != NULL && *(ptr + 1) != '\0')
|
||||||
@ -473,7 +475,7 @@ client_exec(const char *shell)
|
|||||||
setblocking(STDERR_FILENO, 1);
|
setblocking(STDERR_FILENO, 1);
|
||||||
closefrom(STDERR_FILENO + 1);
|
closefrom(STDERR_FILENO + 1);
|
||||||
|
|
||||||
execl(shell, argv0, "-c", shell_cmd, (char *) NULL);
|
execl(shell, argv0, "-c", shellcmd, (char *) NULL);
|
||||||
fatal("execl failed");
|
fatal("execl failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,7 +521,7 @@ client_signal(int sig)
|
|||||||
|
|
||||||
/* Callback for client read events. */
|
/* Callback for client read events. */
|
||||||
void
|
void
|
||||||
client_dispatch(struct imsg *imsg, __unused void *arg)
|
client_dispatch(struct imsg *imsg, void *arg)
|
||||||
{
|
{
|
||||||
if (imsg == NULL) {
|
if (imsg == NULL) {
|
||||||
client_exitreason = CLIENT_EXIT_LOST_SERVER;
|
client_exitreason = CLIENT_EXIT_LOST_SERVER;
|
||||||
@ -531,12 +533,12 @@ client_dispatch(struct imsg *imsg, __unused void *arg)
|
|||||||
if (client_attached)
|
if (client_attached)
|
||||||
client_dispatch_attached(imsg);
|
client_dispatch_attached(imsg);
|
||||||
else
|
else
|
||||||
client_dispatch_wait(imsg);
|
client_dispatch_wait(imsg, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||||
void
|
void
|
||||||
client_dispatch_wait(struct imsg *imsg)
|
client_dispatch_wait(struct imsg *imsg, const char *shellcmd)
|
||||||
{
|
{
|
||||||
char *data;
|
char *data;
|
||||||
ssize_t datalen;
|
ssize_t datalen;
|
||||||
@ -616,7 +618,7 @@ client_dispatch_wait(struct imsg *imsg)
|
|||||||
fatalx("bad MSG_SHELL string");
|
fatalx("bad MSG_SHELL string");
|
||||||
|
|
||||||
clear_signals(0);
|
clear_signals(0);
|
||||||
client_exec(data);
|
client_exec(data, shellcmd);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case MSG_DETACH:
|
case MSG_DETACH:
|
||||||
case MSG_DETACHKILL:
|
case MSG_DETACHKILL:
|
||||||
|
11
tmux.c
11
tmux.c
@ -39,7 +39,6 @@ struct options *global_s_options; /* session options */
|
|||||||
struct options *global_w_options; /* window options */
|
struct options *global_w_options; /* window options */
|
||||||
struct environ *global_environ;
|
struct environ *global_environ;
|
||||||
|
|
||||||
char *shell_cmd;
|
|
||||||
struct timeval start_time;
|
struct timeval start_time;
|
||||||
const char *socket_path;
|
const char *socket_path;
|
||||||
|
|
||||||
@ -184,7 +183,7 @@ find_home(void)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *path, *label, **var, tmp[PATH_MAX];
|
char *path, *label, **var, tmp[PATH_MAX], *shellcmd = NULL;
|
||||||
const char *s;
|
const char *s;
|
||||||
int opt, flags, keys;
|
int opt, flags, keys;
|
||||||
|
|
||||||
@ -203,8 +202,8 @@ main(int argc, char **argv)
|
|||||||
flags |= CLIENT_256COLOURS;
|
flags |= CLIENT_256COLOURS;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
free(shell_cmd);
|
free(shellcmd);
|
||||||
shell_cmd = xstrdup(optarg);
|
shellcmd = xstrdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
if (flags & CLIENT_CONTROL)
|
if (flags & CLIENT_CONTROL)
|
||||||
@ -241,7 +240,7 @@ main(int argc, char **argv)
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
if (shell_cmd != NULL && argc != 0)
|
if (shellcmd != NULL && argc != 0)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (pledge("stdio rpath wpath cpath flock fattr unix getpw sendfd "
|
if (pledge("stdio rpath wpath cpath flock fattr unix getpw sendfd "
|
||||||
@ -318,5 +317,5 @@ main(int argc, char **argv)
|
|||||||
free(label);
|
free(label);
|
||||||
|
|
||||||
/* Pass control to the client. */
|
/* Pass control to the client. */
|
||||||
exit(client_main(event_init(), argc, argv, flags));
|
exit(client_main(event_init(), argc, argv, flags, shellcmd));
|
||||||
}
|
}
|
||||||
|
3
tmux.h
3
tmux.h
@ -1431,7 +1431,6 @@ extern struct options *global_options;
|
|||||||
extern struct options *global_s_options;
|
extern struct options *global_s_options;
|
||||||
extern struct options *global_w_options;
|
extern struct options *global_w_options;
|
||||||
extern struct environ *global_environ;
|
extern struct environ *global_environ;
|
||||||
extern char *shell_cmd;
|
|
||||||
extern struct timeval start_time;
|
extern struct timeval start_time;
|
||||||
extern const char *socket_path;
|
extern const char *socket_path;
|
||||||
const char *getshell(void);
|
const char *getshell(void);
|
||||||
@ -1732,7 +1731,7 @@ int cmd_string_parse(const char *, struct cmd_list **, const char *,
|
|||||||
void cmd_wait_for_flush(void);
|
void cmd_wait_for_flush(void);
|
||||||
|
|
||||||
/* client.c */
|
/* client.c */
|
||||||
int client_main(struct event_base *, int, char **, int);
|
int client_main(struct event_base *, int, char **, int, const char *);
|
||||||
|
|
||||||
/* key-bindings.c */
|
/* key-bindings.c */
|
||||||
RB_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
|
RB_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
|
||||||
|
Loading…
Reference in New Issue
Block a user