]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/buffer.c
Merge pull request #5793 from ton31337/fix/formatting_show_bgp_summary_failed
[mirror_frr.git] / lib / buffer.c
index 03202f125307b4d7425db7aba25749cc89254e8d..766b9791a5d5034e5856239bb3e2e3ba2bd6ea94 100644 (file)
@@ -25,6 +25,8 @@
 #include "buffer.h"
 #include "log.h"
 #include "network.h"
+#include "lib_errors.h"
+
 #include <stddef.h>
 
 DEFINE_MTYPE_STATIC(LIB, BUFFER, "Buffer")
@@ -112,12 +114,6 @@ char *buffer_getstr(struct buffer *b)
        return s;
 }
 
-/* Return 1 if buffer is empty. */
-int buffer_empty(struct buffer *b)
-{
-       return (b->head == NULL);
-}
-
 /* Clear and free all allocated data. */
 void buffer_reset(struct buffer *b)
 {
@@ -272,19 +268,12 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width,
        if (!b->head)
                return BUFFER_EMPTY;
 
-       if (height < 1) {
-               zlog_warn(
-                       "%s called with non-positive window height %d, forcing to 1",
-                       __func__, height);
+       if (height < 1)
                height = 1;
-       else if (height >= 2)
+       else if (height >= 2)
                height--;
-       if (width < 1) {
-               zlog_warn(
-                       "%s called with non-positive window width %d, forcing to 1",
-                       __func__, width);
+       if (width < 1)
                width = 1;
-       }
 
        /* For erase and more data add two to b's buffer_data count.*/
        if (b->head->next == NULL) {
@@ -332,16 +321,12 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width,
                {
                        iov_alloc *= 2;
                        if (iov != small_iov) {
-                               zlog_warn(
-                                       "%s: growing iov array to %d; "
-                                       "width %d, height %d, size %lu",
-                                       __func__, iov_alloc, width, height,
-                                       (unsigned long)b->size);
                                iov = XREALLOC(MTYPE_TMP, iov,
                                               iov_alloc * sizeof(*iov));
                        } else {
                                /* This should absolutely never occur. */
-                               zlog_err(
+                               flog_err_sys(
+                                       EC_LIB_SYSTEM_CALL,
                                        "%s: corruption detected: iov_small overflowed; "
                                        "head %p, tail %p, head->next %p",
                                        __func__, (void *)b->head,
@@ -374,8 +359,9 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width,
                        iov_size =
                                ((iov_index > IOV_MAX) ? IOV_MAX : iov_index);
                        if ((nbytes = writev(fd, c_iov, iov_size)) < 0) {
-                               zlog_warn("%s: writev to fd %d failed: %s",
-                                         __func__, fd, safe_strerror(errno));
+                               flog_err(EC_LIB_SOCKET,
+                                        "%s: writev to fd %d failed: %s",
+                                        __func__, fd, safe_strerror(errno));
                                break;
                        }
 
@@ -386,8 +372,8 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width,
        }
 #else  /* IOV_MAX */
        if ((nbytes = writev(fd, iov, iov_index)) < 0)
-               zlog_warn("%s: writev to fd %d failed: %s", __func__, fd,
-                         safe_strerror(errno));
+               flog_err(EC_LIB_SOCKET, "%s: writev to fd %d failed: %s",
+                        __func__, fd, safe_strerror(errno));
 #endif /* IOV_MAX */
 
        /* Free printed buffer data. */
@@ -429,6 +415,9 @@ in one shot. */
        size_t iovcnt = 0;
        size_t nbyte = 0;
 
+       if (fd < 0)
+               return BUFFER_ERROR;
+
        for (d = b->head; d && (iovcnt < MAX_CHUNKS) && (nbyte < MAX_FLUSH);
             d = d->next, iovcnt++) {
                iov[iovcnt].iov_base = d->data + d->sp;
@@ -444,18 +433,17 @@ in one shot. */
                if (ERRNO_IO_RETRY(errno))
                        /* Calling code should try again later. */
                        return BUFFER_PENDING;
-               zlog_warn("%s: write error on fd %d: %s", __func__, fd,
-                         safe_strerror(errno));
+               flog_err(EC_LIB_SOCKET, "%s: write error on fd %d: %s",
+                        __func__, fd, safe_strerror(errno));
                return BUFFER_ERROR;
        }
 
        /* Free printed buffer data. */
        while (written > 0) {
-               struct buffer_data *d;
                if (!(d = b->head)) {
-                       zlog_err(
-                               "%s: corruption detected: buffer queue empty, "
-                               "but written is %lu",
+                       flog_err(
+                               EC_LIB_DEVELOPMENT,
+                               "%s: corruption detected: buffer queue empty, but written is %lu",
                                __func__, (unsigned long)written);
                        break;
                }
@@ -499,8 +487,8 @@ buffer_status_t buffer_write(struct buffer *b, int fd, const void *p,
                if (ERRNO_IO_RETRY(errno))
                        nbytes = 0;
                else {
-                       zlog_warn("%s: write error on fd %d: %s", __func__, fd,
-                                 safe_strerror(errno));
+                       flog_err(EC_LIB_SOCKET, "%s: write error on fd %d: %s",
+                                __func__, fd, safe_strerror(errno));
                        return BUFFER_ERROR;
                }
        }