From ee45a8a149e1a3c8fe7c232a9e32f3a007e21bee Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 22 Apr 2017 10:22:39 +0000 Subject: Get rid of the extra layer of flags and cmd_prepare() and just store the CMD_FIND_* flags in the cmd_entry and call it for the command. Commands with special requirements call it themselves and update the target for hooks to use. --- cmd-detach-client.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'cmd-detach-client.c') diff --git a/cmd-detach-client.c b/cmd-detach-client.c index 2e21f795..85b9a4ed 100644 --- a/cmd-detach-client.c +++ b/cmd-detach-client.c @@ -37,8 +37,7 @@ const struct cmd_entry cmd_detach_client_entry = { .usage = "[-aP] [-E shell-command] " "[-s target-session] " CMD_TARGET_CLIENT_USAGE, - .sflag = CMD_SESSION, - .tflag = CMD_CLIENT, + .source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, .flags = CMD_READONLY, .exec = cmd_detach_client_exec @@ -51,8 +50,6 @@ const struct cmd_entry cmd_suspend_client_entry = { .args = { "t:", 0, 0 }, .usage = CMD_TARGET_CLIENT_USAGE, - .tflag = CMD_CLIENT, - .flags = 0, .exec = cmd_detach_client_exec }; @@ -61,11 +58,14 @@ static enum cmd_retval cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = item->state.c, *cloop; + struct client *c, *cloop; struct session *s; enum msgtype msgtype; const char *cmd = args_get(args, 'E'); + if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) + return (CMD_RETURN_ERROR); + if (self->entry == &cmd_suspend_client_entry) { server_client_suspend(c); return (CMD_RETURN_NORMAL); @@ -77,7 +77,9 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item) msgtype = MSG_DETACH; if (args_has(args, 's')) { - s = item->state.sflag.s; + s = item->source.s; + if (s == NULL) + return (CMD_RETURN_NORMAL); TAILQ_FOREACH(cloop, &clients, entry) { if (cloop->session == s) { if (cmd != NULL) -- cgit v1.2.3