]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
sys_poll_intr: fix timeout arithmetic
authorDaniel Kobras <d.kobras@science-computing.de>
Mon, 21 Jul 2014 08:47:53 +0000 (10:47 +0200)
committerKarolin Seeger <kseeger@samba.org>
Thu, 21 Aug 2014 14:55:17 +0000 (16:55 +0200)
Callers of sys_poll_intr() assume timeout to be in milliseconds like
poll(2) expects, but implementation used nanosecond units. Also make
sure timeout doesn't become infinite by mistake during time arithmetic.

Signed-off-by: Daniel Kobras <d.kobras@science-computing.de>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10731

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Jul 22 00:12:24 CEST 2014 on sn-devel-104

lib/util/select.c

index 5e66344c9dac4645fbf64b7a39f4bfa60624b97e..99cd772bae8a9f90c9d2493affcc8e541f094e9e 100644 (file)
@@ -42,9 +42,19 @@ int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout)
                if (errno != EINTR) {
                        break;
                }
+               /* Infinite timeout, no need to adjust. */
+               if (timeout < 0) {
+                       continue;
+               }
                clock_gettime_mono(&now);
-               elapsed = nsec_time_diff(&now, &start);
-               timeout = (orig_timeout - elapsed) / 1000000;
+               elapsed = nsec_time_diff(&now, &start) / 1000000;
+               timeout = orig_timeout - elapsed;
+               /* Unlikely, but might happen eg. when getting traced.
+                * Make sure we're not hanging in this case.
+                */
+               if (timeout < 0) {
+                       timeout = 0;
+               }
        };
        return ret;
 }