openocd: fix issue in WIN32 with TCP adapters 56/5456/5
authorTarek BOCHKATI <tarek.bouchkati@gmail.com>
Thu, 23 Apr 2020 10:00:31 +0000 (11:00 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 14 Jun 2020 13:23:48 +0000 (14:23 +0100)
Issue: server_quit is called before adapter_quit:
  In WIN32 only in server_quit we do an WSACleanup,
  which terminates/closes all active sockets.
  So if the adapter is TCP based, the adapter.quit handler
  will fail if it will need to send some commands through TCP.

Example: close_socket in jtag_vpi_quit will fail in WIN32
  because the socket is already closed
  and the errno is set as "Bad File Descriptor"

To fix that we introduced new functions called server_host_os_entry/quit
to manage specific OS setup (hence WSA for sockets in WINDOWS) in order
to delay WSACleanup after adapter_quit().

Change-Id: Ie4afacafe123857f6ae300e376bdfcf0d8c027ac
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/5456
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/openocd.c
src/server/server.c
src/server/server.h

index 2a9a0b3d4a37ae7c764d4cf5968fd0887c1df61a..886228425d79c7dafac6ef7934be7796cbfbd3da 100644 (file)
@@ -345,6 +345,8 @@ int openocd_main(int argc, char *argv[])
        command_context_mode(cmd_ctx, COMMAND_CONFIG);
        command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
 
        command_context_mode(cmd_ctx, COMMAND_CONFIG);
        command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
 
+       server_host_os_entry();
+
        /* Start the executable meat that can evolve into thread in future. */
        ret = openocd_thread(argc, argv, cmd_ctx);
 
        /* Start the executable meat that can evolve into thread in future. */
        ret = openocd_thread(argc, argv, cmd_ctx);
 
@@ -360,6 +362,8 @@ int openocd_main(int argc, char *argv[])
 
        adapter_quit();
 
 
        adapter_quit();
 
+       server_host_os_close();
+
        /* Shutdown commandline interface */
        command_exit(cmd_ctx);
 
        /* Shutdown commandline interface */
        command_exit(cmd_ctx);
 
index 07b7ae48784a5aed19b33f5905c20dc02b19ba7e..23a15ef9a37d6b2071d080e2f151e8a153633351 100644 (file)
@@ -631,7 +631,7 @@ static void sigkey_handler(int sig)
 #endif
 
 
 #endif
 
 
-int server_preinit(void)
+int server_host_os_entry(void)
 {
        /* this currently only calls WSAStartup on native win32 systems
         * before any socket operations are performed.
 {
        /* this currently only calls WSAStartup on native win32 systems
         * before any socket operations are performed.
@@ -647,7 +647,21 @@ int server_preinit(void)
                LOG_ERROR("Failed to Open Winsock");
                return ERROR_FAIL;
        }
                LOG_ERROR("Failed to Open Winsock");
                return ERROR_FAIL;
        }
+#endif
+       return ERROR_OK;
+}
 
 
+int server_host_os_close(void)
+{
+#ifdef _WIN32
+       WSACleanup();
+#endif
+       return ERROR_OK;
+}
+
+int server_preinit(void)
+{
+#ifdef _WIN32
        /* register ctrl-c handler */
        SetConsoleCtrlHandler(ControlHandler, TRUE);
 
        /* register ctrl-c handler */
        SetConsoleCtrlHandler(ControlHandler, TRUE);
 
@@ -688,7 +702,6 @@ int server_quit(void)
        target_quit();
 
 #ifdef _WIN32
        target_quit();
 
 #ifdef _WIN32
-       WSACleanup();
        SetConsoleCtrlHandler(ControlHandler, FALSE);
 
        return ERROR_OK;
        SetConsoleCtrlHandler(ControlHandler, FALSE);
 
        return ERROR_OK;
index ab9b72f901a8d5bb083d6123a5a8d06dbdf2a17a..f4cc39d3a75425e4c8fb45ff3a22c99be7603c49 100644 (file)
@@ -80,6 +80,9 @@ int add_service(char *name, const char *port,
                void *priv);
 int remove_service(const char *name, const char *port);
 
                void *priv);
 int remove_service(const char *name, const char *port);
 
+int server_host_os_entry(void);
+int server_host_os_close(void);
+
 int server_preinit(void);
 int server_init(struct command_context *cmd_ctx);
 int server_quit(void);
 int server_preinit(void);
 int server_init(struct command_context *cmd_ctx);
 int server_quit(void);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)