summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorØyvind Harboe <oyvind.harboe@zylin.com>2011-03-31 13:32:28 +0200
committerØyvind Harboe <oyvind.harboe@zylin.com>2011-03-31 23:46:56 +0200
commit1b9e80f7e6359d59b68a7741c046722bb235a311 (patch)
treef9ae4c2d68a05812e833f282e24f5905d1852a54
parent0c1ebf2673ef02c5fef7677cbf09d4ad4fa3c533 (diff)
downloadopenocd+libswd-1b9e80f7e6359d59b68a7741c046722bb235a311.tar.gz
openocd+libswd-1b9e80f7e6359d59b68a7741c046722bb235a311.tar.bz2
openocd+libswd-1b9e80f7e6359d59b68a7741c046722bb235a311.tar.xz
openocd+libswd-1b9e80f7e6359d59b68a7741c046722bb235a311.zip
startup: fix bugs in cleanup upon errors during startup
Importantly adapter cleanup will now happen upon startup failure. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
-rw-r--r--src/openocd.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/src/openocd.c b/src/openocd.c
index 62b22389..a5002d19 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -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 */