diff --git a/options.c b/options.c index f39fbf2a..bfbec5c7 100644 --- a/options.c +++ b/options.c @@ -749,7 +749,7 @@ options_get_number(struct options *oo, const char *name) return (o->value.number); } -const struct cmd_list * +struct cmd_list * options_get_command(struct options *oo, const char *name) { struct options_entry *o; diff --git a/server-client.c b/server-client.c index 1c41870f..6881a141 100644 --- a/server-client.c +++ b/server-client.c @@ -3443,6 +3443,24 @@ server_client_read_only(struct cmdq_item *item, __unused void *data) return (CMD_RETURN_ERROR); } +/* Callback for default command. */ +static enum cmd_retval +server_client_default_command(struct cmdq_item *item, __unused void *data) +{ + struct client *c = cmdq_get_client(item); + struct cmd_list *cmdlist; + struct cmdq_item *new_item; + + cmdlist = options_get_command(global_options, "default-client-command"); + if ((c->flags & CLIENT_READONLY) && + !cmd_list_all_have(cmdlist, CMD_READONLY)) + new_item = cmdq_get_callback(server_client_read_only, NULL); + else + new_item = cmdq_get_command(cmdlist, NULL); + cmdq_insert_after(item, new_item); + return (CMD_RETURN_NORMAL); +} + /* Callback when command is done. */ static enum cmd_retval server_client_command_done(struct cmdq_item *item, __unused void *data) @@ -3471,7 +3489,6 @@ server_client_dispatch_command(struct client *c, struct imsg *imsg) struct cmd_parse_result *pr; struct args_value *values; struct cmdq_item *new_item; - struct cmd_list *cmdlist; if (c->flags & CLIENT_EXIT) return (0); @@ -3492,8 +3509,8 @@ server_client_dispatch_command(struct client *c, struct imsg *imsg) argc = data.argc; if (argc == 0) { - cmdlist = cmd_list_copy(options_get_command(global_options, - "default-client-command"), 0, NULL); + new_item = cmdq_get_callback(server_client_default_command, + NULL); } else { values = args_from_vector(argc, argv); pr = cmd_parse_from_arguments(values, argc, NULL); @@ -3507,18 +3524,17 @@ server_client_dispatch_command(struct client *c, struct imsg *imsg) args_free_values(values, argc); free(values); cmd_free_argv(argc, argv); - cmdlist = pr->cmdlist; + if ((c->flags & CLIENT_READONLY) && + !cmd_list_all_have(pr->cmdlist, CMD_READONLY)) { + new_item = cmdq_get_callback(server_client_read_only, + NULL); + } else + new_item = cmdq_get_command(pr->cmdlist, NULL); + cmd_list_free(pr->cmdlist); } - - if ((c->flags & CLIENT_READONLY) && - !cmd_list_all_have(cmdlist, CMD_READONLY)) - new_item = cmdq_get_callback(server_client_read_only, NULL); - else - new_item = cmdq_get_command(cmdlist, NULL); cmdq_append(c, new_item); cmdq_append(c, cmdq_get_callback(server_client_command_done, NULL)); - cmd_list_free(cmdlist); return (0); error: diff --git a/tmux.h b/tmux.h index bcd24f1f..f1e769d1 100644 --- a/tmux.h +++ b/tmux.h @@ -2438,7 +2438,7 @@ struct options_entry *options_match_get(struct options *, const char *, int *, int, int *); const char *options_get_string(struct options *, const char *); long long options_get_number(struct options *, const char *); -const struct cmd_list *options_get_command(struct options *, const char *); +struct cmd_list *options_get_command(struct options *, const char *); struct options_entry * printflike(4, 5) options_set_string(struct options *, const char *, int, const char *, ...); struct options_entry *options_set_number(struct options *, const char *,