From: Dave Hart Date: Thu, 23 Dec 2010 19:18:14 +0000 (+0000) Subject: Correct ntpq handling of &1 with multiple servers on cmd line. X-Git-Tag: NTP_4_2_7P103~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=206b8d33791cc103f9762da32c8990f6f14c67c9;p=thirdparty%2Fntp.git Correct ntpq handling of &1 with multiple servers on cmd line. bk: 4d13a076k2U6eXvK8xQbG5A-kTs7CA --- diff --git a/include/ntp_calendar.h b/include/ntp_calendar.h index 8e227387f..6804a184b 100644 --- a/include/ntp_calendar.h +++ b/include/ntp_calendar.h @@ -92,8 +92,9 @@ typedef struct { + ((val)<<4) + ((val)<<2) + (val)) /* *big* hack */ -extern const char *months[12]; -extern const char *daynames[7]; +extern const char * const months[12]; +extern const char * const daynames[7]; + extern void caljulian (u_int32, struct calendar *); extern u_int32 caltontp (const struct calendar *); @@ -145,14 +146,14 @@ ntpcal_days_in_years(int32 years); * excess! But then, we need no leap year flag, either...) */ extern ntpcal_split -ntpcal_days_in_months(int32 months); +ntpcal_days_in_months(int32 mons); /* * Convert ELAPSED years/months/days of gregorian calendar to elapsed * days in Gregorian epoch. No range checks done here! */ extern int32 -ntpcal_edate_to_eradays(int32 years, int32 months, int32 mdays); +ntpcal_edate_to_eradays(int32 years, int32 mons, int32 mdays); /* * Convert a time spec to seconds. No range checks done here! @@ -168,7 +169,7 @@ ntpcal_etime_to_seconds(int32 hours, int32 minutes, int32 seconds); * even if months & days are off-scale. */ extern int32 -ntpcal_edate_to_yeardays(int32 years, int32 months, int32 mdays); +ntpcal_edate_to_yeardays(int32 years, int32 mons, int32 mdays); /* * Convert the date part of a 'struct tm' (that is, year, month, diff --git a/libntp/prettydate.c b/libntp/prettydate.c index cdac5840b..f12129716 100644 --- a/libntp/prettydate.c +++ b/libntp/prettydate.c @@ -17,12 +17,12 @@ static char *common_prettydate(l_fp *, int); -const char * months[12] = { +const char * const months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -const char * daynames[7] = { +const char * const daynames[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index b0f55796f..aa8f9cd5e 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -12,7 +12,7 @@ extern char * chosts[]; extern char currenthost[]; -int maxhostlen; +size_t maxhostlen; /* * Declarations for command handlers in here @@ -1973,7 +1973,7 @@ doopeers( int af ) { - register int i; + u_int i; char fullname[LENHOSTNAME]; sockaddr_u netnum; diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index fedc47072..bab61722f 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -425,7 +425,7 @@ long pktdata[DATASIZE/sizeof(long)]; * Holds association data for use with the &n operator. */ struct association assoc_cache[MAXASSOC]; -u_int numassoc = 0; /* number of cached associations */ +u_int numassoc; /* number of cached associations */ /* * For commands typed on the command line (with the -c option) @@ -736,6 +736,8 @@ openhost( if (a_info == 0) freeaddrinfo(ai); havehost = 1; + numassoc = 0; + return 1; } @@ -2287,27 +2289,19 @@ host( ai_fam_templ = AF_INET; else if (!strcmp("-6", pcmd->argval[i].string)) ai_fam_templ = AF_INET6; - else { - if (havehost) - (void) fprintf(fp, - "current host remains %s\n", - currenthost); - else - (void) fprintf(fp, "still no current host\n"); - return; - } + else + goto no_change; i = 1; } if (openhost(pcmd->argval[i].string)) { - (void) fprintf(fp, "current host set to %s\n", currenthost); - numassoc = 0; + fprintf(fp, "current host set to %s\n", currenthost); } else { + no_change: if (havehost) - (void) fprintf(fp, - "current host remains %s\n", - currenthost); + fprintf(fp, "current host remains %s\n", + currenthost); else - (void) fprintf(fp, "still no current host\n"); + fprintf(fp, "still no current host\n"); } }