refactor command mode detection
authorZachary T Welch <zw@superlucidity.net>
Fri, 27 Nov 2009 18:16:42 +0000 (10:16 -0800)
committerZachary T Welch <zw@superlucidity.net>
Sat, 28 Nov 2009 21:00:39 +0000 (13:00 -0800)
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.

src/helper/command.c

index b2aa76b0b9e0ba00e0236f94913e975e29f35464..3f439426a1764fba9e977cef3fcc176e6729f04d 100644 (file)
@@ -525,13 +525,18 @@ char *command_name(struct command *c, char delim)
        return __command_name(c, delim, 0);
 }
 
        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)
 {
 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 */
        {
                /* 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;
        }
 
                return ERROR_FAIL;
        }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)