diff options
author | Daniel Kobras <d.kobras@science-computing.de> | 2014-07-21 10:47:53 +0200 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2014-08-07 16:43:09 +0200 |
commit | 9449ff4b9605aafbc3ff7cac02b1cd511cbcbec1 (patch) | |
tree | a76514efc451a88036c1fffc17f1978f3edcb24f /lib | |
parent | a2a4d0b6f2e3eff4e537fced6416e50fc0d4993f (diff) | |
download | samba-9449ff4b9605aafbc3ff7cac02b1cd511cbcbec1.tar.gz |
sys_poll_intr: fix timeout arithmetic
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/select.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/util/select.c b/lib/util/select.c index 5e66344c9d..99cd772bae 100644 --- a/lib/util/select.c +++ b/lib/util/select.c @@ -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; } |