Merge prepare_cmd into main as it is short and only called once.

This commit is contained in:
Nicholas Marriott 2009-10-22 10:04:07 +00:00
parent 284b94662a
commit eb0c33cba4

36
tmux.c
View File

@ -55,7 +55,6 @@ int login_shell;
__dead void usage(void); __dead void usage(void);
void fill_session(struct msg_command_data *); void fill_session(struct msg_command_data *);
char *makesockpath(const char *); char *makesockpath(const char *);
int prepare_cmd(enum msgtype *, void **, size_t *, int, char **);
int dispatch_imsg(struct imsgbuf *, const char *, int *); int dispatch_imsg(struct imsgbuf *, const char *, int *);
__dead void shell_exec(const char *, const char *); __dead void shell_exec(const char *, const char *);
@ -282,26 +281,6 @@ makesockpath(const char *label)
return (path); return (path);
} }
int
prepare_cmd(enum msgtype *msg, void **buf, size_t *len, int argc, char **argv)
{
static struct msg_command_data cmddata;
fill_session(&cmddata);
cmddata.argc = argc;
if (cmd_pack_argv(argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
log_warnx("command too long");
return (-1);
}
*buf = &cmddata;
*len = sizeof cmddata;
*msg = MSG_COMMAND;
return (0);
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -313,6 +292,7 @@ main(int argc, char **argv)
struct options *so, *wo; struct options *so, *wo;
struct keylist *keylist; struct keylist *keylist;
struct imsgbuf *ibuf; struct imsgbuf *ibuf;
struct msg_command_data cmddata;
char *s, *shellcmd, *path, *label, *home, *cause; char *s, *shellcmd, *path, *label, *home, *cause;
char cwd[MAXPATHLEN], **var; char cwd[MAXPATHLEN], **var;
void *buf; void *buf;
@ -529,8 +509,20 @@ main(int argc, char **argv)
msg = MSG_SHELL; msg = MSG_SHELL;
buf = NULL; buf = NULL;
len = 0; len = 0;
} else if (prepare_cmd(&msg, &buf, &len, argc, argv) != 0) } else {
fill_session(&cmddata);
cmddata.argc = argc;
if (cmd_pack_argv(
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
log_warnx("command too long");
exit(1); exit(1);
}
msg = MSG_COMMAND;
buf = &cmddata;
len = sizeof cmddata;
}
if (shellcmd != NULL) if (shellcmd != NULL)
cmdflags |= CMD_STARTSERVER; cmdflags |= CMD_STARTSERVER;