Add a new error code LIB_ERR_SYSTEM_CALL to the ferr subsystem.
Additionally convert LIB_ERR_VRF_SOCKET to a more generic
LIB_ERR_SOCKET.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
#include "buffer.h"
#include "log.h"
#include "network.h"
+#include "lib_errors.h"
+
#include <stddef.h>
DEFINE_MTYPE_STATIC(LIB, BUFFER, "Buffer")
iov_alloc * sizeof(*iov));
} else {
/* This should absolutely never occur. */
- zlog_err(
- "%s: corruption detected: iov_small overflowed; "
- "head %p, tail %p, head->next %p",
- __func__, (void *)b->head,
- (void *)b->tail, (void *)b->head->next);
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "%s: corruption detected: iov_small overflowed; "
+ "head %p, tail %p, head->next %p",
+ __func__, (void *)b->head,
+ (void *)b->tail, (void *)b->head->next);
iov = XMALLOC(MTYPE_TMP,
iov_alloc * sizeof(*iov));
memcpy(iov, small_iov, sizeof(small_iov));
#include "libfrr.h"
#include "jhash.h"
#include "hook.h"
+#include "lib_errors.h"
DEFINE_MTYPE(LIB, HOST, "Host config")
DEFINE_MTYPE(LIB, COMPLETION, "Completion item")
cwd[MAXPATHLEN] = '\0';
if (getcwd(cwd, MAXPATHLEN) == NULL) {
- zlog_err("config_log_file: Unable to alloc mem!");
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "config_log_file: Unable to alloc mem!");
return CMD_WARNING_CONFIG_FAILED;
}
.suggestion = "Ensure that there is sufficient memory to start processes and restart FRR",
},
{
- .code = LIB_ERR_VRF_SOCKET,
- .title = "VRF Socket Error",
- .description = "When attempting to access a socket for the VRF specified, we\nwere unable to properly complete the request",
+ .code = LIB_ERR_SOCKET,
+ .title = "Socket Error",
+ .description = "When attempting to access a socket a system error has occured\nand we were unable to properly complete the request",
.suggestion = "Ensure that there is sufficient system resources available and\nensure that the frr user has sufficient permisions to work",
},
{
.suggestion = "Restart FRR"
},
{
- .code = END_FERR
+ .code = LIB_ERR_SYSTEM_CALL,
+ .title = "System Call Error",
+ .description = "FRR has detected a error from using a vital system call and has probably\nalready exited",
+ .suggestion = "Ensure permissions are correct for FRR and FRR user and groups are correct\nAdditionally check that system resources are still available"
+ },
+ {
+ .code = END_FERR,
}
};
enum lib_ferr_refs {
LIB_ERR_PRIVILEGES = LIB_FERR_START,
LIB_ERR_VRF_START,
- LIB_ERR_VRF_SOCKET,
+ LIB_ERR_SOCKET,
LIB_ERR_ZAPI_MISSMATCH,
LIB_ERR_ZAPI_ENCODE,
LIB_ERR_ZAPI_SOCKET,
+ LIB_ERR_SYSTEM_CALL,
};
extern void lib_error_init(void);
#include "log_int.h"
#include "memory.h"
#include "command.h"
+#include "lib_errors.h"
+
#ifndef SUNOS_5
#include <sys/un.h>
#endif
size = backtrace(array, array_size(array));
if (size <= 0 || (size_t)size > array_size(array)) {
- zlog_err(
- "Cannot get backtrace, returned invalid # of frames %d "
- "(valid range is between 1 and %lu)",
- size, (unsigned long)(array_size(array)));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Cannot get backtrace, returned invalid # of frames %d "
+ "(valid range is between 1 and %lu)",
+ size, (unsigned long)(array_size(array)));
return;
}
zlog(priority, "Backtrace for %d stack frames:", size);
if (!(strings = backtrace_symbols(array, size))) {
- zlog_err("Cannot get backtrace symbols (out of memory?)");
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Cannot get backtrace symbols (out of memory?)");
for (i = 0; i < size; i++)
zlog(priority, "[bt %d] %p", i, array[i]);
} else {
void memory_oom(size_t size, const char *name)
{
- zlog_err(
- "out of memory: failed to allocate %zu bytes for %s"
- "object",
- size, name);
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "out of memory: failed to allocate %zu bytes for %s"
+ "object",
+ size, name);
zlog_backtrace(LOG_ERR);
abort();
}
save_errno = errno;
umask(oldumask);
if (zl->fp == NULL) {
- zlog_err(
- "Log rotate failed: cannot open file %s for append: %s",
- zl->filename, safe_strerror(save_errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Log rotate failed: cannot open file %s for append: %s",
+ zl->filename, safe_strerror(save_errno));
ret = -1;
} else {
logfile_fd = fileno(zl->fp);
#include "ns.h"
#include "log.h"
#include "memory.h"
-
#include "command.h"
#include "vty.h"
#include "vrf.h"
+#include "lib_errors.h"
DEFINE_MTYPE_STATIC(LIB, NS, "NetNS Context")
DEFINE_MTYPE_STATIC(LIB, NS_NAME, "NetNS Name")
}
if (!ns_is_enabled(ns)) {
- zlog_err("Can not enable NS %u: %s!", ns->ns_id,
- safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Can not enable NS %u: %s!", ns->ns_id,
+ safe_strerror(errno));
return 0;
}
#include <log.h>
#include "version.h"
#include "network.h"
+#include "lib_errors.h"
#define PIDFILE_MASK 0644
oldumask = umask(0777 & ~PIDFILE_MASK);
fd = open(path, O_RDWR | O_CREAT, PIDFILE_MASK);
if (fd < 0) {
- zlog_err("Can't create pid lock file %s (%s), exiting", path,
- safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Can't create pid lock file %s (%s), exiting", path,
+ safe_strerror(errno));
umask(oldumask);
exit(1);
} else {
lock.l_whence = SEEK_SET;
if (fcntl(fd, F_SETLK, &lock) < 0) {
- zlog_err("Could not lock pid_file %s (%s), exiting",
- path, safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Could not lock pid_file %s (%s), exiting",
+ path, safe_strerror(errno));
exit(1);
}
sprintf(buf, "%d\n", (int)pid);
pidsize = strlen(buf);
if ((tmp = write(fd, buf, pidsize)) != (int)pidsize)
- zlog_err(
- "Could not write pid %d to pid_file %s, rc was %d: %s",
- (int)pid, path, tmp, safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Could not write pid %d to pid_file %s, rc was %d: %s",
+ (int)pid, path, tmp, safe_strerror(errno));
else if (ftruncate(fd, pidsize) < 0)
- zlog_err(
- "Could not truncate pid_file %s to %u bytes: %s",
- path, (unsigned int)pidsize,
- safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Could not truncate pid_file %s to %u bytes: %s",
+ path, (unsigned int)pidsize,
+ safe_strerror(errno));
}
return pid;
}
#include <sigevent.h>
#include <log.h>
#include <memory.h>
+#include <lib_errors.h>
#ifdef SA_SIGINFO
#ifdef HAVE_UCONTEXT_H
sigdelset(&newmask, SIGKILL);
if ((sigprocmask(SIG_BLOCK, &newmask, &oldmask)) < 0) {
- zlog_err("quagga_signal_timer: couldnt block signals!");
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "quagga_signal_timer: couldnt block signals!");
return -1;
}
#endif /* SIGEVENT_BLOCK_SIGNALS */
#include "log.h"
#include "sockopt.h"
#include "sockunion.h"
+#include "lib_errors.h"
void setsockopt_so_recvbuf(int sock, int size)
{
int ret = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&optval,
&optlen);
if (ret < 0) {
- zlog_err("fd %d: can't getsockopt SO_SNDBUF: %d (%s)", sock,
- errno, safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "fd %d: can't getsockopt SO_SNDBUF: %d (%s)", sock,
+ errno, safe_strerror(errno));
return ret;
}
return optval;
if (ENOENT == errno)
ret = 0;
else
- zlog_err("sockopt_tcp_signature: setsockopt(%d): %s",
- sock, safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "sockopt_tcp_signature: setsockopt(%d): %s",
+ sock, safe_strerror(errno));
}
return ret;
#else /* HAVE_TCP_MD5SIG */
ret = vrf_switch_to_netns(vrf_id);
if (ret < 0)
- zlog_ferr(LIB_ERR_VRF_SOCKET,
+ zlog_ferr(LIB_ERR_SOCKET,
"%s: Can't switch to VRF %u (%s)", __func__, vrf_id,
safe_strerror(errno));
save_errno = errno;
ret2 = vrf_switchback_to_initial();
if (ret2 < 0)
- zlog_ferr(LIB_ERR_VRF_SOCKET,
+ zlog_ferr(LIB_ERR_SOCKET,
"%s: Can't switchback from VRF %u (%s)", __func__,
vrf_id, safe_strerror(errno));
errno = save_errno;
ret = vrf_switch_to_netns(vrf_id);
if (ret < 0)
- zlog_ferr(LIB_ERR_VRF_SOCKET,
+ zlog_ferr(LIB_ERR_SOCKET,
"%s: Can't switch to VRF %u (%s)", __func__, vrf_id,
safe_strerror(errno));
ret = getaddrinfo(node, service, hints, res);
save_errno = errno;
ret2 = vrf_switchback_to_initial();
if (ret2 < 0)
- zlog_ferr(LIB_ERR_VRF_SOCKET,
+ zlog_ferr(LIB_ERR_SOCKET,
"%s: Can't switchback from VRF %u (%s)", __func__,
vrf_id, safe_strerror(errno));
errno = save_errno;
ret = vrf_switch_to_netns(vrf_id);
if (ret < 0) {
- zlog_ferr(LIB_ERR_VRF_SOCKET,
+ zlog_ferr(LIB_ERR_SOCKET,
"%s: Can't switch to VRF %u (%s)", __func__, vrf_id,
safe_strerror(errno));
return 0;
saved_errno = errno;
ret = vrf_switchback_to_initial();
if (ret < 0)
- zlog_ferr(LIB_ERR_VRF_SOCKET,
+ zlog_ferr(LIB_ERR_SOCKET,
"%s: Can't switchback from VRF %u (%s)", __func__,
vrf_id, safe_strerror(errno));
errno = saved_errno;
ret = vrf_switch_to_netns(vrf_id);
if (ret < 0)
- zlog_ferr(LIB_ERR_VRF_SOCKET,
+ zlog_ferr(LIB_ERR_SOCKET,
"%s: Can't switch to VRF %u (%s)", __func__, vrf_id,
safe_strerror(errno));
ret = sockunion_socket(su);
save_errno = errno;
ret2 = vrf_switchback_to_initial();
if (ret2 < 0)
- zlog_ferr(LIB_ERR_VRF_SOCKET,
+ zlog_ferr(LIB_ERR_SOCKET,
"%s: Can't switchback from VRF %u (%s)", __func__,
vrf_id, safe_strerror(errno));
errno = save_errno;
ret = getaddrinfo(hostname, port_str, &req, &ainfo);
if (ret != 0) {
- zlog_err("getaddrinfo failed: %s", gai_strerror(ret));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "getaddrinfo failed: %s", gai_strerror(ret));
exit(1);
}
/* Make UNIX domain socket. */
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
- zlog_err("Cannot create unix stream socket: %s",
+ zlog_ferr(LIB_ERR_SOCKET,
+ "Cannot create unix stream socket: %s",
safe_strerror(errno));
return;
}
ret = bind(sock, (struct sockaddr *)&serv, len);
if (ret < 0) {
- zlog_err("Cannot bind path %s: %s", path, safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SOCKET,
+ "Cannot bind path %s: %s",
+ path, safe_strerror(errno));
close(sock); /* Avoid sd leak. */
return;
}
ret = listen(sock, 5);
if (ret < 0) {
- zlog_err("listen(fd %d) failed: %s", sock,
- safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SOCKET,
+ "listen(fd %d) failed: %s", sock,
+ safe_strerror(errno));
close(sock); /* Avoid sd leak. */
return;
}
if ((int)ids.gid_vty > 0) {
/* set group of socket */
if (chown(path, -1, ids.gid_vty)) {
- zlog_err("vty_serv_un: could chown socket, %s",
- safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "vty_serv_un: could chown socket, %s",
+ safe_strerror(errno));
}
}
if (config_file != NULL) {
if (!IS_DIRECTORY_SEP(config_file[0])) {
if (getcwd(cwd, MAXPATHLEN) == NULL) {
- zlog_err(
- "Failure to determine Current Working Directory %d!",
- errno);
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Failure to determine Current Working Directory %d!",
+ errno);
exit(1);
}
tmp = XMALLOC(MTYPE_TMP,
confp = fopen(fullpath, "r");
if (confp == NULL) {
- zlog_err("%s: failed to open configuration file %s: %s",
+ zlog_warn("%s: failed to open configuration file %s: %s, checking backup",
__func__, fullpath, safe_strerror(errno));
confp = vty_use_backup_config(fullpath);
#endif /* VTYSH */
confp = fopen(config_default_dir, "r");
if (confp == NULL) {
- zlog_err("%s: failed to open configuration file %s: %s",
- __func__, config_default_dir,
- safe_strerror(errno));
+ zlog_warn("%s: failed to open configuration file %s: %s, checking backup",
+ __func__, config_default_dir,
+ safe_strerror(errno));
confp = vty_use_backup_config(config_default_dir);
if (confp) {
* Hence not worrying about it too much.
*/
if (!chdir(SYSCONFDIR)) {
- zlog_err("Failure to chdir to %s, errno: %d",
- SYSCONFDIR, errno);
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Failure to chdir to %s, errno: %d",
+ SYSCONFDIR, errno);
exit(-1);
}
if (getcwd(cwd, MAXPATHLEN) == NULL) {
- zlog_err("Failure to getcwd, errno: %d", errno);
+ zlog_ferr(LIB_ERR_SYSTEM_CALL,
+ "Failure to getcwd, errno: %d", errno);
exit(-1);
}
}