cfg: add stm32 cmsis-dap compliant config
[fw/openocd] / src / server / server.c
index 16f751079b017ed9f7c8432b6c2f3882326d5bf7..5e1ae36b1db0d84e2178b392f5b2b4d31f61309e 100644 (file)
@@ -21,7 +21,7 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -85,6 +85,7 @@ static int add_connection(struct service *service, struct command_context *cmd_c
                if (retval != ERROR_OK) {
                        close_socket(c->fd);
                        LOG_ERROR("attempted '%s' connection rejected", service->name);
+                       command_done(c->cmd_ctx);
                        free(c);
                        return retval;
                }
@@ -104,6 +105,7 @@ static int add_connection(struct service *service, struct command_context *cmd_c
                retval = service->new_connection(c);
                if (retval != ERROR_OK) {
                        LOG_ERROR("attempted '%s' connection rejected", service->name);
+                       command_done(c->cmd_ctx);
                        free(c);
                        return retval;
                }
@@ -124,6 +126,7 @@ static int add_connection(struct service *service, struct command_context *cmd_c
                retval = service->new_connection(c);
                if (retval != ERROR_OK) {
                        LOG_ERROR("attempted '%s' connection rejected", service->name);
+                       command_done(c->cmd_ctx);
                        free(c);
                        return retval;
                }
@@ -300,14 +303,14 @@ static int remove_services(void)
                struct service *next = c->next;
 
                if (c->name)
-                       free((void *)c->name);
+                       free(c->name);
 
                if (c->type == CONNECTION_PIPE) {
                        if (c->fd != -1)
                                close(c->fd);
                }
                if (c->port)
-                       free((void *)c->port);
+                       free(c->port);
 
                if (c->priv)
                        free(c->priv);
@@ -462,9 +465,10 @@ int server_loop(struct command_context *command_context)
                                                retval = service->input(c);
                                                if (retval != ERROR_OK) {
                                                        struct connection *next = c->next;
-                                                       if (service->type == CONNECTION_PIPE) {
+                                                       if (service->type == CONNECTION_PIPE ||
+                                                                       service->type == CONNECTION_STDINOUT) {
                                                                /* if connection uses a pipe then
-                                                                *shutdown openocd on error */
+                                                                * shutdown openocd on error */
                                                                shutdown_openocd = 1;
                                                        }
                                                        remove_connection(service, c);
@@ -608,7 +612,7 @@ int server_register_commands(struct command_context *cmd_ctx)
        return register_commands(cmd_ctx, NULL, server_command_handlers);
 }
 
-SERVER_PORT_COMMAND()
+COMMAND_HELPER(server_port_command, unsigned short *out)
 {
        switch (CMD_ARGC) {
                case 0:
@@ -627,7 +631,7 @@ SERVER_PORT_COMMAND()
        return ERROR_OK;
 }
 
-SERVER_PIPE_COMMAND()
+COMMAND_HELPER(server_pipe_command, char **out)
 {
        switch (CMD_ARGC) {
                case 0:
@@ -635,9 +639,12 @@ SERVER_PIPE_COMMAND()
                        break;
                case 1:
                {
-                       const char *t = strdup(CMD_ARGV[0]);
-                       free((void *)*out);
-                       *out = t;
+                       if (CMD_CTX->mode == COMMAND_EXEC) {
+                               LOG_WARNING("unable to change server port after init");
+                               return ERROR_COMMAND_ARGUMENT_INVALID;
+                       }
+                       free(*out);
+                       *out = strdup(CMD_ARGV[0]);
                        break;
                }
                default: