summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-06-01 11:21:15 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-06-01 10:38:47 +0200
commit56e72337b01216dc7cba418f040a5cc928e5fc6f (patch)
tree7d64feee26bfeede2ab07ea6045ac11ebb4ea3c2
parent9bd695c83f43cacfc08566f3c18db44b61f7ed75 (diff)
downloadsamba-56e72337b01216dc7cba418f040a5cc928e5fc6f.tar.gz
samba-56e72337b01216dc7cba418f040a5cc928e5fc6f.tar.bz2
samba-56e72337b01216dc7cba418f040a5cc928e5fc6f.zip
lib/util/time.c: timeval_current_ofs_msec
Several places want "milliseconds from current time", and several were simply doing "msec * 1000" which can (and does in one place) result in a usec value over 1 a million. Using a helper to do this is safer and more readable. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--lib/util/time.c9
-rw-r--r--lib/util/time.h5
-rw-r--r--source3/libsmb/async_smb.c3
-rw-r--r--source3/nmbd/nmbd_processlogon.c3
-rw-r--r--source3/rpc_client/rpc_transport_tstream.c6
-rw-r--r--source3/smbd/blocking.c3
-rw-r--r--source3/smbd/smb2_lock.c4
-rw-r--r--source4/ntvfs/posix/pvfs_lock.c3
8 files changed, 22 insertions, 14 deletions
diff --git a/lib/util/time.c b/lib/util/time.c
index 4843fc9697..de1553aff8 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -580,6 +580,15 @@ _PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs)
}
/**
+ return a timeval milliseconds into the future
+*/
+_PUBLIC_ struct timeval timeval_current_ofs_msec(uint32_t msecs)
+{
+ struct timeval tv = timeval_current();
+ return timeval_add(&tv, msecs / 1000, (msecs % 1000) * 1000);
+}
+
+/**
compare two timeval structures.
Return -1 if tv1 < tv2
Return 0 if tv1 == tv2
diff --git a/lib/util/time.h b/lib/util/time.h
index 3a406340f4..4e4f72f71f 100644
--- a/lib/util/time.h
+++ b/lib/util/time.h
@@ -213,6 +213,11 @@ struct timeval timeval_sum(const struct timeval *tv1,
_PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs);
/**
+ return a timeval milliseconds into the future
+*/
+_PUBLIC_ struct timeval timeval_current_ofs_msec(uint32_t msecs);
+
+/**
compare two timeval structures.
Return -1 if tv1 < tv2
Return 0 if tv1 == tv2
diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c
index 3ed38718c1..8fdcac47a9 100644
--- a/source3/libsmb/async_smb.c
+++ b/source3/libsmb/async_smb.c
@@ -340,8 +340,7 @@ struct tevent_req *cli_smb_req_create(TALLOC_CTX *mem_ctx,
state->iov_count = iov_count + 3;
if (cli->timeout) {
- endtime = timeval_current_ofs(cli->timeout / 1000,
- (cli->timeout % 1000) * 1000);
+ endtime = timeval_current_ofs_msec(cli->timeout);
if (!tevent_req_set_endtime(result, ev, endtime)) {
tevent_req_nomem(NULL, result);
}
diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c
index 790e1c3ce1..25cdcc6970 100644
--- a/source3/nmbd/nmbd_processlogon.c
+++ b/source3/nmbd/nmbd_processlogon.c
@@ -604,8 +604,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) ));
source_name, source_addr,
lp_init_logon_delay()));
- when = timeval_current_ofs(0,
- lp_init_logon_delay() * 1000);
+ when = timeval_current_ofs_msec(lp_init_logon_delay());
p->locked = true;
event_add_timed(nmbd_event_context(),
NULL,
diff --git a/source3/rpc_client/rpc_transport_tstream.c b/source3/rpc_client/rpc_transport_tstream.c
index e62ab4b2bb..488c093d3b 100644
--- a/source3/rpc_client/rpc_transport_tstream.c
+++ b/source3/rpc_client/rpc_transport_tstream.c
@@ -202,7 +202,7 @@ static struct tevent_req *rpc_tstream_read_send(TALLOC_CTX *mem_ctx,
return tevent_req_post(req, ev);
}
- endtime = timeval_current_ofs(0, transp->timeout * 1000);
+ endtime = timeval_current_ofs_msec(transp->timeout);
if (!tevent_req_set_endtime(subreq, ev, endtime)) {
goto fail;
}
@@ -286,7 +286,7 @@ static struct tevent_req *rpc_tstream_write_send(TALLOC_CTX *mem_ctx,
goto fail;
}
- endtime = timeval_current_ofs(0, transp->timeout * 1000);
+ endtime = timeval_current_ofs_msec(transp->timeout);
if (!tevent_req_set_endtime(subreq, ev, endtime)) {
goto fail;
}
@@ -374,7 +374,7 @@ static struct tevent_req *rpc_tstream_trans_send(TALLOC_CTX *mem_ctx,
state->req.iov_base = discard_const_p(void *, data);
state->max_rdata_len = max_rdata_len;
- endtime = timeval_current_ofs(0, transp->timeout * 1000);
+ endtime = timeval_current_ofs_msec(transp->timeout);
subreq = tstream_writev_queue_send(state, ev,
transp->stream,
diff --git a/source3/smbd/blocking.c b/source3/smbd/blocking.c
index ca4106b346..fd77e3d15b 100644
--- a/source3/smbd/blocking.c
+++ b/source3/smbd/blocking.c
@@ -208,8 +208,7 @@ bool push_blocking_lock_request( struct byte_range_lock *br_lck,
blr->expire_time.tv_sec = 0;
blr->expire_time.tv_usec = 0; /* Never expire. */
} else {
- blr->expire_time = timeval_current_ofs(lock_timeout/1000,
- (lock_timeout % 1000) * 1000);
+ blr->expire_time = timeval_current_ofs_msec(lock_timeout);
}
blr->lock_num = lock_num;
blr->smblctx = smblctx;
diff --git a/source3/smbd/smb2_lock.c b/source3/smbd/smb2_lock.c
index 712558481c..5d615e1bed 100644
--- a/source3/smbd/smb2_lock.c
+++ b/source3/smbd/smb2_lock.c
@@ -628,9 +628,7 @@ bool push_blocking_lock_request_smb2( struct byte_range_lock *br_lck,
blr->expire_time.tv_sec = 0;
blr->expire_time.tv_usec = 0; /* Never expire. */
} else {
- blr->expire_time = timeval_current_ofs(
- lock_timeout/1000,
- (lock_timeout % 1000) * 1000);
+ blr->expire_time = timeval_current_ofs_msec(lock_timeout);
}
blr->lock_num = lock_num;
diff --git a/source4/ntvfs/posix/pvfs_lock.c b/source4/ntvfs/posix/pvfs_lock.c
index 76bc73dad8..0d99860e59 100644
--- a/source4/ntvfs/posix/pvfs_lock.c
+++ b/source4/ntvfs/posix/pvfs_lock.c
@@ -324,8 +324,7 @@ NTSTATUS pvfs_lock(struct ntvfs_module_context *ntvfs,
pending->req = req;
pending->end_time =
- timeval_current_ofs(lck->lockx.in.timeout/1000,
- 1000*(lck->lockx.in.timeout%1000));
+ timeval_current_ofs_msec(lck->lockx.in.timeout);
}
if (lck->lockx.in.mode & LOCKING_ANDX_SHARED_LOCK) {