-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
StormLiangMS
wants to merge
3
commits into
sonic-net:master
Choose a base branch
from
StormLiangMS:error_handle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
From 4f50e545db4593121a2da0cab710cac4ad018d04 Mon Sep 17 00:00:00 2001 | ||
From: stormliang <[email protected]> | ||
Date: Sun, 25 Jun 2023 03:15:39 +0000 | ||
Subject: [PATCH] error handling improve | ||
|
||
--- | ||
lib/command.c | 15 +++++++++++++++ | ||
lib/command.h | 1 + | ||
vtysh/vtysh.c | 14 ++++++++++++++ | ||
3 files changed, 30 insertions(+) | ||
|
||
diff --git a/lib/command.c b/lib/command.c | ||
index 3718c1459..5f15f5469 100644 | ||
--- a/lib/command.c | ||
+++ b/lib/command.c | ||
@@ -51,6 +51,9 @@ | ||
|
||
#include "frrscript.h" | ||
|
||
+#include <string.h> | ||
+#include <errno.h> | ||
+ | ||
DEFINE_MTYPE_STATIC(LIB, HOST, "Host config"); | ||
DEFINE_MTYPE(LIB, COMPLETION, "Completion item"); | ||
|
||
@@ -1290,6 +1293,18 @@ int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num) | ||
&& ret != CMD_ERR_NOTHING_TODO) | ||
error_ret = ret; | ||
} | ||
+ if (feof(fp)) { | ||
+ // Handle end-of-file (EOF) error | ||
+ vty_out(vty, "End of file reached.\n"); | ||
+ } else if (ferror(fp)) { | ||
+ error_ret = CMD_ERR_READ_CONF_FILE; | ||
+ // Handle general I/O error | ||
+ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); | ||
+ } else { | ||
+ error_ret = CMD_ERR_READ_CONF_FILE; | ||
+ // Handle other errors | ||
+ vty_out(vty, "fgets error: Unknown error occurred.\n"); | ||
+ } | ||
|
||
if (error_ret) { | ||
return error_ret; | ||
diff --git a/lib/command.h b/lib/command.h | ||
index c888356d6..e38617737 100644 | ||
--- a/lib/command.h | ||
+++ b/lib/command.h | ||
@@ -236,6 +236,7 @@ struct cmd_node { | ||
#define CMD_NOT_MY_INSTANCE 14 | ||
#define CMD_NO_LEVEL_UP 15 | ||
#define CMD_ERR_NO_DAEMON 16 | ||
+#define CMD_ERR_READ_CONF_FILE 17 | ||
|
||
/* Argc max counts. */ | ||
#define CMD_ARGC_MAX 256 | ||
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c | ||
index 8e95aaa47..bbcdb90dc 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,18 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp) | ||
} | ||
} | ||
} | ||
+ if (feof(fp)) { | ||
+ // Handle end-of-file (EOF) error | ||
+ vty_out(vty, "End of file reached.\n"); | ||
+ } else if (ferror(fp)) { | ||
+ retcode = CMD_ERR_READ_CONF_FILE; | ||
+ // Handle general I/O error | ||
+ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); | ||
+ } else { | ||
+ retcode = CMD_ERR_READ_CONF_FILE; | ||
+ // Handle other errors | ||
+ vty_out(vty, "fgets error: Unknown error occurred.\n"); | ||
+ } | ||
|
||
return (retcode); | ||
} | ||
-- | ||
2.25.1 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this upstream patch?
There was a problem hiding this comment.
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.