fix deadlock when dbus-daemon could not start up

windbus:r811: apply patch by Thorvald Natvig to fix endless loop when _dbus_get_autolaunch_shm got called and the dbus-daemon failed to start up.
* if launching for some reason fails, set an error message
* _dbus_get_autolaunch_shm will abort getting the shared memory after 20 attempts (2 seconds)
* _dbus_get_autolaunch_address checks if the return state of WaitForInputIdle before calling _dbus_get_autolaunch_shm.

windbus:r812: remove WaitForInputIdle as it doesn't work in non-console mode
(cherry picked from commit 363fd736556219bad77c4b217e051b7983dc34e9)
This commit is contained in:
Christian Ehrlicher 2009-04-27 13:41:48 +02:00 committed by unknown
parent 722a90c9cb
commit a83b7cb80c

View file

@ -3027,6 +3027,7 @@ _dbus_get_autolaunch_shm(DBusString *adress)
char szUserName[64];
DWORD dwUserNameSize = sizeof(szUserName);
char szDBusDaemonAddressInfo[128];
int i;
if( !GetUserName(szUserName, &dwUserNameSize) )
return FALSE;
@ -3034,12 +3035,14 @@ _dbus_get_autolaunch_shm(DBusString *adress)
cDBusDaemonAddressInfo, szUserName);
// read shm
do {
for(i=0;i<20;++i) {
// we know that dbus-daemon is available, so we wait until shm is available
sharedMem = OpenFileMapping( FILE_MAP_READ, FALSE, szDBusDaemonAddressInfo );
if( sharedMem == 0 )
Sleep( 100 );
} while( sharedMem == 0 );
if ( sharedMem != 0)
break;
}
if( sharedMem == 0 )
return FALSE;
@ -3145,19 +3148,16 @@ _dbus_get_autolaunch_address (DBusString *address,
_snprintf(dbus_args, sizeof(dbus_args) - 1, "\"%s\" %s", dbus_exe_path, " --session");
// argv[i] = "--config-file=bus\\session.conf";
printf("create process \"%s\" %s\n", dbus_exe_path, dbus_args);
// printf("create process \"%s\" %s\n", dbus_exe_path, dbus_args);
if(CreateProcessA(dbus_exe_path, dbus_args, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
{
retval = TRUE;
// Wait until started (see _dbus_get_autolaunch_shm())
WaitForInputIdle(pi.hProcess, INFINITE);
retval = _dbus_get_autolaunch_shm( address );
} else {
retval = FALSE;
}
if (retval == FALSE)
dbus_set_error_const (error, DBUS_ERROR_FAILED, "Failed to launch dbus-daemon");
out:
if (retval)
_DBUS_ASSERT_ERROR_IS_CLEAR (error);