This is an automated email from Gerrit.

"Antonio Borneo <[email protected]>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9378

-- gerrit

commit fe38a13852c46ef044ab13e77acf5c92113ad68c
Author: Antonio Borneo <[email protected]>
Date:   Sun Jan 4 18:39:37 2026 +0100

    server: drop duplicated field 'name'
    
    Don't copy in struct service::name the field struct
    service_driver::name.
    
    Use a new helper service_name() to return the string.
    
    Change-Id: I8b6993853e473cfdb36923786a2394050c19e111
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/src/server/server.c b/src/server/server.c
index a943ace6cb..768d55196f 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -54,6 +54,11 @@ static int polling_period = 100;
 /* address by name on which to listen for incoming TCP/IP connections */
 static char *bindto_name;
 
+const char *service_name(const struct service *service)
+{
+       return service->driver->name;
+}
+
 static int add_connection(struct service *service, struct command_context 
*cmd_ctx)
 {
        socklen_t address_size;
@@ -88,11 +93,12 @@ static int add_connection(struct service *service, struct 
command_context *cmd_c
                        (char *)&flag,                  /* the cast is 
historical cruft */
                        sizeof(int));                   /* length of option 
value */
 
-               LOG_INFO("accepting '%s' connection on tcp/%s", service->name, 
service->port);
+               LOG_INFO("accepting '%s' connection on tcp/%s", 
service_name(service),
+                                service->port);
                retval = service->driver->new_connection(c);
                if (retval != ERROR_OK) {
                        close_socket(c->fd);
-                       LOG_ERROR("attempted '%s' connection rejected", 
service->name);
+                       LOG_ERROR("attempted '%s' connection rejected", 
service_name(service));
                        command_done(c->cmd_ctx);
                        free(c);
                        return retval;
@@ -109,10 +115,10 @@ static int add_connection(struct service *service, struct 
command_context *cmd_c
                /* do not check for new connections again on stdin */
                service->fd = -1;
 
-               LOG_INFO("accepting '%s' connection from pipe", service->name);
+               LOG_INFO("accepting '%s' connection from pipe", 
service_name(service));
                retval = service->driver->new_connection(c);
                if (retval != ERROR_OK) {
-                       LOG_ERROR("attempted '%s' connection rejected", 
service->name);
+                       LOG_ERROR("attempted '%s' connection rejected", 
service_name(service));
                        command_done(c->cmd_ctx);
                        free(c);
                        return retval;
@@ -132,10 +138,11 @@ static int add_connection(struct service *service, struct 
command_context *cmd_c
                        return ERROR_FAIL;
                }
 
-               LOG_INFO("accepting '%s' connection from pipe %s", 
service->name, service->port);
+               LOG_INFO("accepting '%s' connection from pipe %s", 
service_name(service),
+                                service->port);
                retval = service->driver->new_connection(c);
                if (retval != ERROR_OK) {
-                       LOG_ERROR("attempted '%s' connection rejected", 
service->name);
+                       LOG_ERROR("attempted '%s' connection rejected", 
service_name(service));
                        command_done(c->cmd_ctx);
                        free(c);
                        return retval;
@@ -215,7 +222,6 @@ int add_service(const struct service_driver *driver, const 
char *port,
                return ERROR_FAIL;
        }
 
-       c->name = driver->name;
        c->driver = driver;
        c->port = strdup(port);
        c->max_connections = 1; /* Only TCP/IP ports can support more than one 
connection */
@@ -276,7 +282,8 @@ int add_service(const struct service_driver *driver, const 
char *port,
                c->sin.sin_port = htons(c->portnumber);
 
                if (bind(c->fd, (struct sockaddr *)&c->sin, sizeof(c->sin)) == 
-1) {
-                       LOG_ERROR("couldn't bind %s to socket on port %d: %s", 
c->name, c->portnumber, strerror(errno));
+                       LOG_ERROR("couldn't bind %s to socket on port %d: %s",
+                                         service_name(c), c->portnumber, 
strerror(errno));
                        close_socket(c->fd);
                        goto error;
                }
@@ -305,7 +312,7 @@ int add_service(const struct service_driver *driver, const 
char *port,
                socklen_t addr_in_size = sizeof(addr_in);
                if (getsockname(c->fd, (struct sockaddr *)&addr_in, 
&addr_in_size) == 0)
                        LOG_INFO("Listening on port %hu for %s connections",
-                                ntohs(addr_in.sin_port), c->name);
+                                        ntohs(addr_in.sin_port), 
service_name(c));
        } else if (c->type == CONNECTION_STDINOUT) {
                c->fd = fileno(stdin);
 
@@ -374,7 +381,7 @@ int remove_service(const char *name, const char *port)
        prev = services;
 
        for (tmp = services; tmp; prev = tmp, tmp = tmp->next) {
-               if (!strcmp(tmp->name, name) && !strcmp(tmp->port, port)) {
+               if (!strcmp(service_name(tmp), name) && !strcmp(tmp->port, 
port)) {
                        remove_connections(tmp);
 
                        if (tmp == services)
@@ -554,7 +561,7 @@ int server_loop(struct command_context *command_context)
                                        }
                                        LOG_INFO(
                                                "rejected '%s' connection, no 
more connections allowed",
-                                               service->name);
+                                               service_name(service));
                                }
                        }
 
@@ -575,7 +582,7 @@ int server_loop(struct command_context *command_context)
                                                        }
                                                        
remove_connection(service, c);
                                                        LOG_INFO("dropped '%s' 
connection",
-                                                               service->name);
+                                                               
service_name(service));
                                                        c = next;
                                                        continue;
                                                }
diff --git a/src/server/server.h b/src/server/server.h
index 8ba59127ab..ee816463c7 100644
--- a/src/server/server.h
+++ b/src/server/server.h
@@ -66,7 +66,6 @@ struct service_driver {
 };
 
 struct service {
-       const char *name;
        const struct service_driver *driver;
        enum connection_type type;
        char *port;
@@ -82,6 +81,7 @@ struct service {
 int add_service(const struct service_driver *driver, const char *port,
                int max_connections, void *priv);
 int remove_service(const char *name, const char *port);
+const char *service_name(const struct service *service);
 
 int server_host_os_entry(void);
 int server_host_os_close(void);
diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c
index 42fce8f752..cd20e5368d 100644
--- a/src/server/tcl_server.c
+++ b/src/server/tcl_server.c
@@ -298,7 +298,7 @@ COMMAND_HANDLER(handle_tcl_notifications_command)
        if (CMD_CTX->output_handler_priv)
                connection = CMD_CTX->output_handler_priv;
 
-       if (connection && !strcmp(connection->service->name, "tcl")) {
+       if (connection && !strcmp(service_name(connection->service), "tcl")) {
                tclc = connection->priv;
                return CALL_COMMAND_HANDLER(handle_command_parse_bool, 
&tclc->tc_notify, "Target Notification output ");
        } else {
@@ -315,7 +315,7 @@ COMMAND_HANDLER(handle_tcl_trace_command)
        if (CMD_CTX->output_handler_priv)
                connection = CMD_CTX->output_handler_priv;
 
-       if (connection && !strcmp(connection->service->name, "tcl")) {
+       if (connection && !strcmp(service_name(connection->service), "tcl")) {
                tclc = connection->priv;
                return CALL_COMMAND_HANDLER(handle_command_parse_bool, 
&tclc->tc_trace, "Target trace output ");
        } else {
diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c
index d4435aa2a5..1a7408804f 100644
--- a/src/target/semihosting_common.c
+++ b/src/target/semihosting_common.c
@@ -1814,7 +1814,7 @@ static void semihosting_tcp_close_cnx(struct semihosting 
*semihosting)
                return;
 
        struct service *service = semihosting->tcp_connection->service;
-       remove_service(service->name, service->port);
+       remove_service(service_name(service), service->port);
        semihosting->tcp_connection = NULL;
 
 }

-- 

Reply via email to