summaryrefslogtreecommitdiff
path: root/dbind
diff options
context:
space:
mode:
authorMike Gorse <mgorse@novell.com>2011-01-30 11:50:38 -0600
committerMike Gorse <mgorse@novell.com>2011-01-30 11:50:38 -0600
commit047b023b3c0437c6e15493df4e2433842fd761e3 (patch)
treeee3d7c573cd29eac3f0ccf0f9f73d0aa685460ce /dbind
parentea971a90c12b82ed40ade60b7a91734daa0872a1 (diff)
downloadat-spi2-core-047b023b3c0437c6e15493df4e2433842fd761e3.tar.gz
Fix check for message timeout
Diffstat (limited to 'dbind')
-rw-r--r--dbind/dbind.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/dbind/dbind.c b/dbind/dbind.c
index 23046f2f..084de285 100644
--- a/dbind/dbind.c
+++ b/dbind/dbind.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdarg.h>
+#include <sys/time.h>
#include <glib.h>
#include "config.h"
@@ -30,6 +31,15 @@ set_reply (DBusPendingCall * pending, void *user_data)
dbus_pending_call_unref (pending);
}
+static gint
+time_elapsed (struct timeval *origin)
+{
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ return (tv.tv_sec - origin->tv_sec) * 1000 + (tv.tv_usec - origin->tv_usec) / 1000;
+}
+
DBusMessage *
dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
{
@@ -37,6 +47,7 @@ dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusE
SpiReentrantCallClosure closure;
const char *unique_name = dbus_bus_get_unique_name (bus);
const char *destination = dbus_message_get_destination (message);
+ struct timeval tv;
if (unique_name && destination &&
strcmp (destination, unique_name) != 0)
@@ -51,10 +62,13 @@ dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusE
dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
closure.reply = NULL;
+ gettimeofday (&tv, NULL);
while (!closure.reply)
{
if (!dbus_connection_read_write_dispatch (bus, dbind_timeout))
return NULL;
+if (time_elapsed (&tv) > dbind_timeout)
+ return NULL;
}
return closure.reply;