startup: fix bugs in cleanup upon errors during startup
authorØyvind Harboe <oyvind.harboe@zylin.com>
Thu, 31 Mar 2011 11:32:28 +0000 (13:32 +0200)
committerØyvind Harboe <oyvind.harboe@zylin.com>
Thu, 31 Mar 2011 21:46:56 +0000 (23:46 +0200)
Importantly adapter cleanup will now happen upon startup failure.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
src/openocd.c

index 62b22389a9b68fe2fa7d2de6992840ab9043b518..a5002d19268b1f58c167bc18c9acf07002816404 100644 (file)
@@ -301,31 +301,10 @@ struct command_context *setup_command_handler(Jim_Interp *interp)
        return cmd_ctx;
 }
 
-/* normally this is the main() function entry, but if OpenOCD is linked
- * into application, then this fn will not be invoked, but rather that
- * application will have it's own implementation of main(). */
-int openocd_main(int argc, char *argv[])
+static int main2(int argc, char *argv[], struct command_context *cmd_ctx)
 {
        int ret;
 
-       /* initialize commandline interface */
-       struct command_context *cmd_ctx;
-
-       cmd_ctx = setup_command_handler(NULL);
-
-       if (util_init(cmd_ctx) != ERROR_OK)
-               return EXIT_FAILURE;
-
-       if (ioutil_init(cmd_ctx) != ERROR_OK)
-               return EXIT_FAILURE;
-
-       LOG_OUTPUT("For bug reports, read\n\t"
-               "http://openocd.berlios.de/doc/doxygen/bugs.html"
-               "\n");
-
-       command_context_mode(cmd_ctx, COMMAND_CONFIG);
-       command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
-
        if (parse_cmdline_args(cmd_ctx, argc, argv) != ERROR_OK)
                return EXIT_FAILURE;
 
@@ -348,15 +327,43 @@ int openocd_main(int argc, char *argv[])
        {
                ret = command_run_line(cmd_ctx, "init");
                if (ERROR_OK != ret)
-                       ret = EXIT_FAILURE;
+                       return EXIT_FAILURE;
        }
 
-       /* handle network connections */
-       if (ERROR_OK == ret)
-               server_loop(cmd_ctx);
+       server_loop(cmd_ctx);
 
        server_quit();
 
+       return ret;
+}
+
+/* normally this is the main() function entry, but if OpenOCD is linked
+ * into application, then this fn will not be invoked, but rather that
+ * application will have it's own implementation of main(). */
+int openocd_main(int argc, char *argv[])
+{
+       int ret;
+
+       /* initialize commandline interface */
+       struct command_context *cmd_ctx;
+
+       cmd_ctx = setup_command_handler(NULL);
+
+       if (util_init(cmd_ctx) != ERROR_OK)
+               return EXIT_FAILURE;
+
+       if (ioutil_init(cmd_ctx) != ERROR_OK)
+               return EXIT_FAILURE;
+
+       LOG_OUTPUT("For bug reports, read\n\t"
+               "http://openocd.berlios.de/doc/doxygen/bugs.html"
+               "\n");
+
+       command_context_mode(cmd_ctx, COMMAND_CONFIG);
+       command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
+
+       ret = main2(argc, argv, cmd_ctx);
+
        unregister_all_commands(cmd_ctx, NULL);
 
        /* free commandline interface */

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)