diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 5d9c404f..1c72327f 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -2348,7 +2348,8 @@ _dbus_poll (DBusPollFD *fds, } /** - * Get current time, as in gettimeofday(). + * Get current time, as in gettimeofday(). Use the monotonic clock if + * available, to avoid problems when the system time changes. * * @param tv_sec return location for number of seconds * @param tv_usec return location for number of microseconds (thousandths) @@ -2359,12 +2360,22 @@ _dbus_get_current_time (long *tv_sec, { struct timeval t; +#ifdef HAVE_MONOTONIC_CLOCK + struct timespec ts; + clock_gettime (CLOCK_MONOTONIC, &ts); + + if (tv_sec) + *tv_sec = ts.tv_sec; + if (tv_usec) + *tv_usec = ts.tv_nsec / 1000; +#else gettimeofday (&t, NULL); if (tv_sec) *tv_sec = t.tv_sec; if (tv_usec) *tv_usec = t.tv_usec; +#endif } /** diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c index 5a153c6a..bfa4c435 100644 --- a/dbus/dbus-userdb.c +++ b/dbus/dbus-userdb.c @@ -226,7 +226,8 @@ static DBusString process_homedir; static void shutdown_system_db (void *data) { - _dbus_user_database_unref (system_db); + if (system_db != NULL) + _dbus_user_database_unref (system_db); system_db = NULL; _dbus_string_free (&process_username); _dbus_string_free (&process_homedir); @@ -345,7 +346,8 @@ _dbus_user_database_flush_system (void) { _dbus_user_database_lock_system (); - _dbus_user_database_flush (system_db); + if (system_db != NULL) + _dbus_user_database_flush (system_db); _dbus_user_database_unlock_system (); }