From: Juergen Perlinger Date: Sat, 5 Dec 2015 13:29:10 +0000 (+0100) Subject: [Bug 2971] ntpq bails on ^C: select fails: Interrupted system call X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ae97e94daf55181e295587cf549e574f8853412;p=thirdparty%2Fntp.git [Bug 2971] ntpq bails on ^C: select fails: Interrupted system call - make CTRL-C work for retrieval and printing od MRU list. bk: 5662e6a6H9DCWzmnJ6NP1atiKUlRVA --- diff --git a/ChangeLog b/ChangeLog index bd0e8233e..7995fbd4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ lots of clients. perlinger@ntp.org * [Bug 2971] ntpq bails on ^C: select fails: Interrupted system call - changed stacked/nested handling of CTRL-C. perlinger@ntp.org + - make CTRL-C work for retrieval and printing od MRU list. perlinger@ntp.org * Unity cleanup for FreeBSD-6.4. Harlan Stenn. * Unity test cleanup. Harlan Stenn. * Libevent autoconf pthread fixes for FreeBSD-10. Harlan Stenn. diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 438c7ca58..d7bcf087c 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -3173,6 +3173,7 @@ mrulist( qsort(sorted, mru_count, sizeof(sorted[0]), mru_qcmp_table[order]); + mrulist_interrupted = FALSE; printf( "lstint avgint rstr r m v count rport remote address\n" "==============================================================================\n"); /* '=' x 78 */ @@ -3199,6 +3200,11 @@ mrulist( nntohost(&recent->addr)); if (showhostnames) fflush(fp); + if (mrulist_interrupted) { + fputs("\n --interrupted--\n", fp); + fflush(fp); + break; + } } fflush(fp); if (debug) { diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 5b3c9cb80..120695298 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -876,6 +876,21 @@ getresponse( FD_SET(sockfd, &fds); n = select(sockfd+1, &fds, NULL, NULL, &tvo); if (n == -1) { +#if !defined(SYS_WINNT) && defined(EINTR) + /* Windows does not know about EINTR (until very + * recently) and the handling of console events + * is *very* different from POSIX/UNIX signal + * handling anyway. + * + * Under non-windows targets we map EINTR as + * 'last packet was received' and try to exit + * the receive sequence. + */ + if (errno == EINTR) { + seenlastfrag = 1; + goto maybe_final; + } +#endif warning("select fails"); return -1; } @@ -1149,6 +1164,7 @@ getresponse( * If we've seen the last fragment, look for holes in the sequence. * If there aren't any, we're done. */ + maybe_final: if (seenlastfrag && offsets[0] == 0) { for (f = 1; f < numfrags; f++) if (offsets[f-1] + counts[f-1] !=