Hi

I'm testing some of the scripts that was supplied by the sheevaplug
project which was based on OpenOCD 0.2.0. When upgrading to OpenOCD 0.5.0
I found one minor error in OpenOCD. This simple test case returns an error
value back to the calling shell:

?> openocd -f board/sheevaplug.cfg -c init -c exit
?> echo $?       <- should be 0 if no errors occurs
1


I put together a patch, but it might look a bit hackish, but the
exit-scheme currently used is a bit hackish to begin with. Haven't tested
it with telnet-in (which is were the exit functions currently is
implemented).

I also saw that the TCL engine also implements a command named exit which
should have worked as well, but if I renamed the telnet exit command, I
just got that "exit" was an unknown command.


Stian Skjelstad
diff -ur openocd-0.5.0-nand-write-message/src/helper/command.c openocd-0.5.0-exit-clean/src/helper/command.c
--- openocd-0.5.0-nand-write-message/src/helper/command.c	2011-08-09 07:34:19.000000000 +0200
+++ openocd-0.5.0-exit-clean/src/helper/command.c	2012-02-18 14:12:14.757676684 +0100
@@ -123,10 +123,17 @@
 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;
@@ -685,12 +692,12 @@
 		}
 		return retval;
 	} else if (retcode == JIM_EXIT) {
-		/* ignore. */
-		/* exit(Jim_GetExitCode(interp)); */
+		return ERROR_OK_EXIT;
 	} else {
 		const char *result;
 		int reslen;
 
+		fprintf (stderr, "command ran? Fetching result\n");
 		result = Jim_GetString(Jim_GetResult(interp), &reslen);
 		if (reslen > 0)
 		{
diff -ur openocd-0.5.0-nand-write-message/src/helper/log.h openocd-0.5.0-exit-clean/src/helper/log.h
--- openocd-0.5.0-nand-write-message/src/helper/log.h	2011-08-09 07:34:19.000000000 +0200
+++ openocd-0.5.0-exit-clean/src/helper/log.h	2012-02-18 14:05:52.377666892 +0100
@@ -139,5 +139,5 @@
  * 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 -ur openocd-0.5.0-nand-write-message/src/openocd.c openocd-0.5.0-exit-clean/src/openocd.c
--- openocd-0.5.0-nand-write-message/src/openocd.c	2011-08-09 07:34:19.000000000 +0200
+++ openocd-0.5.0-exit-clean/src/openocd.c	2012-02-18 14:08:14.237670522 +0100
@@ -316,6 +316,8 @@
 		return EXIT_FAILURE;
 
 	ret = parse_config_file(cmd_ctx);
+	if (ret == ERROR_OK_EXIT)
+		return ERROR_OK;
 	if (ret != ERROR_OK)
 		return EXIT_FAILURE;
 
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to