[ntp:bk-ntp-dev-send] BitKeeper diffs
Harlan Stenn
stenn at deacon.udel.edu
Thu Oct 13 19:27:25 UTC 2011
#### ChangeSet ####
2011-10-13 18:13:58+00:00, davehart at shiny.ad.hartbrothers.com
ntpq mrulist shows intermediate counts every five seconds while
retrieving list, and allows Ctrl-C interruption of the retrieval,
showing the incomplete list as retrieved. Reduce delay between
successive mrulist retrieval queries from 30 to 5 msec. Do not
give up mrulist retrieval when a single query times out.
==== ChangeLog ====
2011-10-13 18:13:57+00:00, davehart at shiny.ad.hartbrothers.com +5 -0
ntpq mrulist shows intermediate counts every five seconds while
retrieving list, and allows Ctrl-C interruption of the retrieval,
showing the incomplete list as retrieved. Reduce delay between
successive mrulist retrieval queries from 30 to 5 msec. Do not
give up mrulist retrieval when a single query times out.
--- 1.1062/ChangeLog 2011-10-12 06:40:57 -04:00
+++ 1.1063/ChangeLog 2011-10-13 14:13:57 -04:00
@@ -1,3 +1,8 @@
+* ntpq mrulist shows intermediate counts every five seconds while
+ retrieving list, and allows Ctrl-C interruption of the retrieval,
+ showing the incomplete list as retrieved. Reduce delay between
+ successive mrulist retrieval queries from 30 to 5 msec. Do not
+ give up mrulist retrieval when a single query times out.
(4.2.7p223) 2011/10/12 Released by Harlan Stenn <stenn at ntp.org>
* Documentation updates from Dave Mills.
(4.2.7p222) 2011/10/11 Released by Harlan Stenn <stenn at ntp.org>
==== include/ntp_stdlib.h ====
2011-10-13 18:13:57+00:00, davehart at shiny.ad.hartbrothers.com +3 -0
provide portable POSIX/Win32 Ctrl-C interception.
--- 1.65/include/ntp_stdlib.h 2011-10-09 01:08:20 -04:00
+++ 1.66/include/ntp_stdlib.h 2011-10-13 14:13:57 -04:00
@@ -77,6 +77,8 @@ extern void errno_to_str(int, char *, si
errno = preserved_errno; \
}
+typedef void (*ctrl_c_fn)(void);
+
/* authkeys.c */
extern void auth_delkeys (void);
extern int auth_havekey (keyid_t);
@@ -175,6 +177,7 @@ extern int decodenetnum (const char *, s
extern const char * FindConfig (const char *);
extern void signal_no_reset (int, RETSIGTYPE (*func)(int));
+extern void set_ctrl_c_hook (ctrl_c_fn);
extern void getauthkeys (const char *);
extern void auth_agekeys (void);
==== libntp/syssignal.c ====
2011-10-13 18:13:57+00:00, davehart at shiny.ad.hartbrothers.com +79 -0
provide portable POSIX/Win32 Ctrl-C interception.
--- 1.14/libntp/syssignal.c 2011-08-27 01:24:06 -04:00
+++ 1.15/libntp/syssignal.c 2011-10-13 14:13:57 -04:00
@@ -9,6 +9,13 @@
#include "ntp_syslog.h"
#include "ntp_stdlib.h"
+static ctrl_c_fn ctrl_c_hook;
+#ifndef SYS_WINNT
+RETSIGTYPE sigint_handler(int);
+#else
+BOOL WINAPI console_event_handler(DWORD);
+#endif
+
#ifdef HAVE_SIGACTION
@@ -107,3 +114,75 @@ signal_no_reset(
}
#endif
+
+#ifndef SYS_WINNT
+/*
+ * POSIX implementation of set_ctrl_c_hook()
+ */
+RETSIGTYPE
+sigint_handler(
+ int signum
+ )
+{
+ UNUSED_ARG(signum);
+ if (ctrl_c_hook != NULL)
+ (*ctrl_c_hook)();
+}
+
+void
+set_ctrl_c_hook(
+ ctrl_c_fn c_hook
+ )
+{
+ RETSIGTYPE (*handler)(int);
+
+ if (NULL == c_hook) {
+ handler = SIG_DFL;
+ ctrl_c_hook = NULL;
+ } else {
+ handler = &sigint_handler;
+ ctrl_c_hook = c_hook;
+ }
+ signal_no_reset(SIGINT, handler);
+}
+#else /* SYS_WINNT follows */
+/*
+ * Windows implementation of set_ctrl_c_hook()
+ */
+BOOL WINAPI
+console_event_handler(
+ DWORD dwCtrlType
+ )
+{
+ BOOL handled;
+
+ if (CTRL_C_EVENT == dwCtrlType && ctrl_c_hook != NULL) {
+ (*ctrl_c_hook)();
+ handled = TRUE;
+ } else {
+ handled = FALSE;
+ }
+
+ return handled;
+}
+void
+set_ctrl_c_hook(
+ ctrl_c_fn c_hook
+ )
+{
+ BOOL install;
+
+ if (NULL == c_hook) {
+ ctrl_c_hook = NULL;
+ install = FALSE;
+ } else {
+ ctrl_c_hook = c_hook;
+ install = TRUE;
+ }
+ if (!SetConsoleCtrlHandler(&console_event_handler, install))
+ msyslog(LOG_ERR, "Can't %s console control handler: %m",
+ (install)
+ ? "add"
+ : "remove");
+}
+#endif /* SYS_WINNT */
==== ntpq/ntpq-subs.c ====
2011-10-13 18:13:57+00:00, davehart at shiny.ad.hartbrothers.com +53 -8
ntpq mrulist shows intermediate counts every five seconds while
retrieving list, and allows Ctrl-C interruption of the retrieval,
showing the incomplete list as retrieved. Reduce delay between
successive mrulist retrieval queries from 30 to 5 msec. Do not
give up mrulist retrieval when a single query times out.
--- 1.88/ntpq/ntpq-subs.c 2011-08-27 00:19:03 -04:00
+++ 1.89/ntpq/ntpq-subs.c 2011-10-13 14:13:57 -04:00
@@ -319,8 +319,9 @@ typedef struct var_display_collection_ta
} vdc;
/*
- * other static function prototypes
+ * other local function prototypes
*/
+void mrulist_ctrl_c_hook(void);
static mru * add_mru(mru *);
static int collect_mru_list(const char *, l_fp *);
static int fetch_nonce(char *, size_t);
@@ -339,6 +340,8 @@ static void collect_display_vdc(associd_
* static globals
*/
static u_int mru_count;
+static u_int mru_dupes;
+volatile int mrulist_interrupted;
static mru mru_list; /* listhead */
static mru ** hash_table;
@@ -2175,11 +2178,11 @@ add_mru(
add->last.l_uf, mon->last.l_ui,
mon->last.l_uf);
exit(1);
-
}
UNLINK_DLIST(mon, mlink);
UNLINK_SLIST(unlinked, hash_table[hash], mon, hlink, mru);
NTP_INSIST(unlinked == mon);
+ mru_dupes++;
if (debug)
fprintf(stderr, "(updated from %08x.%08x) ",
mon->last.l_ui, mon->last.l_uf);
@@ -2216,16 +2219,24 @@ add_mru(
} while (0)
+void
+mrulist_ctrl_c_hook(void)
+{
+ mrulist_interrupted = TRUE;
+}
+
+
static int
collect_mru_list(
- const char *parms,
- l_fp * pnow
+ const char * parms,
+ l_fp * pnow
)
{
- const u_int sleep_msecs = 30;
+ const u_int sleep_msecs = 5;
static int ntpd_row_limit = MRU_ROW_LIMIT;
int c_mru_l_rc; /* this function's return code */
u_char got; /* MRU_GOT_* bits */
+ time_t next_report;
size_t cb;
mru *mon;
mru *head;
@@ -2279,6 +2290,12 @@ collect_mru_list(
mon = emalloc_zero(cb);
ZERO(*pnow);
ZERO(last_older);
+ mrulist_interrupted = FALSE;
+ set_ctrl_c_hook(&mrulist_ctrl_c_hook);
+ fprintf(stderr,
+ "Ctrl-C will stop MRU retrieval and display partial results.\n");
+ fflush(stderr);
+ next_report = time(NULL) + MRU_REPORT_SECS;
limit = min(3 * MAXFRAGS, ntpd_row_limit);
snprintf(req_buf, sizeof(req_buf), "nonce=%s, limit=%d%s",
@@ -2343,7 +2360,8 @@ collect_mru_list(
fprintf(stderr,
"Row limit reduced to %d following CERR_BADVALUE.\n",
limit);
- } else if (ERR_INCOMPLETE == qres) {
+ } else if (ERR_INCOMPLETE == qres ||
+ ERR_TIMEOUT == qres) {
/*
* Reduce the number of rows to minimize effect
* of single lost packets.
@@ -2466,10 +2484,18 @@ collect_mru_list(
} else if (1 != sscanf(tag, "last.%d", &si) ||
si != ci || '0' != val[0] ||
'x' != val[1] ||
- !hextolfp(val + 2, &mon->last))
+ !hextolfp(val + 2, &mon->last)) {
goto nomatch;
- else
+ } else {
MGOT(MRU_GOT_LAST);
+ /*
+ * allow interrupted retrieval,
+ * using most recent retrieved
+ * entry's last seen timestamp
+ * as the end of operation.
+ */
+ *pnow = mon->last;
+ }
break;
case 'f':
@@ -2531,8 +2557,26 @@ collect_mru_list(
list_complete = TRUE;
if (list_complete) {
NTP_INSIST(0 == ri || have_addr_older);
+ }
+ if (mrulist_interrupted) {
+ printf("mrulist retrieval interrupted by operator.\n"
+ "Displaying partial client list.\n");
+ fflush(stdout);
+ }
+ if (list_complete || mrulist_interrupted) {
+ fprintf(stderr,
+ "\rRetrieved %u unique MRU entries and %u updates.\n",
+ mru_count, mru_dupes);
+ fflush(stderr);
break;
}
+ if (time(NULL) >= next_report) {
+ next_report += MRU_REPORT_SECS;
+ fprintf(stderr, "\r%u (%u updates) ", mru_count,
+ mru_dupes);
+ fflush(stderr);
+ }
+
/*
* Snooze for a bit between queries to let ntpd catch
* up with other duties.
@@ -2592,6 +2636,7 @@ collect_mru_list(
}
}
+ set_ctrl_c_hook(NULL);
c_mru_l_rc = TRUE;
goto retain_hash_table;
==== ntpq/ntpq.h ====
2011-10-13 18:13:57+00:00, davehart at shiny.ad.hartbrothers.com +5 -0
ntpq mrulist shows intermediate counts every five seconds while
retrieving list.
--- 1.23/ntpq/ntpq.h 2010-12-30 05:52:23 -05:00
+++ 1.24/ntpq/ntpq.h 2011-10-13 14:13:57 -04:00
@@ -105,6 +105,11 @@ struct association {
#define MAXASSOC 1024
/*
+ * mrulist terminal status interval
+ */
+#define MRU_REPORT_SECS 5
+
+/*
* var_format is used to override cooked formatting for selected vars.
*/
typedef struct var_format_tag {
More information about the bk-ntp-dev-send
mailing list