This is an automated email from Gerrit.

Paul Fertser (fercer...@gmail.com) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/2600

-- gerrit

commit 78f6cd7136883b8473015bb464ed6d2fc4f91279
Author: Paul Fertser <fercer...@gmail.com>
Date:   Fri Mar 13 16:32:53 2015 +0300

    Tcl exception codes cleanup, shutdown command amendments
    
    This patch might influence openocd Tcl commands behaviour in subtle
    ways, please give it a nice testing.
    
    The idea is that if an OpenOCD Tcl command returns an error, an
    exception is raised, and then the return code is propogated all the
    way up (or to the "catch" if present). This allows to detect
    "shutdown" which is not actually an error but has to raise an
    exception to stop execution of the commands that follow it in the
    script.
    
    openocd_thread special-cases shutdown because it should then terminate
    OpenOCD with a success error code, unless shutdown was called with an
    optional "error" argument which means terminate with a non-zero exit
    code.
    
    Change-Id: I7b6fa8a2e24c947dc45d8def0008b4b007c478b3
    Signed-off-by: Paul Fertser <fercer...@gmail.com>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index 4086437..61a372d 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -6474,8 +6474,10 @@ Useful in connection with script files
 (@command{script} command and @command{target_name} configuration).
 @end deffn
 
-@deffn Command shutdown
-Close the OpenOCD daemon, disconnecting all clients (GDB, telnet, other).
+@deffn Command shutdown [@option{error}]
+Close the OpenOCD daemon, disconnecting all clients (GDB, telnet,
+other). If option @option{error} is used, OpenOCD will return a
+non-zero exit code to the parent process.
 @end deffn
 
 @anchor{debuglevel}
diff --git a/src/flash/startup.tcl b/src/flash/startup.tcl
index 7a96a3e..fbb8d8e 100644
--- a/src/flash/startup.tcl
+++ b/src/flash/startup.tcl
@@ -8,8 +8,8 @@
 
 proc program_error {description exit} {
        if {$exit == 1} {
-               echo $description
-               shutdown
+               echo $description
+               shutdown error
        }
 
        error $description
diff --git a/src/helper/command.c b/src/helper/command.c
index 9d19cff..a0aa9e8 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -121,7 +121,7 @@ static int command_retval_set(Jim_Interp *interp, int 
retval)
        if (return_retval != NULL)
                *return_retval = retval;
 
-       return (retval == ERROR_OK) ? JIM_OK : JIM_ERR;
+       return (retval == ERROR_OK) ? JIM_OK : retval;
 }
 
 extern struct command_context *global_cmd_ctx;
@@ -659,24 +659,7 @@ int command_run_line(struct command_context *context, char 
*line)
                }
                Jim_DeleteAssocData(interp, "context");
        }
-       if (retcode == JIM_ERR) {
-               if (retval == ERROR_COMMAND_CLOSE_CONNECTION) {
-                       /* Shutdown request is not an error */
-                       return ERROR_OK;
-               } else {
-                       /* We do not print the connection closed error message 
*/
-                       Jim_MakeErrorMessage(interp);
-                       LOG_USER("%s", Jim_GetString(Jim_GetResult(interp), 
NULL));
-               }
-               if (retval == ERROR_OK) {
-                       /* It wasn't a low level OpenOCD command that failed */
-                       return ERROR_FAIL;
-               }
-               return retval;
-       } else if (retcode == JIM_EXIT) {
-               /* ignore.
-                * exit(Jim_GetExitCode(interp)); */
-       } else {
+       if (retcode == JIM_OK) {
                const char *result;
                int reslen;
 
@@ -696,7 +679,22 @@ int command_run_line(struct command_context *context, char 
*line)
                        LOG_USER_N("\n");
                }
                retval = ERROR_OK;
+       } else if (retcode == JIM_EXIT) {
+               /* ignore.
+                * exit(Jim_GetExitCode(interp)); */
+       } else if (retcode == ERROR_COMMAND_CLOSE_CONNECTION) {
+               return retcode;
+       } else {
+               Jim_MakeErrorMessage(interp);
+               LOG_USER("%s", Jim_GetString(Jim_GetResult(interp), NULL));
+
+               if (retval == ERROR_OK) {
+                       /* It wasn't a low level OpenOCD command that failed */
+                       return ERROR_FAIL;
+               }
+               return retval;
        }
+
        return retval;
 }
 
diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl
index 926d26b..4ca2cab 100644
--- a/src/helper/startup.tcl
+++ b/src/helper/startup.tcl
@@ -16,10 +16,12 @@ proc exit {} {
 proc ocd_bouncer {name args} {
        set cmd [format "ocd_%s" $name]
        set type [eval ocd_command type $cmd $args]
+       set errcode error
        if {$type == "native"} {
                return [eval $cmd $args]
        } else {if {$type == "simple"} {
-               if {[catch {eval $cmd $args}] == 0} {
+               set errcode [catch {eval $cmd $args}]
+               if {$errcode == 0} {
                        return ""
                } else {
                        # 'classic' commands output error message as part of 
progress output
@@ -32,7 +34,7 @@ proc ocd_bouncer {name args} {
        } else {
                set errmsg [format "invalid subcommand \"%s\"" $args]
        }}}
-       return -code error $errmsg
+       return -code $errcode $errmsg
 }
 
 # Try flipping / and \ to find file if the filename does not
diff --git a/src/openocd.c b/src/openocd.c
index b0dd21a..4a09256 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -283,7 +283,9 @@ 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)
+       if (ret == ERROR_COMMAND_CLOSE_CONNECTION)
+               return ERROR_OK;
+       else if (ret != ERROR_OK)
                return ERROR_FAIL;
 
        ret = server_init(cmd_ctx);
diff --git a/src/server/server.c b/src/server/server.c
index 73d8b5b..0200829 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -608,6 +608,10 @@ COMMAND_HANDLER(handle_shutdown_command)
 
        shutdown_openocd = 1;
 
+       if (CMD_ARGC == 1)
+               if (!strcmp(CMD_ARGV[0], "error"))
+                       return ERROR_FAIL;
+
        return ERROR_COMMAND_CLOSE_CONNECTION;
 }
 

-- 

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to