LibreOffice Module desktop (master)  1
sofficemain.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 #include <config_features.h>
22 #include <config_version.h>
23 #include <config_folders.h>
24 
25 #include <desktop/dllapi.h>
26 
27 #include <app.hxx>
28 #include "cmdlineargs.hxx"
29 #include "cmdlinehelp.hxx"
30 
31 // needed before sal/main.h to avoid redefinition of macros
32 #include <prewin.h>
33 
34 #include <desktop/exithelper.h>
35 #include <osl/file.hxx>
36 #include <rtl/bootstrap.hxx>
37 #include <sal/log.hxx>
38 #include <sal/main.h>
40 #include <vcl/glxtestprocess.hxx>
41 #include <vcl/svmain.hxx>
42 
43 #include <com/sun/star/beans/NamedValue.hpp>
44 #include <cppuhelper/bootstrap.hxx>
46 
47 #if HAVE_FEATURE_BREAKPAD
48 #include <fstream>
49 #include <desktop/crashreport.hxx>
50 
51 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
52 #include <client/linux/handler/exception_handler.h>
53 #elif defined WNT
54 #if defined __clang__
55 #pragma clang diagnostic push
56 #pragma clang diagnostic ignored "-Wmicrosoft-enum-value"
57 #endif
58 #include <client/windows/handler/exception_handler.h>
59 #if defined __clang__
60 #pragma clang diagnostic pop
61 #endif
62 #include <locale>
63 #include <codecvt>
64 #endif
65 
66 #endif
67 
68 #include <postwin.h>
69 
70 #ifdef ANDROID
71 # include <jni.h>
72 # include <android/log.h>
73 # include <salhelper/thread.hxx>
74 
75 # define LOGTAG "LibreOffice/sofficemain"
76 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
77 #endif
78 
79 #if HAVE_FEATURE_BREAKPAD
80 
81 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
82 static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* /*context*/, bool succeeded)
83 {
84  std::string ini_path = CrashReporter::getIniFileName();
85  std::ofstream minidump_file(ini_path, std::ios_base::app);
86  minidump_file << "DumpFile=" << descriptor.path() << "\n";
87  minidump_file.close();
88  SAL_WARN("desktop", "minidump generated: " << descriptor.path());
89  return succeeded;
90 }
91 #elif defined WNT
92 static bool dumpCallback(const wchar_t* path, const wchar_t* id,
93  void* /*context*/, EXCEPTION_POINTERS* /*exinfo*/,
94  MDRawAssertionInfo* /*assertion*/,
95  bool succeeded)
96 {
97  std::string ini_path = CrashReporter::getIniFileName();
98  std::ofstream minidump_file(ini_path, std::ios_base::app);
99  // TODO: moggi: can we avoid this conversion
100 #ifdef _MSC_VER
101 #pragma warning (disable: 4996)
102 #endif
103  std::wstring_convert<std::codecvt_utf8<wchar_t>> conv1;
104  std::string aPath = conv1.to_bytes(std::wstring(path)) + conv1.to_bytes(std::wstring(id)) + ".dmp";
105  minidump_file << "DumpFile=" << aPath << "\n";
106  minidump_file << "GDIHandles=" << ::GetGuiResources (::GetCurrentProcess(), GR_GDIOBJECTS) << "\n";
107  minidump_file.close();
108  SAL_WARN("desktop", "minidump generated: " << aPath);
109  return succeeded;
110 }
111 #endif
112 
113 #endif
115 {
116  sal_detail_initialize(sal::detail::InitializeSoffice, nullptr);
117 
118 #if HAVE_FEATURE_BREAKPAD
119 
120 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
121  google_breakpad::MinidumpDescriptor descriptor("/tmp");
122  google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, nullptr, true, -1);
123 
125 #elif defined WNT
126  google_breakpad::ExceptionHandler eh(L".", nullptr, dumpCallback, nullptr, google_breakpad::ExceptionHandler::HANDLER_ALL);
127 
129 #endif
130 #endif
131 
132 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) && HAVE_FEATURE_OPENGL
133  /* Run test for OpenGL support in own process to avoid crash with broken
134  * OpenGL drivers. Start process as early as possible.
135  * In non-headless mode, the process will be reaped in X11OpenGLDeviceInfo::GetData
136  * (vcl/opengl/x11/X11DeviceInfo.cxx). In headless mode, the process will be reaped late in
137  * Desktop::Main (desktop/source/app/app.cxx), in a code block that needs to be covered by the
138  * same #if condition as this code block.
139  */
140  bool bSuccess = fire_glxtest_process();
141  SAL_WARN_IF(!bSuccess, "desktop.opengl", "problems with glxtest");
142 #endif
143 
144 #if defined ANDROID
145  try {
146  rtl::Bootstrap::setIniFilename("file:///assets/program/lofficerc");
147 #endif
149 
150  desktop::Desktop aDesktop;
151  // This string is used during initialization of the Gtk+ VCL module
152  Application::SetAppName( "soffice" );
153 
154  // handle --version and --help already here, otherwise they would be handled
155  // after VCL initialization that might fail if $DISPLAY is not set
157  const OUString& aUnknown( rCmdLineArgs.GetUnknown() );
158  if ( !aUnknown.isEmpty() )
159  {
161  desktop::displayCmdlineHelp( aUnknown );
162  return EXIT_FAILURE;
163  }
164  if ( rCmdLineArgs.IsHelp() )
165  {
167  desktop::displayCmdlineHelp( OUString() );
168  return EXIT_SUCCESS;
169  }
170  if ( rCmdLineArgs.IsVersion() )
171  {
174  return EXIT_SUCCESS;
175  }
176 
177  return SVMain();
178 #if defined ANDROID
179  } catch (const css::uno::Exception &e) {
180  LOGI("Unhandled UNO exception: '%s'",
181  OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
182  throw; // to get exception type printed
183  }
184 #endif
185 }
186 
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void displayCmdlineHelp(OUString const &unknown)
#define DESKTOP_DLLPUBLIC
Definition: dllapi.h:19
int SVMain()
static void storeExceptionHandler(google_breakpad::ExceptionHandler *pExceptionHandler)
static void SetAppName(const OUString &rUniqueName)
void displayVersion()
static void InitApplicationServiceManager()
Definition: appinit.cxx:76
const OUString & GetUnknown() const
Definition: cmdlineargs.hxx:99
bool fire_glxtest_process()
static CommandLineArgs & GetCommandLineArgs()
Definition: app.cxx:386
static std::string getIniFileName()
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
SAL_DLLPUBLIC void SAL_CALL sal_detail_initialize(int argc, char **argv)
#define SAL_WARN_IF(condition, area, stream)
int DESKTOP_DLLPUBLIC soffice_main()
#define SAL_WARN(area, stream)
void extendApplicationEnvironment()