]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: straight return on error on log open fail
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 20 Sep 2023 12:46:10 +0000 (14:46 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 20 Sep 2023 12:46:10 +0000 (14:46 +0200)
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>
lib/zlog_5424.c

index 16f348369e0affbfa0c22e48fd994ad2416b2421..9bc1c819a8575249a69f35fec836948f119e45fd 100644 (file)
@@ -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