<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Hi,<BR>
<BR>
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:<BR>
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;<BR>
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.<BR>
Code with the above changes never lead the multiple dbus-daemon processes again.<BR>
<BR>
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?<BR>
<BR>
AC_DEFINE_UNQUOTED(DBUS_SESSION_BUS_DEFAULT_ADDRESS, "$DBUS_SESSION_BUS_DEFAULT_ADDRESS", [Session bus default address])<BR><BR>
(The code described in item 1.)<BR>
dbus_bool_t<BR>_dbus_daemon_publish_session_bus_address (const char* address, const char *scope)<BR>{<BR> HANDLE lock;<BR> char *shared_addr = NULL;<BR> DWORD ret;<BR> char addressInfo[1024];<BR> DBusString shm_name;<BR> DBusString mutex_name;<BR>
_dbus_assert (address);<BR>
if (!_dbus_get_mutex_name(&mutex_name,scope))<BR> {<BR> _dbus_string_free( &mutex_name );<BR> return FALSE;<BR> }<BR>
// sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs<BR> lock = _dbus_global_lock( cUniqueDBusInitMutex );<BR>
if (!hDBusDaemonMutex)<BR> {<BR> hDBusDaemonMutex = CreateMutexA( NULL, FALSE, _dbus_string_get_const_data(&mutex_name) );<BR> }<BR> _dbus_string_free( &mutex_name );<BR>
// acquire the mutex<BR> if (WaitForSingleObject( hDBusDaemonMutex, 10 ) != WAIT_OBJECT_0)<BR> {<BR> return FALSE;<BR> }<BR>
if (!_dbus_get_shm_name(&shm_name,scope))<BR> {<BR> _dbus_string_free( &shm_name );<BR> _dbus_global_unlock( lock );<BR> return FALSE;<BR> }<BR>
// create shm<BR> hDBusSharedMem = CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,<BR> 0, strlen( address ) + 1, _dbus_string_get_const_data(&shm_name) );<BR> _dbus_assert( hDBusSharedMem );<BR>
shared_addr = MapViewOfFile( hDBusSharedMem, FILE_MAP_WRITE, 0, 0, 0 );<BR>
_dbus_assert (shared_addr);<BR>
strcpy( shared_addr, address);<BR>
// cleanup<BR> UnmapViewOfFile( shared_addr );<BR> // release the ownership of dbus daemon mutex<BR> ReleaseMutex( hDBusDaemonMutex );<BR>
_dbus_global_unlock( lock );<BR> _dbus_verbose( "published session bus address at %s\n",_dbus_string_get_const_data (&shm_name) );<BR>
_dbus_string_free( &shm_name );<BR> return TRUE;<BR>}<BR>
<BR>
static dbus_bool_t<BR>_dbus_daemon_already_runs (DBusString *address, DBusString *shm_name, const char *scope)<BR>{<BR> HANDLE lock;<BR> HANDLE daemon;<BR> DBusString mutex_name;<BR> dbus_bool_t bRet = TRUE;<BR>
if (!_dbus_get_mutex_name(&mutex_name,scope))<BR> {<BR> _dbus_string_free( &mutex_name );<BR> return FALSE;<BR> }<BR>
// sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs<BR> lock = _dbus_global_lock( cUniqueDBusInitMutex );<BR>
// do checks<BR> daemon = CreateMutexA( NULL, FALSE, _dbus_string_get_const_data(&mutex_name) );<BR> if(WaitForSingleObject( daemon, 10 ) != WAIT_OBJECT_0)<BR> {<BR> ReleaseMutex (daemon);<BR> CloseHandle (daemon);<BR>
_dbus_global_unlock( lock );<BR> _dbus_string_free( &mutex_name );<BR> return FALSE;<BR> }<BR>
// read shm<BR> bRet = _dbus_get_autolaunch_shm( address, shm_name );<BR>
// cleanup<BR> ReleaseMutex (daemon);<BR> CloseHandle ( daemon );<BR>
_dbus_global_unlock( lock );<BR> _dbus_string_free( &mutex_name );<BR>
return bRet;<BR>}<BR><BR>
-Vincent<BR><BR>                                            </body>
</html>