From: Dave Hart Date: Mon, 2 Jul 2012 02:17:35 +0000 (+0000) Subject: Remove 1024 associations-per-server limit from ntpq. X-Git-Tag: NTP_4_2_7P287~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=256f30edc40f6ce2d73c0a9b6badfd5dec738d9a;p=thirdparty%2Fntp.git Remove 1024 associations-per-server limit from ntpq. Remove blank line between ntpq mreadvar associations. bk: 4ff104bfA2R2TrHTe-Sg0E4fDJFd8Q --- diff --git a/ChangeLog b/ChangeLog index 5f89a1313..828ba4693 100644 --- 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 * CID 97193: check return from sscanf() in ntp_config.c. * CID 709169: check return from open("/dev/null", 0) and friends. diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 2297d3132..52e952b86 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -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; } diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 0474b2f56..f8257850b 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -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 * diff --git a/ntpq/ntpq.h b/ntpq/ntpq.h index 1672eb01f..f5d7dcd4b 100644 --- a/ntpq/ntpq.h +++ b/ntpq/ntpq.h @@ -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);