Skip to content

To improve the error handling of vtysh read config file #15568

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 42 additions & 0 deletions src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From 33a231ac26a46bfb728975d1695b7a71a7bc95ab Mon Sep 17 00:00:00 2001
From: stormliang <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this upstream patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I this is not upstream patch, I create this one.

Date: Wed, 21 Jun 2023 08:10:10 +0000
Subject: [PATCH] error handling improve

---
vtysh/vtysh.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 8e95aaa47..9df2011ce 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -25,6 +25,8 @@
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/stat.h>
+#include <string.h>
+#include <errno.h>

/* readline carries some ancient definitions around */
#pragma GCC diagnostic push
@@ -895,6 +897,16 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp)
}
}
}
+ if (feof(fp)) {
+ // Handle end-of-file (EOF) error
+ vty_out(vty, "fgets error: End of file reached.\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do we see such message, in syslog?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is not ready for review yet, make it as draft.

+ } else if (ferror(file)) {
+ // Handle general I/O error
+ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno));
+ } else {
+ // Handle other errors
+ vty_out(vty, "fgets error: Unknown error occurred.\n");
+ }

return (retcode);
}
--
2.25.1

1 change: 1 addition & 0 deletions src/sonic-frr/patch/series
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ cross-compile-changes.patch
0027-bgpd-Ensure-FRR-has-enough-data-to-read-in-peek_for_as4_capability-and-bgp_open_option_parse.patch
0028-bgpd-Ensure-that-bgp-open-message-stream-has-enough-data-to-read.patch
0029-bgpd-Change-log-level-for-graceful-restart-events.patch
0030-bgpd-error-handling-improve.patch