Remove blank line between ntpq mreadvar associations.
bk: 4ff104bfA2R2TrHTe-Sg0E4fDJFd8Q
+* 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.
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;
}
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;
}
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;
}
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 */
/*
}
+/*
+ * 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
*
u_short status;
};
-#define MAXASSOC 1024
-
/*
* mrulist terminal status interval
*/
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);