mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 11:18:43 +00:00
lib: replace stderr with zlog in vty config load
Now that the logging hole is plugged, we can just print config-loading errors to the log. This has 2 hidden advantages: - vty_read_config calls in SIGHUP don't print errors to /dev/null - errors are consistently printed to syslog on --enable-cumulus Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
d34cb7f0b7
commit
b4fa7c95f9
48
lib/vty.c
48
lib/vty.c
@ -1852,7 +1852,7 @@ static void vty_serv_sock_addrinfo(const char *hostname, unsigned short port)
|
|||||||
ret = getaddrinfo(hostname, port_str, &req, &ainfo);
|
ret = getaddrinfo(hostname, port_str, &req, &ainfo);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(ret));
|
zlog_err("getaddrinfo failed: %s", gai_strerror(ret));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2246,23 +2246,22 @@ static void vty_read_file(FILE *confp)
|
|||||||
|
|
||||||
if (!((ret == CMD_SUCCESS) || (ret == CMD_ERR_NOTHING_TODO))) {
|
if (!((ret == CMD_SUCCESS) || (ret == CMD_ERR_NOTHING_TODO))) {
|
||||||
const char *message = NULL;
|
const char *message = NULL;
|
||||||
|
char *nl;
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case CMD_ERR_AMBIGUOUS:
|
case CMD_ERR_AMBIGUOUS:
|
||||||
message =
|
message = "Ambiguous command";
|
||||||
"*** Error reading config: Ambiguous command.";
|
|
||||||
break;
|
break;
|
||||||
case CMD_ERR_NO_MATCH:
|
case CMD_ERR_NO_MATCH:
|
||||||
message =
|
message = "No such command";
|
||||||
"*** Error reading config: There is no such command.";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s\n", message);
|
|
||||||
zlog_err("%s", message);
|
nl = strchr(vty->error_buf, '\n');
|
||||||
fprintf(stderr,
|
if (nl)
|
||||||
"*** Error occurred processing line %u, below:\n%s\n",
|
*nl = '\0';
|
||||||
line_num, vty->error_buf);
|
zlog_err("ERROR: %s on config line %u: %s",
|
||||||
zlog_err("*** Error occurred processing line %u, below:\n%s",
|
message, line_num, vty->error_buf);
|
||||||
line_num, vty->error_buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vty_close(vty);
|
vty_close(vty);
|
||||||
@ -2334,8 +2333,7 @@ void vty_read_config(const char *config_file, char *config_default_dir)
|
|||||||
if (config_file != NULL) {
|
if (config_file != NULL) {
|
||||||
if (!IS_DIRECTORY_SEP(config_file[0])) {
|
if (!IS_DIRECTORY_SEP(config_file[0])) {
|
||||||
if (getcwd(cwd, MAXPATHLEN) == NULL) {
|
if (getcwd(cwd, MAXPATHLEN) == NULL) {
|
||||||
fprintf(stderr,
|
zlog_err("Failure to determine Current Working Directory %d!",
|
||||||
"Failure to determine Current Working Directory %d!\n",
|
|
||||||
errno);
|
errno);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -2349,17 +2347,14 @@ void vty_read_config(const char *config_file, char *config_default_dir)
|
|||||||
confp = fopen(fullpath, "r");
|
confp = fopen(fullpath, "r");
|
||||||
|
|
||||||
if (confp == NULL) {
|
if (confp == NULL) {
|
||||||
fprintf(stderr,
|
zlog_err("%s: failed to open configuration file %s: %s",
|
||||||
"%s: failed to open configuration file %s: %s\n",
|
|
||||||
__func__, fullpath, safe_strerror(errno));
|
__func__, fullpath, safe_strerror(errno));
|
||||||
|
|
||||||
confp = vty_use_backup_config(fullpath);
|
confp = vty_use_backup_config(fullpath);
|
||||||
if (confp)
|
if (confp)
|
||||||
fprintf(stderr,
|
zlog_warn("WARNING: using backup configuration file!");
|
||||||
"WARNING: using backup configuration file!\n");
|
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,
|
zlog_err("can't open configuration file [%s]",
|
||||||
"can't open configuration file [%s]\n",
|
|
||||||
config_file);
|
config_file);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -2394,19 +2389,16 @@ void vty_read_config(const char *config_file, char *config_default_dir)
|
|||||||
#endif /* VTYSH */
|
#endif /* VTYSH */
|
||||||
confp = fopen(config_default_dir, "r");
|
confp = fopen(config_default_dir, "r");
|
||||||
if (confp == NULL) {
|
if (confp == NULL) {
|
||||||
fprintf(stderr,
|
zlog_err("%s: failed to open configuration file %s: %s",
|
||||||
"%s: failed to open configuration file %s: %s\n",
|
|
||||||
__func__, config_default_dir,
|
__func__, config_default_dir,
|
||||||
safe_strerror(errno));
|
safe_strerror(errno));
|
||||||
|
|
||||||
confp = vty_use_backup_config(config_default_dir);
|
confp = vty_use_backup_config(config_default_dir);
|
||||||
if (confp) {
|
if (confp) {
|
||||||
fprintf(stderr,
|
zlog_warn("WARNING: using backup configuration file!");
|
||||||
"WARNING: using backup configuration file!\n");
|
|
||||||
fullpath = config_default_dir;
|
fullpath = config_default_dir;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
zlog_err("can't open configuration file [%s]",
|
||||||
"can't open configuration file [%s]\n",
|
|
||||||
config_default_dir);
|
config_default_dir);
|
||||||
goto tmp_free_and_out;
|
goto tmp_free_and_out;
|
||||||
}
|
}
|
||||||
@ -2916,12 +2908,12 @@ static void vty_save_cwd(void)
|
|||||||
* Hence not worrying about it too much.
|
* Hence not worrying about it too much.
|
||||||
*/
|
*/
|
||||||
if (!chdir(SYSCONFDIR)) {
|
if (!chdir(SYSCONFDIR)) {
|
||||||
fprintf(stderr, "Failure to chdir to %s, errno: %d\n",
|
zlog_err("Failure to chdir to %s, errno: %d",
|
||||||
SYSCONFDIR, errno);
|
SYSCONFDIR, errno);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
if (getcwd(cwd, MAXPATHLEN) == NULL) {
|
if (getcwd(cwd, MAXPATHLEN) == NULL) {
|
||||||
fprintf(stderr, "Failure to getcwd, errno: %d\n",
|
zlog_err("Failure to getcwd, errno: %d",
|
||||||
errno);
|
errno);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user