]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: ssh-keyscan(1): simplify conloop() with timercmp(3),
authorcheloha@openbsd.org <cheloha@openbsd.org>
Wed, 12 Aug 2020 01:23:45 +0000 (01:23 +0000)
committerDamien Miller <djm@mindrot.org>
Thu, 27 Aug 2020 01:27:01 +0000 (11:27 +1000)
timersub(3); ok djm@

OpenBSD-Commit-ID: a102acb544f840d33ad73d40088adab4a687fa27

ssh-keyscan.c

index a5e6440764b36a601931dda2df9a49d720a6e69b..ca190428a78b662f2b0f4cf5239e639b6514d920 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keyscan.c,v 1.131 2019/12/15 19:47:10 djm Exp $ */
+/* $OpenBSD: ssh-keyscan.c,v 1.132 2020/08/12 01:23:45 cheloha Exp $ */
 /*
  * Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
  *
@@ -584,16 +584,9 @@ conloop(void)
        monotime_tv(&now);
        c = TAILQ_FIRST(&tq);
 
-       if (c && (c->c_tv.tv_sec > now.tv_sec ||
-           (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec > now.tv_usec))) {
-               seltime = c->c_tv;
-               seltime.tv_sec -= now.tv_sec;
-               seltime.tv_usec -= now.tv_usec;
-               if (seltime.tv_usec < 0) {
-                       seltime.tv_usec += 1000000;
-                       seltime.tv_sec--;
-               }
-       } else
+       if (c && timercmp(&c->c_tv, &now, >))
+               timersub(&c->c_tv, &now, &seltime);
+       else
                timerclear(&seltime);
 
        r = xcalloc(read_wait_nfdset, sizeof(fd_mask));
@@ -616,8 +609,7 @@ conloop(void)
        free(e);
 
        c = TAILQ_FIRST(&tq);
-       while (c && (c->c_tv.tv_sec < now.tv_sec ||
-           (c->c_tv.tv_sec == now.tv_sec && c->c_tv.tv_usec < now.tv_usec))) {
+       while (c && timercmp(&c->c_tv, &now, <)) {
                int s = c->c_fd;
 
                c = TAILQ_NEXT(c, c_link);