summaryrefslogtreecommitdiff
path: root/desktop/win32
diff options
context:
space:
mode:
authorPierre-Eric Pelloux-Prayer <pierre-eric@lanedo.com>2012-11-20 11:03:03 +0100
committerStephan Bergmann <sbergman@redhat.com>2012-12-13 11:16:12 +0100
commit0dce7eae55bf90d2a7171a1fb8663d66ba4ac6d3 (patch)
tree104a391ba1d2d6cdaa2bc121a522c827e45e8577 /desktop/win32
parent53fbd30b3cd6465251b1b07f4728813d524fcd82 (diff)
startup: more reliable startup of multiple instances
Until now, when a new soffice instance (S2) started and tried to connect to an existing soffice process (S1), S2 may have failed to boostrap due to race condition in communication over the shared pipe. S1 can be shutdown after S2 connected to it but _before_ S1 handled its arguments (code run after 'accept' method in OfficeIPCThread). This patch introduces a new message, sent by the main soffice after it has called accept if and only if it's not shutting down (see mbDowning member). The other soffice waits for this message before enabling going in PIPE_CONNECTED mode. If soffice fails to receive this message, pipe mode is left unchanged and after a quick pause, it will try again. Change-Id: I2e099a5804e1e8dd535cfd31ef454cffa44efa62 Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'desktop/win32')
-rw-r--r--desktop/win32/source/officeloader/officeloader.cxx60
1 files changed, 35 insertions, 25 deletions
diff --git a/desktop/win32/source/officeloader/officeloader.cxx b/desktop/win32/source/officeloader/officeloader.cxx
index b1a42565d547..c7c91c64f707 100644
--- a/desktop/win32/source/officeloader/officeloader.cxx
+++ b/desktop/win32/source/officeloader/officeloader.cxx
@@ -264,42 +264,52 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
if ( INVALID_HANDLE_VALUE != hPipe )
{
- DWORD dwBytesWritten;
- int argc2 = 0;
- LPWSTR *argv2 = CommandLineToArgvW( GetCommandLine(), &argc2 );
-
- fSuccess = WriteFile( hPipe, RTL_CONSTASCII_STRINGPARAM("InternalIPC::Arguments"), &dwBytesWritten, NULL );
- if (fSuccess) {
- if (cwdLen > 0) {
- fSuccess = writeArgument(hPipe, '2', cwd);
- } else {
- fSuccess = WriteFile(
- hPipe, RTL_CONSTASCII_STRINGPARAM("0"),
- &dwBytesWritten, NULL);
- }
- }
- for ( int argn = 1; fSuccess && argn < argc2; argn++ )
+ DWORD dwBytesRead = 0;
+ char *pBuffer = (char *)_alloca( sizeof("InternalIPC::SendArguments") + 1);
+ fSuccess = ReadFile( hPipe, pBuffer, sizeof("InternalIPC::SendArguments") + 1, &dwBytesRead, NULL );
+ if ( fSuccess )
{
- fSuccess = writeArgument(hPipe, ',', argv2[argn]);
+ fSuccess = (dwBytesRead == (sizeof("InternalIPC::SendArguments") + 1) &&
+ 0 == strncmp( "InternalIPC::SendArguments", pBuffer, dwBytesRead - 1 ) );
}
-
if ( fSuccess )
{
- fSuccess = WriteFile( hPipe, "", 1, &dwBytesWritten, NULL );
+ DWORD dwBytesWritten;
+ int argc2 = 0;
+ LPWSTR *argv2 = CommandLineToArgvW( GetCommandLine(), &argc2 );
+
+ fSuccess = WriteFile( hPipe, RTL_CONSTASCII_STRINGPARAM("InternalIPC::Arguments"), &dwBytesWritten, NULL );
+ if (fSuccess) {
+ if (cwdLen > 0) {
+ fSuccess = writeArgument(hPipe, '2', cwd);
+ } else {
+ fSuccess = WriteFile(
+ hPipe, RTL_CONSTASCII_STRINGPARAM("0"),
+ &dwBytesWritten, NULL);
+ }
+ }
+ for ( int argn = 1; fSuccess && argn < argc2; argn++ )
+ {
+ fSuccess = writeArgument(hPipe, ',', argv2[argn]);
+ }
+
if ( fSuccess )
{
- DWORD dwBytesRead = 0;
- char *pBuffer = (char *)_alloca( sizeof(PIPE_TERMINATION_SEQUENCE) );
- fSuccess = ReadFile( hPipe, pBuffer, sizeof(PIPE_TERMINATION_SEQUENCE) - 1, &dwBytesRead, NULL );
+ fSuccess = WriteFile( hPipe, "", 1, &dwBytesWritten, NULL );
if ( fSuccess )
{
- pBuffer[dwBytesRead] = 0;
- if ( 0 != strcmp( PIPE_TERMINATION_SEQUENCE, pBuffer ) )
- fSuccess = FALSE;
+ DWORD dwBytesRead = 0;
+ char *pBuffer = (char *)_alloca( sizeof(PIPE_TERMINATION_SEQUENCE) );
+ fSuccess = ReadFile( hPipe, pBuffer, sizeof(PIPE_TERMINATION_SEQUENCE) - 1, &dwBytesRead, NULL );
+ if ( fSuccess )
+ {
+ pBuffer[dwBytesRead] = 0;
+ if ( 0 != strcmp( PIPE_TERMINATION_SEQUENCE, pBuffer ) )
+ fSuccess = FALSE;
+ }
}
}
}
-
CloseHandle( hPipe );
return fSuccess ? 0 : -1;