diff --git a/src/helper/command.c b/src/helper/command.c index ef0afa2b5..868d0952e 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -118,10 +118,15 @@ static void command_log_capture_finish(struct log_capture_state *state) static int command_retval_set(Jim_Interp *interp, int retval) { int *return_retval = Jim_GetAssocData(interp, "retval"); - if (return_retval != NULL) - *return_retval = retval; - - return (retval == ERROR_OK) ? JIM_OK : JIM_ERR; + if (retval == ERROR_COMMAND_CLOSE_CONNECTION) { + if (return_retval != NULL) + *return_retval = 0; + return JIM_EXIT; + } else { + if (return_retval != NULL) + *return_retval = retval; + return (retval == ERROR_OK) ? JIM_OK : JIM_ERR; + } } extern struct command_context *global_cmd_ctx; @@ -671,8 +676,7 @@ int command_run_line(struct command_context *context, char *line) } return retval; } else if (retcode == JIM_EXIT) { - /* ignore. - * exit(Jim_GetExitCode(interp)); */ + return ERROR_OK_EXIT; } else { const char *result; int reslen; diff --git a/src/helper/log.h b/src/helper/log.h index e161a6ea2..ad8d24795 100644 --- a/src/helper/log.h +++ b/src/helper/log.h @@ -138,5 +138,5 @@ extern int debug_level; * make no assumptions about what went wrong and try to handle the problem. */ #define ERROR_FAIL (-4) - +#define ERROR_OK_EXIT (-5) #endif /* LOG_H */ diff --git a/src/openocd.c b/src/openocd.c index 048ce8524..d06e2c56e 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -279,6 +279,8 @@ static int openocd_thread(int argc, char *argv[], struct command_context *cmd_ct return EXIT_FAILURE; ret = parse_config_file(cmd_ctx); + if (ret == ERROR_OK_EXIT) + return ERROR_OK; if (ret != ERROR_OK) return EXIT_FAILURE;