]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Log failures to allocate receive buffers.
authorDave Hart <hart@ntp.org>
Mon, 15 Apr 2024 22:28:07 +0000 (22:28 +0000)
committerDave Hart <hart@ntp.org>
Mon, 15 Apr 2024 22:28:07 +0000 (22:28 +0000)
bk: 661da9f7Lqm5Yio4HJHgYeohvknUdw

ChangeLog
libntp/recvbuff.c

index 401140f76fea3e4b213d5240eb930e483acefd0a..cd6ec708df4b05a6b6f9e4f1cf506fe8de811d13 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -54,6 +54,7 @@
              is disabled.  <burnicki@ntp.org>
 * [Bug 3825] Don't touch HTML files unless building inside a BK repo.
              Fix the script checkHtmlFileDates.  <burnicki@ntp.org>
+* Log failures to allocate receive buffers.  <hart@ntp.org>
 * Remove extraneous */ from libparse/ieee754io.c
 * Fix .datecheck target line in Makefile.am.  <stenn@ntp.org>
 * Update the copyright year.  <stenn@ntp.org>
index d84a87d685019978c753e7271197d7c01f7aafc2..6e7cda5d373d982b89ceb0db0dec0f0efb6aa7d3 100644 (file)
@@ -93,41 +93,54 @@ initialise_buffer(recvbuf_t *buff)
 
 static void
 create_buffers(
-       size_t          nbufs)
+       size_t                  nbufs
+)
 {
+       static const u_int      chunk =
 #   ifndef DEBUG
-       static const u_int chunk = RECV_INC;
+                                       RECV_INC;
 #   else
        /* Allocate each buffer individually so they can be free()d
         * during ntpd shutdown on DEBUG builds to keep them out of heap
         * leak reports.
         */
-       static const u_int chunk = 1;
+                                       1;
 #   endif
-
-       register recvbuf_t *bufp;
-       u_int i;
-       size_t abuf;
+       static int/*BOOL*/      doneonce;
+       recvbuf_t *             bufp;
+       u_int                   i;
+       size_t                  abuf;
 
        /*[bug 3666]: followup -- reset shortfalls in all cases */
        abuf = nbufs + buffer_shortfall;
        buffer_shortfall = 0;
 
-       if (limit_recvbufs <= total_recvbufs)
+       if (limit_recvbufs <= total_recvbufs) {
+               if (!doneonce) {
+                       msyslog(LOG_CRIT, "Unable to allocate receive"
+                                         " buffer, %lu/%lu",
+                               total_recvbufs, limit_recvbufs);
+                       doneonce = TRUE;
+               }
                return;
-       
-       if (abuf < nbufs || abuf > RECV_BATCH)
+       }
+
+       if (abuf < nbufs || abuf > RECV_BATCH) {
                abuf = RECV_BATCH;      /* clamp on overflow */
-       else
+       } else {
                abuf += (~abuf + 1) & (RECV_INC - 1);   /* round up */
-       
-       if (abuf > (limit_recvbufs - total_recvbufs))
+       }
+       if (abuf > (limit_recvbufs - total_recvbufs)) {
                abuf = limit_recvbufs - total_recvbufs;
+       }
        abuf += (~abuf + 1) & (chunk - 1);              /* round up */
        
        while (abuf) {
                bufp = calloc(chunk, sizeof(*bufp));
                if (!bufp) {
+                       msyslog(LOG_CRIT, "Out of memory, allocating "
+                                         "%u recvbufs, %lu bytes",
+                               chunk, (u_long)sizeof(*bufp) * chunk);
                        limit_recvbufs = total_recvbufs;
                        break;
                }