This is an automated email from Gerrit.

"Jan Matyas <jan.mat...@codasip.com>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/8957

-- gerrit

commit 0afaa0b7b5b63ee3b51ee73d0a72a16e5f1927e5
Author: Jan Matyas <jan.mat...@codasip.com>
Date:   Tue Jun 17 13:17:23 2025 +0200

    openocd.c: 'init' should fail if GDB service cannot be created
    
    If it is not possible to create a GDB service for a certain target
    (for example the given TCP port is already occupied), the "init"
    command should fail, but it currently does not.
    
    Fix this by checking the return code of gdb_target_add_all().
    
    Steps to reproduce:
    
    1) Make the port 3333/tcp occupied. For example by:
    
       nc -l 3333
    
    2) In another terminal, launch OpenOCD. Use the gdb_port
       3333 (which is the default). For example:
    
       path/to/your/openocd \
          -c "adapter driver ..." \
          -c "jtag newtap ..."
          -c "target create ..."
    
    3) Observe the outcome:
    
       Before this patch:
    
       Error "couldn't bind gdb to socket on port 3333: Address already in use"
       is displayed but OpenOCD keeps running.
    
       After this patch:
    
       The error message is displayed and OpenOCD exits - as expected.
    
    Change-Id: I63c283a9a1095167b78e69e9ee879c378a6b9f2a
    Signed-off-by: Jan Matyas <jan.mat...@codasip.com>

diff --git a/src/openocd.c b/src/openocd.c
index 3fbece3955..e63a9661a3 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -170,7 +170,8 @@ COMMAND_HANDLER(handle_init_command)
        jtag_poll_unmask(save_poll_mask);
 
        /* initialize telnet subsystem */
-       gdb_target_add_all(all_targets);
+       if (gdb_target_add_all(all_targets) != ERROR_OK)
+               return ERROR_FAIL;
 
        target_register_event_callback(log_target_callback_event_handler, 
CMD_CTX);
 

-- 

Reply via email to