xref: /AOO41X/main/desktop/unx/source/officeloader/officeloader.cxx (revision 79aad27f7f29270c03e208e3d687e8e3850af11d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #include <sal/main.h>
28 #include <osl/process.h>
29 #include <rtl/ustring.hxx>
30 
31 #include "../../../source/inc/exithelper.hxx"
32 
33 using namespace rtl;
34 using namespace desktop;
35 
SAL_IMPLEMENT_MAIN()36 SAL_IMPLEMENT_MAIN()
37 {
38     oslProcess      process;
39     oslProcessError error;
40 
41     OUString    sExecutableFile;
42     rtl_uString **pCommandArgs;
43     sal_uInt32  nCommandArgs;
44 
45     osl_getExecutableFile( &sExecutableFile.pData );
46 
47     sExecutableFile += OUString( RTL_CONSTASCII_USTRINGPARAM(".bin") );
48 
49     nCommandArgs = osl_getCommandArgCount();
50     pCommandArgs = new rtl_uString *[nCommandArgs];
51 
52     for ( sal_uInt32 i = 0; i < nCommandArgs; i++ )
53     {
54         pCommandArgs[i] = NULL;
55         osl_getCommandArg( i, &pCommandArgs[i] );
56     }
57 
58     bool bRestart = false;
59     bool bFirstRun = true;
60     oslProcessExitCode  exitcode = 255;
61 
62     do  {
63         error = osl_executeProcess(
64             sExecutableFile.pData,
65             bFirstRun ? pCommandArgs : NULL,
66             bFirstRun ? nCommandArgs : 0,
67             0,
68             NULL,
69             NULL,
70             NULL,
71             0,
72             &process
73             );
74 
75         if ( osl_Process_E_None == error )
76         {
77             oslProcessInfo  info;
78 
79             info.Size = sizeof(info);
80 
81             error = osl_joinProcess( process );
82             if ( osl_Process_E_None != error )
83                 break;
84 
85             error = osl_getProcessInfo( process, osl_Process_EXITCODE, &info );
86             if ( osl_Process_E_None != error )
87                 break;
88 
89             if ( info.Fields & osl_Process_EXITCODE )
90             {
91                 exitcode = info.Code;
92                 bRestart = (ExitHelper::E_CRASH_WITH_RESTART == exitcode || ExitHelper::E_NORMAL_RESTART == exitcode);
93             }
94             else
95                 break;
96 
97             osl_freeProcessHandle( process );
98 
99         }
100 
101         bFirstRun = false;
102 
103     } while ( bRestart );
104 
105     return exitcode;
106 }
107