1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_desktop.hxx"
30 
31 #include <sal/main.h>
32 #include <osl/process.h>
33 #include <rtl/ustring.hxx>
34 
35 #include "../../../source/inc/exithelper.hxx"
36 
37 using namespace rtl;
38 using namespace desktop;
39 
40 SAL_IMPLEMENT_MAIN()
41 {
42 	oslProcess		process;
43 	oslProcessError	error;
44 
45 	OUString	sExecutableFile;
46 	rtl_uString	**pCommandArgs;
47 	sal_uInt32	nCommandArgs;
48 
49 	osl_getExecutableFile( &sExecutableFile.pData );
50 
51 	sExecutableFile += OUString( RTL_CONSTASCII_USTRINGPARAM(".bin") );
52 
53 	nCommandArgs = osl_getCommandArgCount();
54 	pCommandArgs = new rtl_uString *[nCommandArgs];
55 
56 	for ( sal_uInt32 i = 0; i < nCommandArgs; i++ )
57 	{
58 		pCommandArgs[i] = NULL;
59 		osl_getCommandArg( i, &pCommandArgs[i] );
60 	}
61 
62 	bool bRestart = false;
63 	bool bFirstRun = true;
64 	oslProcessExitCode	exitcode = 255;
65 
66 	do  {
67 		error = osl_executeProcess(
68 			sExecutableFile.pData,
69 			bFirstRun ? pCommandArgs : NULL,
70 			bFirstRun ? nCommandArgs : 0,
71 			0,
72 			NULL,
73 			NULL,
74 			NULL,
75 			0,
76 			&process
77 			);
78 
79 		if ( osl_Process_E_None == error )
80 		{
81 			oslProcessInfo	info;
82 
83 			info.Size = sizeof(info);
84 
85 			error = osl_joinProcess( process );
86 			if ( osl_Process_E_None != error )
87 				break;
88 
89 			error = osl_getProcessInfo( process, osl_Process_EXITCODE, &info );
90 			if ( osl_Process_E_None != error )
91 				break;
92 
93 			if ( info.Fields & osl_Process_EXITCODE )
94 			{
95 				exitcode = info.Code;
96 				bRestart = (ExitHelper::E_CRASH_WITH_RESTART == exitcode || ExitHelper::E_NORMAL_RESTART == exitcode);
97 			}
98 			else
99 				break;
100 
101 			osl_freeProcessHandle( process );
102 
103 		}
104 
105 		bFirstRun = false;
106 
107 	} while ( bRestart );
108 
109 	return exitcode;
110 }
111