summarylogtreecommitdiffstats
path: root/openocd-0.9.0-exit-clean.patch
blob: 4babc355a651a5755f87fda36e11205aef8a3f0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
diff --git a/src/helper/command.c b/src/helper/command.c
index c29f113..d01c35e 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -118,10 +118,17 @@ 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 +678,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 7f9f32c..8a15b41 100644
--- a/src/helper/log.h
+++ b/src/helper/log.h
@@ -140,5 +140,6 @@ extern int debug_level;
 #define ERROR_FAIL						(-4)
 #define ERROR_WAIT						(-5)
 
+#define ERROR_OK_EXIT					(-6)
 
 #endif	/* LOG_H */
diff --git a/src/openocd.c b/src/openocd.c
index b0dd21a..847c137 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -283,6 +283,8 @@ static int openocd_thread(int argc, char *argv[], struct command_context *cmd_ct
 		return ERROR_FAIL;
 
 	ret = parse_config_file(cmd_ctx);
+	if (ret == ERROR_OK_EXIT)
+		return ERROR_OK;
 	if (ret != ERROR_OK)
 		return ERROR_FAIL;