summaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-27 10:16:42 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-28 13:00:39 -0800
commitfd343bea7f11796a9fba77158fe84b0ccaac1a4b (patch)
tree99cb58bf5dab59f06afa5cf929d3cc3bc9d907f8 /src/helper
parent933b4579f06d25e349e6648ec4aff114e634164d (diff)
downloadopenocd_libswd-fd343bea7f11796a9fba77158fe84b0ccaac1a4b.tar.gz
openocd_libswd-fd343bea7f11796a9fba77158fe84b0ccaac1a4b.tar.bz2
openocd_libswd-fd343bea7f11796a9fba77158fe84b0ccaac1a4b.tar.xz
openocd_libswd-fd343bea7f11796a9fba77158fe84b0ccaac1a4b.zip
refactor command mode detection
Splits the check for a command's ability to run into a helper. This also fixes a bug whereby commands that specified COMMAND_EXEC were allowed to run during the configuration stage. This allowed problematic commands to be called before 'init', defeating the intention of specifying that command mode. With this change, the run_command() helper denies access to handlers that should run only after 'init' during the configuration stage.
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/command.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index b2aa76b0..3f439426 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -525,13 +525,18 @@ char *command_name(struct command *c, char delim)
return __command_name(c, delim, 0);
}
+static bool command_can_run(struct command_context *cmd_ctx, struct command *c)
+{
+ return c->mode == COMMAND_ANY || c->mode == cmd_ctx->mode;
+}
+
static int run_command(struct command_context *context,
struct command *c, const char *words[], unsigned num_words)
{
- if (!((context->mode == COMMAND_CONFIG) || (c->mode == COMMAND_ANY) || (c->mode == context->mode)))
+ if (!command_can_run(context, c))
{
/* Config commands can not run after the config stage */
- LOG_ERROR("Command '%s' only runs during configuration stage", c->name);
+ LOG_ERROR("The '%s' command must be used before 'init'.", c->name);
return ERROR_FAIL;
}