server/server: Add ability to remove services 54/4054/5
authorMarc Schink <openocd-dev@marcschink.de>
Mon, 19 Dec 2016 19:09:08 +0000 (20:09 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Wed, 1 Aug 2018 13:34:13 +0000 (14:34 +0100)
Add the ability to remove services while OpenOCD is running.

Change-Id: I4067916fda6d03485463fa40901b40484d94e24e
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4054
Tested-by: jenkins
Reviewed-by: Fredrik Hederstierna <fredrik@hederstierna.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/server/server.c
src/server/server.h

index bc5856c..f8273d4 100644 (file)
@@ -364,6 +364,35 @@ static void remove_connections(struct service *service)
        }
 }
 
+int remove_service(const char *name, const char *port)
+{
+       struct service *tmp;
+       struct service *prev;
+
+       prev = services;
+
+       for (tmp = services; tmp; prev = tmp, tmp = tmp->next) {
+               if (!strcmp(tmp->name, name) && !strcmp(tmp->port, port)) {
+                       remove_connections(tmp);
+
+                       if (tmp == services)
+                               services = tmp->next;
+                       else
+                               prev->next = tmp->next;
+
+                       if (tmp->type != CONNECTION_STDINOUT)
+                               close_socket(tmp->fd);
+
+                       free(tmp->priv);
+                       free_service(tmp);
+
+                       return ERROR_OK;
+               }
+       }
+
+       return ERROR_OK;
+}
+
 static int remove_services(void)
 {
        struct service *c = services;
index d4eae94..96e0b48 100644 (file)
@@ -78,6 +78,7 @@ int add_service(char *name, const char *port,
                int max_connections, new_connection_handler_t new_connection_handler,
                input_handler_t in_handler, connection_closed_handler_t close_handler,
                void *priv);
+int remove_service(const char *name, const char *port);
 
 int server_preinit(void);
 int server_init(struct command_context *cmd_ctx);