From 2b1cd4a1147a8d5ba10ddcef4c2d258df2bd5dd4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 22 Jan 2016 08:53:57 +0100 Subject: [PATCH] ldb: allow a timeout of -1 result in no timeout timer at all. This is required in order to have long running async searches, e.g. with LDB_CONTROL_NOTIFICATION_OID. Signed-off-by: Stefan Metzmacher Reviewed-by: Garming Sam Reviewed-by: Andrew Bartlett --- lib/ldb/ldb_ldap/ldb_ldap.c | 18 +++++++++++------- lib/ldb/ldb_sqlite3/ldb_sqlite3.c | 11 +++++++---- lib/ldb/ldb_tdb/ldb_tdb.c | 14 +++++++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/ldb/ldb_ldap/ldb_ldap.c b/lib/ldb/ldb_ldap/ldb_ldap.c index 7e6ac903c8a..29f89388c5f 100644 --- a/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/lib/ldb/ldb_ldap/ldb_ldap.c @@ -252,8 +252,11 @@ static int lldb_search(struct lldb_context *lldb_ac) break; } - tv.tv_sec = req->timeout; + tv.tv_sec = 0; tv.tv_usec = 0; + if (req->timeout > 0) { + tv.tv_sec = req->timeout; + } ret = ldap_search_ext(lldb->ldap, search_base, ldap_scope, expression, @@ -836,12 +839,13 @@ static int lldb_handle_request(struct ldb_module *module, struct ldb_request *re return LDB_ERR_OPERATIONS_ERROR; } - - tv.tv_sec = req->starttime + req->timeout; - tv.tv_usec = 0; - te = tevent_add_timer(ev, ac, tv, lldb_timeout, ac); - if (NULL == te) { - return LDB_ERR_OPERATIONS_ERROR; + if (req->timeout > 0) { + tv.tv_sec = req->starttime + req->timeout; + tv.tv_usec = 0; + te = tevent_add_timer(ev, ac, tv, lldb_timeout, ac); + if (NULL == te) { + return LDB_ERR_OPERATIONS_ERROR; + } } return LDB_SUCCESS; diff --git a/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/lib/ldb/ldb_sqlite3/ldb_sqlite3.c index 223868a6c0a..60b39e89790 100644 --- a/lib/ldb/ldb_sqlite3/ldb_sqlite3.c +++ b/lib/ldb/ldb_sqlite3/ldb_sqlite3.c @@ -1566,10 +1566,13 @@ static int lsql_handle_request(struct ldb_module *module, struct ldb_request *re return LDB_ERR_OPERATIONS_ERROR; } - tv.tv_sec = req->starttime + req->timeout; - ac->timeout_event = tevent_add_timer(ev, ac, tv, lsql_timeout, ac); - if (NULL == ac->timeout_event) { - return LDB_ERR_OPERATIONS_ERROR; + if (req->timeout > 0) { + tv.tv_sec = req->starttime + req->timeout; + tv.tv_usec = 0; + ac->timeout_event = tevent_add_timer(ev, ac, tv, lsql_timeout, ac); + if (NULL == ac->timeout_event) { + return LDB_ERR_OPERATIONS_ERROR; + } } return LDB_SUCCESS; diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index bcb8f0fb141..8d1fd360014 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1469,11 +1469,15 @@ static int ltdb_handle_request(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - tv.tv_sec = req->starttime + req->timeout; - ac->timeout_event = tevent_add_timer(ev, ac, tv, ltdb_timeout, ac); - if (NULL == ac->timeout_event) { - talloc_free(ac); - return LDB_ERR_OPERATIONS_ERROR; + if (req->timeout > 0) { + tv.tv_sec = req->starttime + req->timeout; + tv.tv_usec = 0; + ac->timeout_event = tevent_add_timer(ev, ac, tv, + ltdb_timeout, ac); + if (NULL == ac->timeout_event) { + talloc_free(ac); + return LDB_ERR_OPERATIONS_ERROR; + } } /* set a spy so that we do not try to use the request context