]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/command.c
Merge pull request #2602 from pacovn/PVS-Studio_element_overflow
[mirror_frr.git] / lib / command.c
index 7df81438f2a801e63572edd2ef56b190ecfd7e07..0bf856f2484b4ac07d74466629e11f6f92982723 100644 (file)
@@ -261,8 +261,11 @@ void print_version(const char *progname)
 
 char *argv_concat(struct cmd_token **argv, int argc, int shift)
 {
-       int cnt = argc - shift;
-       const char *argstr[cnt];
+       int cnt = MAX(argc - shift, 0);
+       const char *argstr[cnt + 1];
+
+       if (!cnt)
+               return NULL;
 
        for (int i = 0; i < cnt; i++)
                argstr[i] = argv[i + shift]->arg;
@@ -515,13 +518,6 @@ static int config_write_host(struct vty *vty)
                                        host.enable);
                }
 
-               if (zlog_default->default_lvl != LOG_DEBUG) {
-                       vty_out(vty,
-                               "! N.B. The 'log trap' command is deprecated.\n");
-                       vty_out(vty, "log trap %s\n",
-                               zlog_priority[zlog_default->default_lvl]);
-               }
-
                if (host.logfile
                    && (zlog_default->maxlvl[ZLOG_DEST_FILE]
                        != ZLOG_DISABLED)) {
@@ -1184,7 +1180,7 @@ static int handle_pipe_action(struct vty *vty, const char *cmd_in,
                              char **cmd_out)
 {
        /* look for `|` */
-       char *orig, *working, *token;
+       char *orig, *working, *token, *u;
        char *pipe = strstr(cmd_in, "| ");
 
        if (!pipe)
@@ -1213,7 +1209,8 @@ static int handle_pipe_action(struct vty *vty, const char *cmd_in,
                        goto fail;
                }
                *cmd_out = XSTRDUP(MTYPE_TMP, cmd_in);
-               *(strstr(*cmd_out, "|")) = '\0';
+               u = *cmd_out;
+               strsep(&u, "|");
        } else {
                vty_out(vty, "%% Unknown action '%s'\n", token);
                goto fail;
@@ -2428,7 +2425,8 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel)
                XFREE(MTYPE_TMP, p);
 
        if (!ret) {
-               vty_out(vty, "can't open logfile %s\n", fname);
+               if (vty)
+                       vty_out(vty, "can't open logfile %s\n", fname);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
@@ -2444,6 +2442,39 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel)
        return CMD_SUCCESS;
 }
 
+void command_setup_early_logging(const char *dest, const char *level)
+{
+       char *token;
+
+       if (level) {
+               int nlevel = level_match(level);
+
+               if (nlevel != ZLOG_DISABLED)
+                       zlog_default->default_lvl = nlevel;
+       }
+
+       if (!dest)
+               return;
+
+       if (strcmp(dest, "stdout") == 0) {
+               zlog_set_level(ZLOG_DEST_STDOUT, zlog_default->default_lvl);
+               return;
+       }
+
+       if (strcmp(dest, "syslog") == 0) {
+               zlog_set_level(ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
+               return;
+       }
+
+       token = strstr(dest, ":");
+       if (token == NULL)
+               return;
+
+       token++;
+
+       set_log_file(NULL, token, zlog_default->default_lvl);
+}
+
 DEFUN (config_log_file,
        config_log_file_cmd,
        "log file FILENAME [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
@@ -2551,36 +2582,6 @@ DEFUN (no_config_log_facility,
        return CMD_SUCCESS;
 }
 
-DEFUN_DEPRECATED(
-       config_log_trap, config_log_trap_cmd,
-       "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
-       "Logging control\n"
-       "(Deprecated) Set logging level and default for all destinations\n" LOG_LEVEL_DESC)
-{
-       int new_level;
-       int i;
-
-       if ((new_level = level_match(argv[2]->arg)) == ZLOG_DISABLED)
-               return CMD_ERR_NO_MATCH;
-
-       zlog_default->default_lvl = new_level;
-       for (i = 0; i < ZLOG_NUM_DESTS; i++)
-               if (zlog_default->maxlvl[i] != ZLOG_DISABLED)
-                       zlog_default->maxlvl[i] = new_level;
-       return CMD_SUCCESS;
-}
-
-DEFUN_DEPRECATED(
-       no_config_log_trap, no_config_log_trap_cmd,
-       "no log trap [emergencies|alerts|critical|errors|warnings|notifications|informational|debugging]",
-       NO_STR
-       "Logging control\n"
-       "Permit all logging information\n" LOG_LEVEL_DESC)
-{
-       zlog_default->default_lvl = LOG_DEBUG;
-       return CMD_SUCCESS;
-}
-
 DEFUN (config_log_record_priority,
        config_log_record_priority_cmd,
        "log record-priority",
@@ -2870,8 +2871,6 @@ void cmd_init(int terminal)
                install_element(CONFIG_NODE, &no_config_log_syslog_cmd);
                install_element(CONFIG_NODE, &config_log_facility_cmd);
                install_element(CONFIG_NODE, &no_config_log_facility_cmd);
-               install_element(CONFIG_NODE, &config_log_trap_cmd);
-               install_element(CONFIG_NODE, &no_config_log_trap_cmd);
                install_element(CONFIG_NODE, &config_log_record_priority_cmd);
                install_element(CONFIG_NODE,
                                &no_config_log_record_priority_cmd);