s3: Fix timeout calculation if g_lock_lock is given a timeout < 60s
authorVolker Lendecke <vl@samba.org>
Tue, 16 Feb 2010 14:21:25 +0000 (15:21 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 16 Feb 2010 15:41:23 +0000 (16:41 +0100)
Detected while showing this code to obnox :-)

source3/lib/g_lock.c

index fc21a304be768109b05c96308494d55669a13f1a..4e31761ee23d88f1e6220d2b995eed2a8e98cf7a 100644 (file)
@@ -340,7 +340,7 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
                fd_set *r_fds = NULL;
                int max_fd = 0;
                int ret;
-               struct timeval select_timeout;
+               struct timeval timeout_remaining, select_timeout;
 
                status = g_lock_trylock(ctx, name, lock_type);
                if (NT_STATUS_IS_OK(status)) {
@@ -397,8 +397,13 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
                }
 #endif
 
+               time_now = timeval_current();
+               timeout_remaining = timeval_until(&time_now, &timeout_end);
                select_timeout = timeval_set(60, 0);
 
+               select_timeout = timeval_min(&select_timeout,
+                                            &timeout_remaining);
+
                ret = sys_select(max_fd + 1, r_fds, NULL, NULL,
                                 &select_timeout);
                if (ret == -1) {