Fix bug 6828 - infinite timeout occurs when byte lock held outside of samba Jeremy.
authorJeremy Allison <jra@samba.org>
Wed, 21 Oct 2009 01:10:30 +0000 (18:10 -0700)
committerKarolin Seeger <kseeger@samba.org>
Mon, 26 Oct 2009 10:52:33 +0000 (11:52 +0100)
(cherry picked from commit a572c28ca3daa199d78fc340819c5c9ff53a3ed6)

source3/smbd/blocking.c

index 42849931f3ab5dd4b65de58a8964cd44b27aca5d..f4d88d85e86e7c7a58621b202e4ba5e6a3e5b35d 100644 (file)
@@ -47,6 +47,22 @@ static void brl_timeout_fn(struct event_context *event_ctx,
        process_blocking_lock_queue();
 }
 
+/****************************************************************************
+ We need a version of timeval_min that treats zero timval as infinite.
+****************************************************************************/
+
+static struct timeval timeval_brl_min(const struct timeval *tv1,
+                                       const struct timeval *tv2)
+{
+       if (timeval_is_zero(tv1)) {
+               return *tv2;
+       }
+       if (timeval_is_zero(tv2)) {
+               return *tv1;
+       }
+       return timeval_min(tv1, tv2);
+}
+
 /****************************************************************************
  After a change to blocking_lock_queue, recalculate the timed_event for the
  next processing.
@@ -70,19 +86,13 @@ static bool recalc_brl_timeout(void)
                         */
                         if (blr->blocking_pid == 0xFFFFFFFF) {
                                struct timeval psx_to = timeval_current_ofs(10, 0);
-                               next_timeout = timeval_min(&next_timeout, &psx_to);
+                               next_timeout = timeval_brl_min(&next_timeout, &psx_to);
                         }
 
                        continue;
                }
 
-               if (timeval_is_zero(&next_timeout)) {
-                       next_timeout = blr->expire_time;
-               }
-               else {
-                       next_timeout = timeval_min(&next_timeout,
-                                                  &blr->expire_time);
-               }
+               next_timeout = timeval_brl_min(&next_timeout, &blr->expire_time);
        }
 
        if (timeval_is_zero(&next_timeout)) {