Merge pull request #4879 from qlyoung/fix-vtysh-of-crashy

vtysh: fix rare crash(es)
This commit is contained in:
Mark Stapp 2019-08-26 08:30:10 -04:00 committed by GitHub
commit 7c6824fdbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,9 +164,10 @@ static int vtysh_reconnect(struct vtysh_client *vclient);
static void vclient_close(struct vtysh_client *vclient) static void vclient_close(struct vtysh_client *vclient)
{ {
if (vclient->fd >= 0) { if (vclient->fd >= 0) {
vty_out(vty, if (vty->of)
"Warning: closing connection to %s because of an I/O error!\n", vty_out(vty,
vclient->name); "Warning: closing connection to %s because of an I/O error!\n",
vclient->name);
close(vclient->fd); close(vclient->fd);
/* indicate as candidate for reconnect */ /* indicate as candidate for reconnect */
vclient->fd = VTYSH_WAS_ACTIVE; vclient->fd = VTYSH_WAS_ACTIVE;
@ -237,8 +238,11 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line,
continue; continue;
if (nread <= 0) { if (nread <= 0) {
vty_out(vty, "vtysh: error reading from %s: %s (%d)", if (vty->of)
vclient->name, safe_strerror(errno), errno); vty_out(vty,
"vtysh: error reading from %s: %s (%d)",
vclient->name, safe_strerror(errno),
errno);
goto out_err; goto out_err;
} }
@ -383,7 +387,7 @@ static int vtysh_client_run_all(struct vtysh_client *head_client,
rc_all = rc; rc_all = rc;
} }
} }
if (wrong_instance && !correct_instance) { if (wrong_instance && !correct_instance && vty->of) {
vty_out(vty, vty_out(vty,
"%% [%s]: command ignored as it targets an instance that is not running\n", "%% [%s]: command ignored as it targets an instance that is not running\n",
head_client->name); head_client->name);