diff options
author | 2013-03-24 09:54:10 +0000 | |
---|---|---|
committer | 2013-03-24 09:54:10 +0000 | |
commit | 175d36cccd2fcc2eae91dce1d3b4e3f4079aa983 (patch) | |
tree | 916aed045266a229704154541db1b8ab571a9aa2 /usr.bin/tmux/server-client.c | |
parent | Expand format variables in the run-shell and if-shell shell commands, (diff) | |
download | wireguard-openbsd-175d36cccd2fcc2eae91dce1d3b4e3f4079aa983.tar.xz wireguard-openbsd-175d36cccd2fcc2eae91dce1d3b4e3f4079aa983.zip |
Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.
Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.
When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.
Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.
Diffstat (limited to 'usr.bin/tmux/server-client.c')
-rw-r--r-- | usr.bin/tmux/server-client.c | 85 |
1 files changed, 12 insertions, 73 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 56945a18451..88244dbc9e2 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.93 2013/03/24 09:28:59 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.94 2013/03/24 09:54:10 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -45,10 +45,6 @@ void server_client_msg_identify( struct client *, struct msg_identify_data *, int); void server_client_msg_shell(struct client *); -void printflike2 server_client_msg_error(struct cmd_ctx *, const char *, ...); -void printflike2 server_client_msg_print(struct cmd_ctx *, const char *, ...); -void printflike2 server_client_msg_info(struct cmd_ctx *, const char *, ...); - /* Create a new client. */ void server_client_create(int fd) @@ -67,6 +63,9 @@ server_client_create(int fd) fatal("gettimeofday failed"); memcpy(&c->activity_time, &c->creation_time, sizeof c->activity_time); + c->cmdq = cmdq_new(c); + c->cmdq->client_exit = 1; + c->stdin_data = evbuffer_new (); c->stdout_data = evbuffer_new (); c->stderr_data = evbuffer_new (); @@ -181,6 +180,10 @@ server_client_lost(struct client *c) free(c->prompt_buffer); free(c->cwd); + c->cmdq->dead = 1; + cmdq_free(c->cmdq); + c->cmdq = NULL; + environ_free(&c->environ); close(c->ibuf.fd); @@ -901,71 +904,18 @@ server_client_msg_dispatch(struct client *c) } } -/* Callback to send error message to client. */ -void printflike2 -server_client_msg_error(struct cmd_ctx *ctx, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - evbuffer_add_vprintf(ctx->cmdclient->stderr_data, fmt, ap); - va_end(ap); - - evbuffer_add(ctx->cmdclient->stderr_data, "\n", 1); - server_push_stderr(ctx->cmdclient); - ctx->cmdclient->retcode = 1; -} - -/* Callback to send print message to client. */ -void printflike2 -server_client_msg_print(struct cmd_ctx *ctx, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - evbuffer_add_vprintf(ctx->cmdclient->stdout_data, fmt, ap); - va_end(ap); - - evbuffer_add(ctx->cmdclient->stdout_data, "\n", 1); - server_push_stdout(ctx->cmdclient); -} - -/* Callback to send print message to client, if not quiet. */ -void printflike2 -server_client_msg_info(struct cmd_ctx *ctx, const char *fmt, ...) -{ - va_list ap; - - if (options_get_number(&global_options, "quiet")) - return; - - va_start(ap, fmt); - evbuffer_add_vprintf(ctx->cmdclient->stdout_data, fmt, ap); - va_end(ap); - - evbuffer_add(ctx->cmdclient->stdout_data, "\n", 1); - server_push_stdout(ctx->cmdclient); -} - /* Handle command message. */ void server_client_msg_command(struct client *c, struct msg_command_data *data) { - struct cmd_ctx *ctx; struct cmd_list *cmdlist = NULL; int argc; char **argv, *cause; - ctx = cmd_get_ctx(c, NULL); - ctx->msgdata = data; - ctx->error = server_client_msg_error; - ctx->print = server_client_msg_print; - ctx->info = server_client_msg_info; - argc = data->argc; data->argv[(sizeof data->argv) - 1] = '\0'; if (cmd_unpack_argv(data->argv, sizeof data->argv, argc, &argv) != 0) { - server_client_msg_error(ctx, "command too long"); + cmdq_error(c->cmdq, "command too long"); goto error; } @@ -975,31 +925,20 @@ server_client_msg_command(struct client *c, struct msg_command_data *data) *argv = xstrdup("new-session"); } - if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) { - server_client_msg_error(ctx, "%s", cause); + if ((cmdlist = cmd_list_parse(argc, argv, NULL, 0, &cause)) == NULL) { + cmdq_error(c->cmdq, "%s", cause); cmd_free_argv(argc, argv); goto error; } cmd_free_argv(argc, argv); - switch (cmd_list_exec(cmdlist, ctx)) - { - case CMD_RETURN_ERROR: - case CMD_RETURN_NORMAL: - c->flags |= CLIENT_EXIT; - break; - case CMD_RETURN_ATTACH: - case CMD_RETURN_YIELD: - break; - } + cmdq_run(c->cmdq, cmdlist); cmd_list_free(cmdlist); - cmd_free_ctx(ctx); return; error: if (cmdlist != NULL) cmd_list_free(cmdlist); - cmd_free_ctx(ctx); c->flags |= CLIENT_EXIT; } |