]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2971] ntpq bails on ^C: select fails: Interrupted system call
authorJuergen Perlinger <perlinger@ntp.org>
Sat, 5 Dec 2015 13:29:10 +0000 (14:29 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Sat, 5 Dec 2015 13:29:10 +0000 (14:29 +0100)
  - make CTRL-C work for retrieval and printing od MRU list.

bk: 5662e6a6H9DCWzmnJ6NP1atiKUlRVA

ChangeLog
ntpq/ntpq-subs.c
ntpq/ntpq.c

index bd0e8233ed4c451a93ca75ada00ec083e1648093..7995fbd4acdb7ac604d561a03604f7df2f9a0c1e 100644 (file)
--- 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.
index 438c7ca58a65054702a0e0ddf60797f330d30d47..d7bcf087c74b304b78c8e7845c7685588efc983f 100644 (file)
@@ -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) {
index 5b3c9cb807b7fa144af95479ef2eabc9ae031d5e..12069529800732a21efc70049784accb8ea6823a 100644 (file)
@@ -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] !=