summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2023-09-20 14:46:10 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2023-09-20 14:46:10 +0200
commite408a915a3c6d808d6f522f9e124b7079b2a6e33 (patch)
tree4c6af58aed1d23d9b74006d3d304e5a6c9880b98
parentlib: add dup() error check in logging code (diff)
downloadfrr-e408a915a3c6d808d6f522f9e124b7079b2a6e33.tar.xz
frr-e408a915a3c6d808d6f522f9e124b7079b2a6e33.zip
lib: straight return on error on log open fail
I think I originally had some other code at the tail end of that function, but that's not the case anymore, and dropping out of the function with a straight "return -1" is more useful than trucking on with an invalid fd. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r--lib/zlog_5424.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/zlog_5424.c b/lib/zlog_5424.c
index 16f348369..9bc1c819a 100644
--- a/lib/zlog_5424.c
+++ b/lib/zlog_5424.c
@@ -877,14 +877,14 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
switch (zcf->dst) {
case ZLOG_5424_DST_NONE:
- break;
+ return -1;
case ZLOG_5424_DST_FD:
fd = dup(zcf->fd);
if (fd < 0) {
flog_err_sys(EC_LIB_SYSTEM_CALL,
"failed to dup() log file descriptor: %m (FD limit too low?)");
- break;
+ return -1;
}
optlen = sizeof(sock_type);
@@ -896,7 +896,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
case ZLOG_5424_DST_FIFO:
if (!zcf->filename)
- break;
+ return -1;
if (!zcf->file_nocreate) {
frr_with_privs (lib_privs) {
@@ -909,7 +909,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
if (err == 0)
do_chown = true;
else if (errno != EEXIST)
- break;
+ return -1;
}
flags = O_NONBLOCK;
@@ -917,7 +917,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
case ZLOG_5424_DST_FILE:
if (!zcf->filename)
- break;
+ return -1;
frr_with_privs (lib_privs) {
fd = open(zcf->filename, flags | O_WRONLY | O_APPEND |
@@ -929,7 +929,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
flog_err_sys(EC_LIB_SYSTEM_CALL,
"could not open log file %pSE: %m",
zcf->filename);
- break;
+ return -1;
}
frr_with_privs (lib_privs) {
@@ -957,11 +957,11 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
flog_err_sys(EC_LIB_SYSTEM_CALL,
"could not open or create log file %pSE: %m",
zcf->filename);
- break;
+ return -1;
case ZLOG_5424_DST_UNIX:
if (!zcf->filename)
- break;
+ return -1;
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
@@ -993,6 +993,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
"could not connect to log unix path %pSE: %m",
zcf->filename);
need_reconnect = true;
+ /* no return -1 here, trigger retry code below */
} else {
/* datagram sockets are connectionless, restarting
* the receiver may lose some packets but will resume