DBus issue on Windows

Vincent Zhang winter_zh at msn.com
Fri Jun 10 19:41:08 PDT 2011


Hi,
 
1. I run dbus-daemon.exe on windows platform as a session bus, using "autolaunch:" address. When I run other programs that communicate with DBus, I found additional dbus-daemon processes created, all the preocess except the original one feed 64 bytes memory. After digging the code, I found it is the dbus daemon mutex issue: dbus daemon uses a shared memory file store the bus address and uses a mutex protect it, but the mutex is used incorrectly:
a) When publishing session bus address (function _dbus_daemon_publish_session_bus_address in dbus-sysdeps-win.c), it does not acquire the ownership of the mutex;
b) When checking dbus daemon running instance (function _dbus_daemon_already_runs in dbus-sysdeps-win.c), check condition of the result of function WaitForSingleObject should be WAIT_OBJECT_0, not WAIT_TIMEOUT.
Code with the above changes never lead the multiple dbus-daemon processes again.
 
2. There is another issue about session bus default address. DBUS_SESSION_BUS_DEFAULT_ADDRESS, deduced in configure.ac, is not exported to config.h, so the default session bus address used in dbus lib maybe inconsistent with the one in session.conf, so should the following line be added in configure.ac?
 
AC_DEFINE_UNQUOTED(DBUS_SESSION_BUS_DEFAULT_ADDRESS, "$DBUS_SESSION_BUS_DEFAULT_ADDRESS", [Session bus default address])

(The code described in item 1.)
dbus_bool_t
_dbus_daemon_publish_session_bus_address (const char* address, const char *scope)
{
  HANDLE lock;
  char *shared_addr = NULL;
  DWORD ret;
  char addressInfo[1024];
  DBusString shm_name;
  DBusString mutex_name;
  _dbus_assert (address);
  if (!_dbus_get_mutex_name(&mutex_name,scope))
    {
      _dbus_string_free( &mutex_name );
      return FALSE;
    }
  // sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs
  lock = _dbus_global_lock( cUniqueDBusInitMutex );
  if (!hDBusDaemonMutex)
    {
      hDBusDaemonMutex = CreateMutexA( NULL, FALSE, _dbus_string_get_const_data(&mutex_name) );
    }
  _dbus_string_free( &mutex_name );
  // acquire the mutex
  if (WaitForSingleObject( hDBusDaemonMutex, 10 ) != WAIT_OBJECT_0)
    {
   return FALSE;
 }
  if (!_dbus_get_shm_name(&shm_name,scope))
    {
      _dbus_string_free( &shm_name );
      _dbus_global_unlock( lock );
      return FALSE;
    }
  // create shm
  hDBusSharedMem = CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
                                       0, strlen( address ) + 1, _dbus_string_get_const_data(&shm_name) );
  _dbus_assert( hDBusSharedMem );
  shared_addr = MapViewOfFile( hDBusSharedMem, FILE_MAP_WRITE, 0, 0, 0 );
  _dbus_assert (shared_addr);
  strcpy( shared_addr, address);
  // cleanup
  UnmapViewOfFile( shared_addr );
  // release the ownership of dbus daemon mutex
  ReleaseMutex( hDBusDaemonMutex );
  _dbus_global_unlock( lock );
  _dbus_verbose( "published session bus address at %s\n",_dbus_string_get_const_data (&shm_name) );
  _dbus_string_free( &shm_name );
  return TRUE;
}
 
static dbus_bool_t
_dbus_daemon_already_runs (DBusString *address, DBusString *shm_name, const char *scope)
{
  HANDLE lock;
  HANDLE daemon;
  DBusString mutex_name;
  dbus_bool_t bRet = TRUE;
  if (!_dbus_get_mutex_name(&mutex_name,scope))
    {
      _dbus_string_free( &mutex_name );
      return FALSE;
    }
  // sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs
  lock = _dbus_global_lock( cUniqueDBusInitMutex );
  // do checks
  daemon = CreateMutexA( NULL, FALSE, _dbus_string_get_const_data(&mutex_name) );
  if(WaitForSingleObject( daemon, 10 ) != WAIT_OBJECT_0)
    {
      ReleaseMutex (daemon);
      CloseHandle (daemon);
      _dbus_global_unlock( lock );
      _dbus_string_free( &mutex_name );
      return FALSE;
    }
  // read shm
  bRet = _dbus_get_autolaunch_shm( address, shm_name );
  // cleanup
  ReleaseMutex (daemon);
  CloseHandle ( daemon );
  _dbus_global_unlock( lock );
  _dbus_string_free( &mutex_name );
  return bRet;
}

-Vincent
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20110611/b0b29fa6/attachment.htm>


More information about the dbus mailing list