]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: clean up variable-shadow warnings
authorMark Stapp <mjs@cisco.com>
Thu, 30 Jan 2025 22:30:42 +0000 (17:30 -0500)
committerMark Stapp <mjs@cisco.com>
Tue, 8 Apr 2025 18:41:27 +0000 (14:41 -0400)
Clean up various variable-shadowing warnings from -Wshadow

Signed-off-by: Mark Stapp <mjs@cisco.com>
vtysh/vtysh.c
vtysh/vtysh.h
vtysh/vtysh_config.c
vtysh/vtysh_main.c

index 31e7ce12bac95b6ef61d6a64a5d35fe0c059e149..fba39526c6d4b54bf7c9ef303759447b8f4722fb 100644 (file)
@@ -44,7 +44,7 @@
 DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy");
 
 /* Struct VTY. */
-struct vty *vty;
+struct vty *gvty;
 
 /* VTY shell pager name. */
 char *vtysh_pager_name = NULL;
@@ -161,8 +161,8 @@ static int vtysh_reconnect(struct vtysh_client *vclient);
 static void vclient_close(struct vtysh_client *vclient)
 {
        if (vclient->fd >= 0) {
-               if (vty->of)
-                       vty_out(vty,
+               if (gvty->of)
+                       vty_out(gvty,
                                "Warning: closing connection to %s because of an I/O error!\n",
                                vclient->name);
                close(vclient->fd);
@@ -282,8 +282,8 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line,
                        vclient, bufvalid, buf + bufsz - bufvalid - 1, pass_fd);
 
                if (nread <= 0) {
-                       if (vty->of)
-                               vty_out(vty,
+                       if (gvty->of)
+                               vty_out(gvty,
                                        "vtysh: error reading from %s: %s (%d)",
                                        vclient->name, safe_strerror(errno),
                                        errno);
@@ -357,8 +357,8 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line,
                        /* eol is at line end now, either \n => \0 or \0\0\0 */
                        assert(eol && eol <= bufvalid);
 
-                       if (vty->of)
-                               vty_out(vty, "%s\n", buf);
+                       if (gvty->of)
+                               vty_out(gvty, "%s\n", buf);
 
                        callback(cbarg, buf);
 
@@ -371,8 +371,8 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line,
 
                /* else if no callback, dump raw */
                if (!callback) {
-                       if (vty->of)
-                               vty_out(vty, "%s", buf);
+                       if (gvty->of)
+                               vty_out(gvty, "%s", buf);
                        memmove(buf, buf + textlen, bufvalid - buf - textlen);
                        bufvalid -= textlen;
                        if (end)
@@ -431,8 +431,8 @@ static int vtysh_client_run_all(struct vtysh_client *head_client,
                        rc_all = rc;
                }
        }
-       if (wrong_instance && !correct_instance && vty->of) {
-               vty_out(vty,
+       if (wrong_instance && !correct_instance && gvty->of) {
+               vty_out(gvty,
                        "%% [%s]: command ignored as it targets an instance that is not running\n",
                        head_client->name);
                rc_all = CMD_WARNING_CONFIG_FAILED;
@@ -468,7 +468,7 @@ static int vtysh_client_execute_name(const char *name, const char *line)
        if (idx_client != -1)
                ret = vtysh_client_execute(&vtysh_client[idx_client], line);
        else {
-               vty_out(vty, "Client not found\n");
+               vty_out(gvty, "Client not found\n");
                ret = CMD_WARNING;
        }
 
@@ -495,11 +495,11 @@ static void vtysh_client_config(struct vtysh_client *head_client, char *line)
                return;
 
        /* suppress output to user */
-       vty->of_saved = vty->of;
-       vty->of = NULL;
+       gvty->of_saved = gvty->of;
+       gvty->of = NULL;
        vtysh_client_run_all(head_client, line, 1, vtysh_config_parse_line,
                             NULL);
-       vty->of = vty->of_saved;
+       gvty->of = gvty->of_saved;
 }
 
 /* Command execution over the vty interface. */
@@ -522,11 +522,11 @@ static int vtysh_execute_func(const char *line, int pager)
                char ts[48];
 
                (void)frr_timestamp(3, ts, sizeof(ts));
-               vty_out(vty, "%% %s\n\n", ts);
+               vty_out(gvty, "%% %s\n\n", ts);
        }
 
-       saved_ret = ret = cmd_execute(vty, line, &cmd, 1);
-       saved_node = vty->node;
+       saved_ret = ret = cmd_execute(gvty, line, &cmd, 1);
+       saved_node = gvty->node;
 
        /*
         * If command doesn't succeeded in current node, try to walk up in node
@@ -536,13 +536,13 @@ static int vtysh_execute_func(const char *line, int pager)
        while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON
               && ret != CMD_WARNING && ret != CMD_WARNING_CONFIG_FAILED
               && ret != CMD_ERR_AMBIGUOUS && ret != CMD_ERR_INCOMPLETE
-              && vty->node > CONFIG_NODE) {
-               vty->node = node_parent(vty->node);
-               ret = cmd_execute(vty, line, &cmd, 1);
+              && gvty->node > CONFIG_NODE) {
+               gvty->node = node_parent(gvty->node);
+               ret = cmd_execute(gvty, line, &cmd, 1);
                tried++;
        }
 
-       vty->node = saved_node;
+       gvty->node = saved_node;
 
        /*
         * If command succeeded in any other node than current (tried > 0) we
@@ -567,17 +567,17 @@ static int vtysh_execute_func(const char *line, int pager)
        switch (ret) {
        case CMD_WARNING:
        case CMD_WARNING_CONFIG_FAILED:
-               if (vty->type == VTY_FILE)
-                       vty_out(vty, "Warning...\n");
+               if (gvty->type == VTY_FILE)
+                       vty_out(gvty, "Warning...\n");
                break;
        case CMD_ERR_AMBIGUOUS:
-               vty_out(vty, "%% Ambiguous command: %s\n", line);
+               vty_out(gvty, "%% Ambiguous command: %s\n", line);
                break;
        case CMD_ERR_NO_MATCH:
-               vty_out(vty, "%% Unknown command: %s\n", line);
+               vty_out(gvty, "%% Unknown command: %s\n", line);
                break;
        case CMD_ERR_INCOMPLETE:
-               vty_out(vty, "%% Command incomplete: %s\n", line);
+               vty_out(gvty, "%% Command incomplete: %s\n", line);
                break;
        case CMD_SUCCESS_DAEMON: {
                /*
@@ -586,7 +586,7 @@ static int vtysh_execute_func(const char *line, int pager)
                 * cause any problem but is really ugly.
                 */
                if (pager && strncmp(line, "exit", 4))
-                       vty_open_pager(vty);
+                       vty_open_pager(gvty);
 
                if (!strcmp(cmd->string, "configure")) {
                        for (i = 0; i < array_size(vtysh_client); i++) {
@@ -602,17 +602,17 @@ static int vtysh_execute_func(const char *line, int pager)
 
 
                                if (vline == NULL) {
-                                       if (vty->is_paged)
-                                               vty_close_pager(vty);
+                                       if (gvty->is_paged)
+                                               vty_close_pager(gvty);
                                        return CMD_SUCCESS;
                                }
 
-                               ret = cmd_execute_command(vline, vty, &cmd, 1);
+                               ret = cmd_execute_command(vline, gvty, &cmd, 1);
                                cmd_free_strvec(vline);
                                if (ret != CMD_SUCCESS_DAEMON)
                                        break;
                        } else if (cmd->func) {
-                               (*cmd->func)(cmd, vty, 0, NULL);
+                               (*cmd->func)(cmd, gvty, 0, NULL);
                                break;
                        }
                }
@@ -653,11 +653,11 @@ static int vtysh_execute_func(const char *line, int pager)
                        break;
 
                if (cmd->func)
-                       (*cmd->func)(cmd, vty, 0, NULL);
+                       (*cmd->func)(cmd, gvty, 0, NULL);
        }
        }
-       if (vty->is_paged)
-               vty_close_pager(vty);
+       if (gvty->is_paged)
+               vty_close_pager(gvty);
 
        return cmd_stat;
 }
@@ -980,21 +980,21 @@ static int vtysh_process_questionmark(const char *input, int input_len)
        } else if (input_len && isspace((unsigned char)input[input_len - 1]))
                vector_set(vline, NULL);
 
-       describe = cmd_describe_command(vline, vty, &ret);
+       describe = cmd_describe_command(vline, gvty, &ret);
 
        /* Ambiguous and no match error. */
        switch (ret) {
        case CMD_ERR_AMBIGUOUS:
                cmd_free_strvec(vline);
                vector_free(describe);
-               vty_out(vty, "%% Ambiguous command.\n");
+               vty_out(gvty, "%% Ambiguous command.\n");
                rl_on_new_line();
                return 0;
        case CMD_ERR_NO_MATCH:
                cmd_free_strvec(vline);
                if (describe)
                        vector_free(describe);
-               vty_out(vty, "%% There is no matched command.\n");
+               vty_out(gvty, "%% There is no matched command.\n");
                rl_on_new_line();
                return 0;
        }
@@ -1015,9 +1015,9 @@ static int vtysh_process_questionmark(const char *input, int input_len)
        for (i = 0; i < vector_active(describe); i++)
                if ((token = vector_slot(describe, i)) != NULL) {
                        if (!token->desc)
-                               vty_out(vty, "  %-s\n", token->text);
+                               vty_out(gvty, "  %-s\n", token->text);
                        else
-                               vty_out(vty, "  %-*s  %s\n", width, token->text,
+                               vty_out(gvty, "  %-*s  %s\n", width, token->text,
                                        token->desc);
 
                        if (IS_VARYING_TOKEN(token->type)) {
@@ -1033,7 +1033,7 @@ static int vtysh_process_questionmark(const char *input, int input_len)
 
                                        char *ac = cmd_variable_comp2str(
                                                varcomps, cols);
-                                       vty_out(vty, "%s\n", ac);
+                                       vty_out(gvty, "%s\n", ac);
                                        XFREE(MTYPE_TMP, ac);
                                }
 
@@ -1056,7 +1056,7 @@ static int vtysh_rl_describe(int a, int b)
 {
        int ret;
 
-       vty_out(vty, "\n");
+       vty_out(gvty, "\n");
 
        ret = vtysh_process_questionmark(rl_line_buffer, rl_end);
        rl_on_new_line();
@@ -1116,7 +1116,7 @@ static char *command_generator(const char *text, int state)
        if (!state) {
                index = 0;
 
-               if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
+               if (gvty->node == AUTH_NODE || gvty->node == AUTH_ENABLE_NODE)
                        return NULL;
 
                vline = cmd_make_strvec(rl_line_buffer);
@@ -1127,7 +1127,7 @@ static char *command_generator(const char *text, int state)
                    isspace((unsigned char)rl_line_buffer[rl_end - 1]))
                        vector_set(vline, NULL);
 
-               matched = cmd_complete_command(vline, vty, &complete_status);
+               matched = cmd_complete_command(vline, gvty, &complete_status);
                cmd_free_strvec(vline);
        }
 
@@ -1672,13 +1672,13 @@ extern struct cmd_node vty_node;
 /* When '^Z' is received from vty, move down to the enable mode. */
 static int vtysh_end(void)
 {
-       switch (vty->node) {
+       switch (gvty->node) {
        case VIEW_NODE:
        case ENABLE_NODE:
                /* Nothing to do. */
                break;
        default:
-               vty->node = ENABLE_NODE;
+               gvty->node = ENABLE_NODE;
                break;
        }
        return CMD_SUCCESS;
@@ -3627,7 +3627,7 @@ static void show_route_map_send(const char *route_map, bool json)
                strlcat(command_line, " json", sizeof(command_line));
 
        if (json)
-               vty_out(vty, "{");
+               vty_out(gvty, "{");
 
        for (i = 0; i < array_size(vtysh_client); i++) {
                const struct vtysh_client *client = &vtysh_client[i];
@@ -3644,18 +3644,18 @@ static void show_route_map_send(const char *route_map, bool json)
                        continue;
 
                if (json && !first)
-                       vty_out(vty, ",");
+                       vty_out(gvty, ",");
                else
                        first = false;
 
                if (json)
-                       vty_out(vty, "\"%s\":", vtysh_client[i].name);
+                       vty_out(gvty, "\"%s\":", vtysh_client[i].name);
 
                vtysh_client_execute_name(vtysh_client[i].name, command_line);
        }
 
        if (json)
-               vty_out(vty, "}\n");
+               vty_out(gvty, "}\n");
 }
 
 DEFPY (show_route_map,
@@ -3699,7 +3699,7 @@ static void show_prefix_list_send(afi_t afi, const char *prefix_list,
                strlcat(command_line, " json", sizeof(command_line));
 
        if (json)
-               vty_out(vty, "{");
+               vty_out(gvty, "{");
 
        for (i = 0; i < array_size(vtysh_client); i++) {
                const struct vtysh_client *client = &vtysh_client[i];
@@ -3716,18 +3716,18 @@ static void show_prefix_list_send(afi_t afi, const char *prefix_list,
                        continue;
 
                if (json && !first)
-                       vty_out(vty, ",");
+                       vty_out(gvty, ",");
                else
                        first = false;
 
                if (json)
-                       vty_out(vty, "\"%s\":", vtysh_client[i].name);
+                       vty_out(gvty, "\"%s\":", vtysh_client[i].name);
 
                vtysh_client_execute_name(vtysh_client[i].name, command_line);
        }
 
        if (json)
-               vty_out(vty, "}\n");
+               vty_out(gvty, "}\n");
 }
 
 DEFPY (show_ip_prefix_list,
@@ -3842,7 +3842,7 @@ static void show_access_list_send(afi_t afi, const char *access_list, bool json)
                strlcat(command_line, access_list, sizeof(command_line));
        if (json) {
                strlcat(command_line, " json", sizeof(command_line));
-               vty_out(vty, "{");
+               vty_out(gvty, "{");
        }
 
        for (i = 0; i < array_size(vtysh_client); i++) {
@@ -3860,18 +3860,18 @@ static void show_access_list_send(afi_t afi, const char *access_list, bool json)
                        continue;
 
                if (json && !first)
-                       vty_out(vty, ",");
+                       vty_out(gvty, ",");
                else
                        first = false;
 
                if (json)
-                       vty_out(vty, "\"%s\":", vtysh_client[i].name);
+                       vty_out(gvty, "\"%s\":", vtysh_client[i].name);
 
                vtysh_client_execute_name(vtysh_client[i].name, command_line);
        }
 
        if (json)
-               vty_out(vty, "}\n");
+               vty_out(gvty, "}\n");
 }
 
 DEFPY (show_ip_access_list,
@@ -3956,10 +3956,10 @@ static void backup_config_file(const char *fbackup)
 
        /* Move current configuration file to backup config file. */
        if (unlink(integrate_sav) != 0 && errno != ENOENT)
-               vty_out(vty, "Unlink failed for %s: %s\n", integrate_sav,
+               vty_out(gvty, "Unlink failed for %s: %s\n", integrate_sav,
                        strerror(errno));
        if (rename(fbackup, integrate_sav) != 0 && errno != ENOENT)
-               vty_out(vty, "Error renaming %s to %s: %s\n", fbackup,
+               vty_out(gvty, "Error renaming %s to %s: %s\n", fbackup,
                        integrate_sav, strerror(errno));
        free(integrate_sav);
 }
@@ -3981,12 +3981,12 @@ int vtysh_write_config_integrated(void)
        struct stat st;
        int err = 0;
 
-       vty_out(vty, "Building Configuration...\n");
+       vty_out(gvty, "Building Configuration...\n");
 
        backup_config_file(frr_config);
        fp = fopen(frr_config, "w");
        if (fp == NULL) {
-               vty_out(vty,
+               vty_out(gvty,
                        "%% Error: failed to open configuration file %s: %s\n",
                        frr_config, safe_strerror(errno));
                return CMD_WARNING_CONFIG_FAILED;
@@ -3997,10 +3997,10 @@ int vtysh_write_config_integrated(void)
                vtysh_client_config(&vtysh_client[i], line);
 
        vtysh_config_write();
-       vty->of_saved = vty->of;
-       vty->of = fp;
+       gvty->of_saved = gvty->of;
+       gvty->of = fp;
        vtysh_config_dump();
-       vty->of = vty->of_saved;
+       gvty->of = gvty->of_saved;
 
        if (fchmod(fd, CONFIGFILE_MASK) != 0) {
                printf("%% Warning: can't chmod configuration file %s: %s\n",
@@ -4964,7 +4964,7 @@ char *vtysh_prompt(void)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
        /* prompt formatting has a %s in the cmd_node prompt string. */
-       snprintf(buf, sizeof(buf), cmd_prompt(vty->node), cmd_hostname_get());
+       snprintf(buf, sizeof(buf), cmd_prompt(gvty->node), cmd_hostname_get());
 #pragma GCC diagnostic pop
        return buf;
 }
@@ -4987,12 +4987,12 @@ static void vtysh_autocomplete(vector comps, struct cmd_token *token)
        snprintf(accmd, sizeof(accmd), "autocomplete %d %s %s", token->type,
                 token->text, token->varname ? token->varname : "-");
 
-       vty->of_saved = vty->of;
-       vty->of = NULL;
+       gvty->of_saved = gvty->of;
+       gvty->of = NULL;
        for (i = 0; i < array_size(vtysh_client); i++)
                vtysh_client_run_all(&vtysh_client[i], accmd, 1, vtysh_ac_line,
                                     comps);
-       vty->of = vty->of_saved;
+       gvty->of = gvty->of_saved;
 }
 
 static const struct cmd_variable_handler vtysh_var_handler[] = {
@@ -5004,8 +5004,8 @@ static const struct cmd_variable_handler vtysh_var_handler[] = {
 
 void vtysh_uninit(void)
 {
-       if (vty->of != stdout)
-               fclose(vty->of);
+       if (gvty->of != stdout)
+               fclose(gvty->of);
 }
 
 void vtysh_init_vty(void)
@@ -5026,12 +5026,12 @@ void vtysh_init_vty(void)
                stderr_stdout_same = true;
 
        /* Make vty structure. */
-       vty = vty_new();
-       vty->type = VTY_SHELL;
-       vty->node = VIEW_NODE;
+       gvty = vty_new();
+       gvty->type = VTY_SHELL;
+       gvty->node = VIEW_NODE;
 
        /* set default output */
-       vty->of = stdout;
+       gvty->of = stdout;
        vtysh_pager_envdef(false);
 
        /* Initialize commands. */
index 3c532b99a8cebe54fca5b8baab2a87c35a130639..6d5e559a2fa962e0308a6ca384f575ad55bbc87c 100644 (file)
@@ -152,7 +152,7 @@ void suid_off(void);
 /* Child process execution flag. */
 extern int execute_flag;
 
-extern struct vty *vty;
+extern struct vty *gvty;
 
 extern int user_mode;
 
index 6536e1b3769340c5a8c34917211c372c382de87d..4f6fc782c200e5aaf3d4be618d626d9143759cab 100644 (file)
@@ -558,19 +558,19 @@ static void configvec_dump(vector vec, bool nested)
                                        continue;
                                }
 
-                               vty_out(vty, "%s\n", config->name);
+                               vty_out(gvty, "%s\n", config->name);
 
                                for (ALL_LIST_ELEMENTS(config->line, mnode,
                                                       mnnode, line))
-                                       vty_out(vty, "%s\n", line);
+                                       vty_out(gvty, "%s\n", line);
 
                                configvec_dump(config->nested, true);
 
                                if (config->exit)
-                                       vty_out(vty, "%s\n", config->exit);
+                                       vty_out(gvty, "%s\n", config->exit);
 
                                if (!NO_DELIMITER(i))
-                                       vty_out(vty, "!\n");
+                                       vty_out(gvty, "!\n");
 
                                config_del(config);
                        }
@@ -579,7 +579,7 @@ static void configvec_dump(vector vec, bool nested)
                        XFREE(MTYPE_VTYSH_CONFIG, configuration);
                        vector_slot(vec, i) = NULL;
                        if (!nested && NO_DELIMITER(i))
-                               vty_out(vty, "!\n");
+                               vty_out(gvty, "!\n");
                }
 }
 
@@ -589,11 +589,11 @@ void vtysh_config_dump(void)
        char *line;
 
        for (ALL_LIST_ELEMENTS(config_top, node, nnode, line))
-               vty_out(vty, "%s\n", line);
+               vty_out(gvty, "%s\n", line);
 
        list_delete_all_node(config_top);
 
-       vty_out(vty, "!\n");
+       vty_out(gvty, "!\n");
 
        configvec_dump(configvec, false);
 }
@@ -601,13 +601,13 @@ void vtysh_config_dump(void)
 /* Read up configuration file from file_name. */
 static int vtysh_read_file(FILE *confp, bool dry_run)
 {
-       struct vty *vty;
+       struct vty *lvty;
        int ret;
 
-       vty = vty_new();
-       vty->wfd = STDERR_FILENO;
-       vty->type = VTY_TERM;
-       vty->node = CONFIG_NODE;
+       lvty = vty_new();
+       lvty->wfd = STDERR_FILENO;
+       lvty->type = VTY_TERM;
+       lvty->node = CONFIG_NODE;
 
        vtysh_execute_no_pager("enable");
        /*
@@ -622,7 +622,7 @@ static int vtysh_read_file(FILE *confp, bool dry_run)
                vtysh_execute_no_pager("XFRR_start_configuration");
 
        /* Execute configuration file. */
-       ret = vtysh_config_from_file(vty, confp);
+       ret = vtysh_config_from_file(lvty, confp);
 
        if (!dry_run)
                vtysh_execute_no_pager("XFRR_end_configuration");
@@ -630,7 +630,7 @@ static int vtysh_read_file(FILE *confp, bool dry_run)
        vtysh_execute_no_pager("end");
        vtysh_execute_no_pager("disable");
 
-       vty_close(vty);
+       vty_close(lvty);
 
        return (ret);
 }
index 297d87ec419d495d5729d16dd774991685b985c0..16e166beacd206c0b138ce0e9ec93517e731d2cb 100644 (file)
@@ -726,7 +726,7 @@ int main(int argc, char **argv, char **env)
 
        vtysh_readline_init();
 
-       vty_hello(vty);
+       vty_hello(gvty);
 
        /* Enter into enable node. */
        if (!user_mode)