command: check command mode for native jim commands 41/4841/2
authorTomas Vanek <vanekt@fbl.cz>
Wed, 9 Jan 2019 11:55:51 +0000 (12:55 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Sun, 27 Jan 2019 20:59:42 +0000 (20:59 +0000)
The command mode was checked only for simple type of commands.
Native commands (handled by jim_handler) was treated as
they had mode COMMAND_ANY

Change-Id: Iab1d8cbb0b8c6f6b9f3cf942600432dec9a703ff
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4841
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/helper/command.c

index 1ff4e01a7d1a5d51c4cf1cd26ed8d394bec43eb8..0afbe2ccf2d6b135cd7d5b65854d706998fdd527 100644 (file)
@@ -579,31 +579,35 @@ char *command_name(struct command *c, char delim)
 
 static bool command_can_run(struct command_context *cmd_ctx, struct command *c)
 {
-       return c->mode == COMMAND_ANY || c->mode == cmd_ctx->mode;
+       if (c->mode == COMMAND_ANY || c->mode == cmd_ctx->mode)
+               return true;
+
+       /* Many commands may be run only before/after 'init' */
+       const char *when;
+       switch (c->mode) {
+               case COMMAND_CONFIG:
+                       when = "before";
+                       break;
+               case COMMAND_EXEC:
+                       when = "after";
+                       break;
+               /* handle the impossible with humor; it guarantees a bug report! */
+               default:
+                       when = "if Cthulhu is summoned by";
+                       break;
+       }
+       char *full_name = command_name(c, ' ');
+       LOG_ERROR("The '%s' command must be used %s 'init'.",
+                       full_name ? full_name : c->name, when);
+       free(full_name);
+       return false;
 }
 
 static int run_command(struct command_context *context,
        struct command *c, const char *words[], unsigned num_words)
 {
-       if (!command_can_run(context, c)) {
-               /* Many commands may be run only before/after 'init' */
-               const char *when;
-               switch (c->mode) {
-                       case COMMAND_CONFIG:
-                               when = "before";
-                               break;
-                       case COMMAND_EXEC:
-                               when = "after";
-                               break;
-                       /* handle the impossible with humor; it guarantees a bug report! */
-                       default:
-                               when = "if Cthulhu is summoned by";
-                               break;
-               }
-               LOG_ERROR("The '%s' command must be used %s 'init'.",
-                       c->name, when);
+       if (!command_can_run(context, c))
                return ERROR_FAIL;
-       }
 
        struct command_invocation cmd = {
                .ctx = context,
@@ -1032,6 +1036,9 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        }
        /* pass the command through to the intended handler */
        if (c->jim_handler) {
+               if (!command_can_run(cmd_ctx, c))
+                       return ERROR_FAIL;
+
                interp->cmdPrivData = c->jim_handler_data;
                return (*c->jim_handler)(interp, count, start);
        }

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)