]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Remove 1024 associations-per-server limit from ntpq.
authorDave Hart <hart@ntp.org>
Mon, 2 Jul 2012 02:17:35 +0000 (02:17 +0000)
committerDave Hart <hart@ntp.org>
Mon, 2 Jul 2012 02:17:35 +0000 (02:17 +0000)
Remove blank line between ntpq mreadvar associations.

bk: 4ff104bfA2R2TrHTe-Sg0E4fDJFd8Q

ChangeLog
ntpq/ntpq-subs.c
ntpq/ntpq.c
ntpq/ntpq.h

index 5f89a1313408699f4a435887f666c3a4b5b5964f..828ba4693be9d6cf9165cb566888fbe3e78aa0ec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+* Remove 1024 associations-per-server limit from ntpq.
+* Remove blank line between ntpq mreadvar associations.
 (4.2.7p286) 2012/06/28 Released by Harlan Stenn <stenn@ntp.org>
 * CID 97193: check return from sscanf() in ntp_config.c.
 * CID 709169: check return from open("/dev/null", 0) and friends.
index 2297d313254ddded8e7cd85cf77ea749eb118fe2..52e952b868755e1776337846da0f817154fda06c 100644 (file)
@@ -280,7 +280,7 @@ struct varlist {
 extern int showhostnames;
 extern int rawmode;
 extern struct servent *server_entry;
-extern struct association assoc_cache[];
+extern struct association *assoc_cache;
 extern u_char pktversion;
 
 typedef struct mru_tag mru;
@@ -1035,8 +1035,6 @@ mreadvar(
        }
 
        for (i = from; i <= to; i++) {
-               if (i != from)
-                       fprintf(fp, "\n");
                if (!dolist(pvars, assoc_cache[i].assid, CTL_OP_READVAR,
                            TYPE_PEER, fp))
                        break;
@@ -1086,22 +1084,27 @@ dogetassoc(
        }
 
        numassoc = 0;
+
        while (dsize > 0) {
+               if (numassoc >= assoc_cache_slots) {
+                       grow_assoc_cache();
+               }
                pus = (const void *)datap;
                assoc_cache[numassoc].assid = ntohs(*pus);
-               datap += sizeof(u_short);
+               datap += sizeof(*pus);
                pus = (const void *)datap;
                assoc_cache[numassoc].status = ntohs(*pus);
-               datap += sizeof(u_short);
-               if (debug)
+               datap += sizeof(*pus);
+               dsize -= 2 * sizeof(*pus);
+               if (debug) {
                        fprintf(stderr, "[%u] ",
                                assoc_cache[numassoc].assid);
-               if (++numassoc >= MAXASSOC)
-                       break;
-               dsize -= sizeof(u_short) + sizeof(u_short);
+               }
+               numassoc++;
        }
-       if (debug)
+       if (debug) {
                fprintf(stderr, "\n%d associations total\n", numassoc);
+       }
        sortassoc();
        return 1;
 }
index 0474b2f565c9888fa0eef228394c1d7369e2b18a..f8257850b87e262d9e70235da614079686907303 100644 (file)
@@ -340,9 +340,13 @@ u_short sequence;
 long pktdata[DATASIZE/sizeof(long)];
 
 /*
- * Holds association data for use with the &n operator.
+ * assoc_cache[] is a dynamic array which allows references to
+ * associations using &1 ... &N for n associations, avoiding manual
+ * lookup of the current association IDs for a given ntpd.  It also
+ * caches the status word for each association, retrieved incidentally.
  */
-struct association assoc_cache[MAXASSOC];
+struct association *   assoc_cache;
+u_int assoc_cache_slots;/* count of allocated array entries */
 u_int numassoc;                /* number of cached associations */
 
 /*
@@ -3297,6 +3301,28 @@ assoccmp(
 }
 
 
+/*
+ * grow_assoc_cache() - enlarge dynamic assoc_cache array
+ *
+ * The strategy is to add an assumed 4k page size at a time, leaving
+ * room for malloc() bookkeeping overhead equivalent to 4 pointers.
+ */
+void
+grow_assoc_cache(void)
+{
+       static size_t   prior_sz;
+       size_t          new_sz;
+
+       new_sz = prior_sz + 4 * 1024;
+       if (0 == prior_sz) {
+               new_sz -= 4 * sizeof(void *);
+       }
+       assoc_cache = erealloc_zero(assoc_cache, new_sz, prior_sz); 
+       prior_sz = new_sz;
+       assoc_cache_slots = new_sz / sizeof(assoc_cache[0]);
+}
+
+
 /*
  * ntpq_custom_opt_handler - autoopts handler for -c and -p
  *
index 1672eb01feaa829561940943d8331b7157a1101e..f5d7dcd4bea7f4977ebd0f0e9994e454d073d76f 100644 (file)
@@ -103,8 +103,6 @@ struct association {
        u_short status;
 };
 
-#define        MAXASSOC        1024
-
 /*
  * mrulist terminal status interval
  */
@@ -120,9 +118,11 @@ typedef struct var_format_tag {
 
 extern int     interactive;    /* are we prompting? */
 extern int     old_rv;         /* use old rv behavior? --old-rv */
+extern u_int   assoc_cache_slots;/* count of allocated array entries */
+extern u_int   numassoc;       /* number of cached associations */
 extern u_int   numhosts;
-extern u_int   numassoc;
 
+extern void    grow_assoc_cache(void);
 extern void    asciize         (int, char *, FILE *);
 extern int     getnetnum       (const char *, sockaddr_u *, char *, int);
 extern void    sortassoc       (void);