From b3bd48edfc1aab0a9dc64bfa4c380d845d218e73 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 25 Apr 2003 23:50:34 +0000 Subject: 2003-04-25 Havoc Pennington test suite is slightly hosed at the moment, will fix soon * bus/connection.c (bus_connections_expire_incomplete): fix to properly disable the timeout when required (bus_connection_set_name): check whether we can remove incomplete connections timeout after we complete each connection. * dbus/dbus-mainloop.c (check_timeout): fix this up a bit, probably still broken. * bus/services.c (bus_registry_acquire_service): implement max number of services owned, and honor allow/deny rules on which services a connection can own. * bus/connection.c (bus_connection_get_policy): report errors here * bus/activation.c: implement limit on number of pending activations --- dbus/dbus-mainloop.c | 86 ++++++++++++++++++++++++++++------------------------ dbus/dbus-timeout.c | 2 ++ 2 files changed, 49 insertions(+), 39 deletions(-) (limited to 'dbus') diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index 1d1af78c..60191882 100644 --- a/dbus/dbus-mainloop.c +++ b/dbus/dbus-mainloop.c @@ -356,10 +356,12 @@ check_timeout (unsigned long tv_sec, long interval_milliseconds; int interval; + /* I'm pretty sure this function could suck (a lot) less */ + interval = dbus_timeout_get_interval (tcb->timeout); - interval_seconds = interval / 1000; - interval_milliseconds = interval - interval_seconds * 1000; + interval_seconds = interval / 1000L; + interval_milliseconds = interval % 1000L; expiration_tv_sec = tcb->last_tv_sec + interval_seconds; expiration_tv_usec = tcb->last_tv_usec + interval_milliseconds * 1000; @@ -368,44 +370,35 @@ check_timeout (unsigned long tv_sec, expiration_tv_usec -= 1000000; expiration_tv_sec += 1; } - - if (expiration_tv_sec < tv_sec || - (expiration_tv_sec == tv_sec && expiration_tv_usec < tv_usec)) - { - _dbus_verbose ("System clock went backward interval_seconds %ld interval_msecs %ld last_tv_sec %lu last_tv_usec %lu tv_sec %lu tv_usec %lu\n", - interval_seconds, interval_milliseconds, - tcb->last_tv_sec, tcb->last_tv_usec, tv_sec, tv_usec); - - /* The system time has been set backwards, reset the timeout to "interval" in the future */ - - tcb->last_tv_sec = tv_sec; - tcb->last_tv_usec = tv_usec; - - *timeout = interval; - - return FALSE; - } sec_remaining = expiration_tv_sec - tv_sec; - msec_remaining = (expiration_tv_usec - tv_usec) / 1000; - -#if 0 - printf ("Interval is %ld seconds %ld msecs\n", - interval_seconds, - interval_milliseconds); - printf ("Now is %lu seconds %lu usecs\n", - tv_sec, tv_usec); - printf ("Exp is %lu seconds %lu usecs\n", - expiration_tv_sec, expiration_tv_usec); - printf ("Pre-correction, remaining sec_remaining %ld msec_remaining %ld\n", sec_remaining, msec_remaining); + /* need to force this to be signed, as it is intended to sometimes + * produce a negative result + */ + msec_remaining = ((long) expiration_tv_usec - (long) tv_usec) / 1000L; + +#if MAINLOOP_SPEW + _dbus_verbose ("Interval is %ld seconds %ld msecs\n", + interval_seconds, + interval_milliseconds); + _dbus_verbose ("Now is %lu seconds %lu usecs\n", + tv_sec, tv_usec); + _dbus_verbose ("Last is %lu seconds %lu usecs\n", + tcb->last_tv_sec, tcb->last_tv_usec); + _dbus_verbose ("Exp is %lu seconds %lu usecs\n", + expiration_tv_sec, expiration_tv_usec); + _dbus_verbose ("Pre-correction, sec_remaining %ld msec_remaining %ld\n", + sec_remaining, msec_remaining); #endif /* We do the following in a rather convoluted fashion to deal with * the fact that we don't have an integral type big enough to hold - * the difference of two timevals in millseconds. + * the difference of two timevals in milliseconds. */ if (sec_remaining < 0 || (sec_remaining == 0 && msec_remaining < 0)) - msec_remaining = 0; + { + *timeout = 0; + } else { if (msec_remaining < 0) @@ -414,20 +407,29 @@ check_timeout (unsigned long tv_sec, sec_remaining -= 1; } - if (msec_remaining > _DBUS_INT_MAX) - { - /* Not going to fit in a 32-bit integer */ - msec_remaining = _DBUS_INT_MAX; - } + if (sec_remaining > (_DBUS_INT_MAX / 1000) || + msec_remaining > _DBUS_INT_MAX) + *timeout = _DBUS_INT_MAX; + else + *timeout = sec_remaining * 1000 + msec_remaining; } - *timeout = msec_remaining; + if (*timeout > interval) + { + /* This indicates that the system clock probably moved backward */ + _dbus_verbose ("System clock set backward! Resetting timeout.\n"); + + tcb->last_tv_sec = tv_sec; + tcb->last_tv_usec = tv_usec; + *timeout = interval; + } + #if MAINLOOP_SPEW _dbus_verbose (" timeout expires in %d milliseconds\n", *timeout); #endif - return msec_remaining == 0; + return *timeout == 0; } dbus_bool_t @@ -708,6 +710,12 @@ _dbus_loop_iterate (DBusLoop *loop, retval = TRUE; } + else + { +#if MAINLOOP_SPEW + _dbus_verbose (" timeout has not expired\n"); +#endif + } } link = next; diff --git a/dbus/dbus-timeout.c b/dbus/dbus-timeout.c index 74210f9a..1a2d2965 100644 --- a/dbus/dbus-timeout.c +++ b/dbus/dbus-timeout.c @@ -124,6 +124,8 @@ void _dbus_timeout_set_interval (DBusTimeout *timeout, int interval) { + _dbus_assert (interval >= 0); + timeout->interval = interval; } -- cgit