D-BUS handles timeouts itself and reports DBUS_ERROR_NO_REPLY if
a timeout fires, so we can rely on this instead of having an
explicit timeout ourselves. Furthermore, the two timeouts present
a potential race condition.
-- 
Stephen Gallagher
RHCE 804006346421761

Looking to carve out IT costs?
www.redhat.com/carveoutcosts/
From 98446697ec26000cf2028e52e96252902b4a4d1d Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgall...@redhat.com>
Date: Wed, 12 Aug 2009 08:49:24 -0400
Subject: [PATCH] Eliminate unnecessary explicit timeout for DP account requests

D-BUS handles timeouts itself and reports DBUS_ERROR_NO_REPLY if
a timeout fires, so we can rely on this instead of having an
explicit timeout ourselves. Furthermore, the two timeouts present
a potential race condition.
---
 server/responder/common/responder_dp.c |   46 ++++++++++++--------------------
 1 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/server/responder/common/responder_dp.c 
b/server/responder/common/responder_dp.c
index fd13208..e408ca7 100644
--- a/server/responder/common/responder_dp.c
+++ b/server/responder/common/responder_dp.c
@@ -156,22 +156,6 @@ static int nss_dp_req_destructor(void *ptr)
     return 0;
 }
 
-static void nss_dp_send_acct_timeout(struct tevent_context *ev,
-                                     struct tevent_timer *te,
-                                     struct timeval t, void *data)
-{
-    struct nss_dp_req *ndp_req;
-    dbus_uint16_t err_maj = DP_ERR_TIMEOUT;
-    dbus_uint32_t err_min = EIO;
-    const char *err_msg = "Request timed out";
-
-    ndp_req = talloc_get_type(data, struct nss_dp_req);
-
-    ndp_req->callback(err_maj, err_min, err_msg, ndp_req->callback_ctx);
-
-    talloc_free(ndp_req);
-}
-
 static int nss_dp_get_reply(DBusPendingCall *pending,
                             dbus_uint16_t *err_maj,
                             dbus_uint32_t *err_min,
@@ -193,9 +177,16 @@ static void nss_dp_send_acct_callback(DBusPendingCall 
*pending, void *ptr)
 
     ret = nss_dp_get_reply(pending, &err_maj, &err_min, &err_msg);
     if (ret != EOK) {
-        err_maj = DP_ERR_FATAL;
-        err_min = ret;
-        err_msg = "Failed to get reply from Data Provider";
+        if (ret == ETIME) {
+            err_maj = DP_ERR_TIMEOUT;
+            err_min = ret;
+            err_msg = "Request timed out";
+        }
+        else {
+            err_maj = DP_ERR_FATAL;
+            err_min = ret;
+            err_msg = "Failed to get reply from Data Provider";
+        }
     }
 
     ndp_req->callback(err_maj, err_min, err_msg, ndp_req->callback_ctx);
@@ -216,7 +207,6 @@ int nss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX 
*memctx,
     uint32_t be_type;
     const char *attrs = "core";
     char *filter;
-    struct timeval tv;
 
     /* either, or, not both */
     if (opt_name && opt_id) {
@@ -288,7 +278,7 @@ int nss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX 
*memctx,
     }
 
     ret = dbus_connection_send_with_reply(dbus_conn, msg, &pending_reply,
-                                            600000 /* TODO: set timeout */);
+                                          600000 /* TODO: set timeout */);
     if (!ret || pending_reply == NULL) {
         /*
          * Critical Failure
@@ -312,13 +302,6 @@ int nss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX 
*memctx,
     ndp_req->pending_reply = pending_reply;
     talloc_set_destructor((TALLOC_CTX *)ndp_req, nss_dp_req_destructor);
 
-    /* setup the timeout handler */
-    gettimeofday(&tv, NULL);
-    tv.tv_sec += timeout/1000;
-    tv.tv_usec += (timeout%1000) * 1000;
-    ndp_req->te = tevent_add_timer(rctx->ev, memctx, tv,
-                                   nss_dp_send_acct_timeout, ndp_req);
-
     /* Set up the reply handler */
     dbus_pending_call_set_notify(pending_reply,
                                  nss_dp_send_acct_callback,
@@ -363,7 +346,7 @@ static int nss_dp_get_reply(DBusPendingCall *pending,
                                     DBUS_TYPE_STRING, err_msg,
                                     DBUS_TYPE_INVALID);
         if (!ret) {
-            DEBUG(1,("Filed to parse message\n"));
+            DEBUG(1,("Failed to parse message\n"));
             /* FIXME: Destroy this connection ? */
             if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error);
             err = EIO;
@@ -376,6 +359,11 @@ static int nss_dp_get_reply(DBusPendingCall *pending,
         break;
 
     case DBUS_MESSAGE_TYPE_ERROR:
+        if (strcmp(dbus_message_get_error_name(reply),
+                   DBUS_ERROR_NO_REPLY) == 0) {
+            err = ETIME;
+            goto done;
+        }
         DEBUG(0,("The Data Provider returned an error [%s]\n",
                  dbus_message_get_error_name(reply)));
         /* Falling through to default intentionally*/
-- 
1.6.2.5

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to