The branch, master has been updated via e340cd8 lib/tevent/tevent.h: minor documentation fix. via c29069e libcli/cldap/cldap.c: don't hand huge values to tevent_timeval_add usecs via 0204ae6 lib/util/time.c: timeval_current_ofs_usec via 56e7233 lib/util/time.c: timeval_current_ofs_msec from 9bd695c samba-tool: update tests for new 'user enable' syntax
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit e340cd83f87a9ea02cacd9af520d154652c5afb1 Author: Rusty Russell <ru...@rustcorp.com.au> Date: Wed Jun 1 12:20:11 2011 +0930 lib/tevent/tevent.h: minor documentation fix. The usecs arguments are (of course) microseconds, not milliseconds. This was added by Andreas Schneider in 6c1bcdc2 (tevent: Document the tevent helper functions.). Signed-off-by: Rusty Russell <ru...@rustcorp.com.au> Autobuild-User: Rusty Russell <ru...@rustcorp.com.au> Autobuild-Date: Wed Jun 1 11:47:38 CEST 2011 on sn-devel-104 commit c29069e079018853867d643b8de604edd95c94d9 Author: Rusty Russell <ru...@rustcorp.com.au> Date: Wed Jun 1 12:20:08 2011 +0930 libcli/cldap/cldap.c: don't hand huge values to tevent_timeval_add usecs state->request.delay is two million here, resulting in an invalid timeval. Since tevent doesn't have a convenient wrapper to add arbitrary usecs, do the arithmetic here (it's the sole caller of this function). Signed-off-by: Rusty Russell <ru...@rustcorp.com.au> commit 0204ae6229bae3573b3194c3f657c8f385c0b940 Author: Rusty Russell <ru...@rustcorp.com.au> Date: Wed Jun 1 11:24:51 2011 +0930 lib/util/time.c: timeval_current_ofs_usec Several places want "microseconds from current time", and several were simply handing "usecs" values which could be over a million. Using a helper to do this is safer and more readable. I didn't replace any obviously correct callers (ie. constants). I also renamed wait_nsec in source3/lib/util_sock.c; it's actually microseconds not nanoseconds (introduced with this code in Volker's 19b783cc Async wrapper for open_socket_out_send/recv). Signed-off-by: Rusty Russell <ru...@rustcorp.com.au> commit 56e72337b01216dc7cba418f040a5cc928e5fc6f Author: Rusty Russell <ru...@rustcorp.com.au> Date: Wed Jun 1 11:21:15 2011 +0930 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 <ru...@rustcorp.com.au> ----------------------------------------------------------------------- Summary of changes: lib/tevent/tevent.h | 6 +++--- lib/util/time.c | 18 ++++++++++++++++++ lib/util/time.h | 10 ++++++++++ libcli/cldap/cldap.c | 6 ++++-- source3/lib/util_sock.c | 14 +++++++------- source3/libsmb/async_smb.c | 3 +-- source3/nmbd/nmbd_processlogon.c | 3 +-- source3/rpc_client/rpc_transport_tstream.c | 6 +++--- source3/smbd/blocking.c | 3 +-- source3/smbd/fileio.c | 2 +- source3/smbd/smb2_lock.c | 4 +--- source4/lib/socket/connect_multi.c | 2 +- source4/libcli/raw/clitransport.c | 2 +- source4/ntvfs/posix/pvfs_lock.c | 3 +-- source4/ntvfs/posix/pvfs_open.c | 2 +- source4/ntvfs/posix/pvfs_write.c | 2 +- 16 files changed, 55 insertions(+), 31 deletions(-) Changeset truncated at 500 lines: diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h index f4eb60c..38a4a9c 100644 --- a/lib/tevent/tevent.h +++ b/lib/tevent/tevent.h @@ -1218,7 +1218,7 @@ struct timeval tevent_timeval_current(void); * * @param[in] secs The seconds to set. * - * @param[in] usecs The milliseconds to set. + * @param[in] usecs The microseconds to set. * * @return A timeval structure with the given values. */ @@ -1253,7 +1253,7 @@ bool tevent_timeval_is_zero(const struct timeval *tv); * * @param[in] secs The seconds to add to the timeval. * - * @param[in] usecs The milliseconds to add to the timeval. + * @param[in] usecs The microseconds to add to the timeval. * * @return The timeval structure with the new time. */ @@ -1265,7 +1265,7 @@ struct timeval tevent_timeval_add(const struct timeval *tv, uint32_t secs, * * @param[in] secs The seconds of the offset from now. * - * @param[in] usecs The milliseconds of the offset from now. + * @param[in] usecs The microseconds of the offset from now. * * @return A timval with the given offset in the future. */ diff --git a/lib/util/time.c b/lib/util/time.c index 4843fc9..d8fd4a3 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -580,6 +580,24 @@ _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); +} + +/** + return a timeval microseconds into the future +*/ +_PUBLIC_ struct timeval timeval_current_ofs_usec(uint32_t usecs) +{ + struct timeval tv = timeval_current(); + return timeval_add(&tv, usecs / 1000000, usecs % 1000000); +} + +/** 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 3a40634..1f7f57d 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -213,6 +213,16 @@ 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); + +/** + return a timeval microseconds into the future +*/ +_PUBLIC_ struct timeval timeval_current_ofs_usec(uint32_t usecs); + +/** compare two timeval structures. Return -1 if tv1 < tv2 Return 0 if tv1 == tv2 diff --git a/libcli/cldap/cldap.c b/libcli/cldap/cldap.c index f5585c2..37b4f49 100644 --- a/libcli/cldap/cldap.c +++ b/libcli/cldap/cldap.c @@ -626,7 +626,8 @@ struct tevent_req *cldap_search_send(TALLOC_CTX *mem_ctx, now = tevent_timeval_current(); end = now; for (i = 0; i < state->request.count; i++) { - end = tevent_timeval_add(&end, 0, state->request.delay); + end = tevent_timeval_add(&end, state->request.delay / 1000000, + state->request.delay % 1000000); } if (!tevent_req_set_endtime(req, state->caller.cldap->event.ctx, end)) { @@ -688,7 +689,8 @@ static void cldap_search_state_queue_done(struct tevent_req *subreq) return; } - next = tevent_timeval_current_ofs(0, state->request.delay); + next = tevent_timeval_current_ofs(state->request.delay / 1000000, + state->request.delay % 1000000); subreq = tevent_wakeup_send(state, state->caller.cldap->event.ctx, next); diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 5d20d74..5b01d11 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -524,7 +524,7 @@ struct open_socket_out_state { struct sockaddr_storage ss; socklen_t salen; uint16_t port; - int wait_nsec; + int wait_usec; }; static void open_socket_out_connected(struct tevent_req *subreq); @@ -560,7 +560,7 @@ struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx, state->ev = ev; state->ss = *pss; state->port = port; - state->wait_nsec = 10000; + state->wait_usec = 10000; state->salen = -1; state->fd = socket(state->ss.ss_family, SOCK_STREAM, 0); @@ -571,7 +571,7 @@ struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx, talloc_set_destructor(state, open_socket_out_state_destructor); if (!tevent_req_set_endtime( - result, ev, timeval_current_ofs(0, timeout*1000))) { + result, ev, timeval_current_ofs_msec(timeout))) { goto fail; } @@ -608,7 +608,7 @@ struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx, if ((subreq == NULL) || !tevent_req_set_endtime( subreq, state->ev, - timeval_current_ofs(0, state->wait_nsec))) { + timeval_current_ofs(0, state->wait_usec))) { goto fail; } tevent_req_set_callback(subreq, open_socket_out_connected, result); @@ -650,8 +650,8 @@ static void open_socket_out_connected(struct tevent_req *subreq) * retry */ - if (state->wait_nsec < 250000) { - state->wait_nsec *= 1.5; + if (state->wait_usec < 250000) { + state->wait_usec *= 1.5; } subreq = async_connect_send(state, state->ev, state->fd, @@ -662,7 +662,7 @@ static void open_socket_out_connected(struct tevent_req *subreq) } if (!tevent_req_set_endtime( subreq, state->ev, - timeval_current_ofs(0, state->wait_nsec))) { + timeval_current_ofs_usec(state->wait_usec))) { tevent_req_nterror(req, NT_STATUS_NO_MEMORY); return; } diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c index 3ed3871..8fdcac4 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 790e1c3..25cdcc6 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 e62ab4b..488c093 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 ca4106b..fd77e3d 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/fileio.c b/source3/smbd/fileio.c index 5e0ea90..3b317f9 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -241,7 +241,7 @@ void trigger_write_time_update(struct files_struct *fsp) /* trigger the update 2 seconds later */ fsp->update_write_time_event = event_add_timed(server_event_context(), NULL, - timeval_current_ofs(0, delay), + timeval_current_ofs_usec(delay), update_write_time_handler, fsp); } diff --git a/source3/smbd/smb2_lock.c b/source3/smbd/smb2_lock.c index 7125584..5d615e1 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/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c index 300e5fb..e3b5845 100644 --- a/source4/lib/socket/connect_multi.c +++ b/source4/lib/socket/connect_multi.c @@ -162,7 +162,7 @@ static void connect_multi_next_socket(struct composite_context *result) connect attempt state, so it will go away when this request completes */ event_add_timed(result->event_ctx, state, - timeval_current_ofs(0, MULTI_PORT_DELAY), + timeval_current_ofs_usec(MULTI_PORT_DELAY), connect_multi_timer, result); } } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 7a3993c..4331669 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -338,7 +338,7 @@ _PUBLIC_ void smbcli_transport_idle_handler(struct smbcli_transport *transport, transport->socket->event.te = event_add_timed(transport->socket->event.ctx, transport, - timeval_current_ofs(0, period), + timeval_current_ofs_usec(period), idle_handler, transport); } diff --git a/source4/ntvfs/posix/pvfs_lock.c b/source4/ntvfs/posix/pvfs_lock.c index 76bc73d..0d99860 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) { diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index dfe2f2a..d56bce5 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -1174,7 +1174,7 @@ static NTSTATUS pvfs_open_setup_retry(struct ntvfs_module_context *ntvfs, *final_timeout = timeval_add(&req->statistics.request_time, pvfs->oplock_break_timeout, 0); - end_time = timeval_current_ofs(0, (pvfs->sharing_violation_delay*4)/5); + end_time = timeval_current_ofs_usec((pvfs->sharing_violation_delay*4)/5); end_time = timeval_min(final_timeout, &end_time); } else { return NT_STATUS_INTERNAL_ERROR; diff --git a/source4/ntvfs/posix/pvfs_write.c b/source4/ntvfs/posix/pvfs_write.c index fb629a8..892d3dd 100644 --- a/source4/ntvfs/posix/pvfs_write.c +++ b/source4/ntvfs/posix/pvfs_write.c @@ -64,7 +64,7 @@ static void pvfs_trigger_write_time_update(struct pvfs_file_handle *h) return; } - tv = timeval_current_ofs(0, pvfs->writetime_delay); + tv = timeval_current_ofs_usec(pvfs->writetime_delay); h->write_time.update_triggered = true; h->write_time.update_on_close = true; -- Samba Shared Repository