Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtysh: only show error codes once #4732

Merged
merged 2 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/ferr.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json)

if (code) {
ref = log_ref_get(code);
if (!ref) {
vty_out(vty, "Code %"PRIu32" - Unknown\n", code);
if (!ref)
return;
}
listnode_add(errlist, ref);
}

Expand Down Expand Up @@ -197,8 +195,6 @@ void log_ref_init(void)
"Error Reference Texts");
}
pthread_mutex_unlock(&refs_mtx);

install_element(VIEW_NODE, &show_error_code_cmd);
}

void log_ref_fini(void)
Expand All @@ -212,6 +208,12 @@ void log_ref_fini(void)
pthread_mutex_unlock(&refs_mtx);
}

void log_ref_vty_init(void)
{
install_element(VIEW_NODE, &show_error_code_cmd);
}


const struct ferr *ferr_get_last(ferr_r errval)
{
struct ferr *last_error = pthread_getspecific(errkey);
Expand Down
1 change: 1 addition & 0 deletions lib/ferr.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json);
*/
void log_ref_init(void);
void log_ref_fini(void);
void log_ref_vty_init(void);

/* get error details.
*
Expand Down
1 change: 1 addition & 0 deletions lib/libfrr.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ struct thread_master *frr_init(void)
log_filter_cmd_init();

log_ref_init();
log_ref_vty_init();
lib_error_init();

yang_init();
Expand Down
30 changes: 22 additions & 8 deletions vtysh/vtysh.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "command_graph.h"
#include "frrstr.h"
#include "json.h"
#include "ferr.h"

DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy")

Expand Down Expand Up @@ -2394,17 +2395,30 @@ DEFUN (vtysh_show_error_code,
"Information on all errors\n"
JSON_STR)
{
char *fcmd = argv_concat(argv, argc, 0);
char cmd[256];
int rv;
uint32_t arg = 0;

snprintf(cmd, sizeof(cmd), "do %s", fcmd);
if (!strmatch(argv[2]->text, "all"))
arg = strtoul(argv[2]->arg, NULL, 10);

/* FIXME: Needs to determine which daemon to send to via code ranges */
rv = show_per_daemon(cmd, "");
/* If it's not a shared code, send it to all the daemons */
if (arg < LIB_FERR_START || arg > LIB_FERR_END) {
char *fcmd = argv_concat(argv, argc, 0);
char cmd[256];

XFREE(MTYPE_TMP, fcmd);
return rv;
snprintf(cmd, sizeof(cmd), "do %s", fcmd);
show_per_daemon(cmd, "");
XFREE(MTYPE_TMP, fcmd);
/* Otherwise, print it ourselves to avoid duplication */
} else {
bool json = strmatch(argv[argc - 1]->text, "json");

if (!strmatch(argv[2]->text, "all"))
arg = strtoul(argv[2]->arg, NULL, 10);

log_ref_display(vty, arg, json);
}

return CMD_SUCCESS;
}

/* Memory */
Expand Down
5 changes: 5 additions & 0 deletions vtysh/vtysh_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include "linklist.h"
#include "memory_vty.h"
#include "libfrr.h"
#include "ferr.h"
#include "lib_errors.h"

#include "vtysh/vtysh.h"
#include "vtysh/vtysh_user.h"
Expand Down Expand Up @@ -461,6 +463,9 @@ int main(int argc, char **argv, char **env)
vtysh_read_config(vtysh_config);
suid_off();
}
/* Error code library system */
log_ref_init();
lib_error_init();

if (markfile) {
if (!inputfile) {
Expand Down