From a32f6a107fd2b9ed8295a6a3879c6aa2da3464d1 Mon Sep 17 00:00:00 2001 From: Yaroslav Fedoriachenko Date: Tue, 17 Aug 2021 18:30:03 +0300 Subject: [PATCH] vtysh: Add error code if daemon is not running After ` is not running` message vtysh does not return error. For example if you disable ospf in `/etc/frr/daemons` and run `vtysh -c configure -c "router ospf"` it prints the message to stderr, but returns 0. This commit will make vtysh return error when not in interractive mode. But if you run commands from vtysh, you will still be able to enter views and exit them if daemon is not running. Signed-off-by: Yaroslav Fedoriachenko --- lib/command.h | 1 + vtysh/vtysh.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/command.h b/lib/command.h index c76fc1e8e..8a7c9a204 100644 --- a/lib/command.h +++ b/lib/command.h @@ -229,6 +229,7 @@ struct cmd_node { #define CMD_WARNING_CONFIG_FAILED 13 #define CMD_NOT_MY_INSTANCE 14 #define CMD_NO_LEVEL_UP 15 +#define CMD_ERR_NO_DAEMON 16 /* Argc max counts. */ #define CMD_ARGC_MAX 256 diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index b74360c75..beb7045a7 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -602,7 +602,8 @@ static int vtysh_execute_func(const char *line, int pager) fprintf(stderr, "%s is not running\n", vtysh_client[i].name); - continue; + cmd_stat = CMD_ERR_NO_DAEMON; + break; } } cmd_stat = vtysh_client_execute( @@ -611,7 +612,7 @@ static int vtysh_execute_func(const char *line, int pager) break; } } - if (cmd_stat != CMD_SUCCESS) + if (cmd_stat != CMD_SUCCESS && cmd_stat != CMD_ERR_NO_DAEMON) break; if (cmd->func)