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 #include <desktop/exithelper.h>
32 #include <osl/file.hxx>
33 #include <rtl/bootstrap.hxx>
34 #include <sal/log.hxx>
36 #include <vcl/glxtestprocess.hxx>
37 #include <vcl/svmain.hxx>
38 
39 #include <com/sun/star/beans/NamedValue.hpp>
40 #include <cppuhelper/bootstrap.hxx>
42 
43 #if HAVE_FEATURE_BREAKPAD
44 #include <fstream>
45 #include <desktop/crashreport.hxx>
46 
47 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
48 #include <client/linux/handler/exception_handler.h>
49 #elif defined WNT
50 #if defined __clang__
51 #pragma clang diagnostic push
52 #pragma clang diagnostic ignored "-Wmicrosoft-enum-value"
53 #endif
54 #include <client/windows/handler/exception_handler.h>
55 #if defined __clang__
56 #pragma clang diagnostic pop
57 #endif
58 #include <locale>
59 #include <codecvt>
60 #endif
61 
62 #endif
63 
64 
65 #ifdef ANDROID
66 # include <jni.h>
67 # include <android/log.h>
68 # include <salhelper/thread.hxx>
69 
70 # define LOGTAG "LibreOffice/sofficemain"
71 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
72 #endif
73 
74 #if HAVE_FEATURE_BREAKPAD
75 
76 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
77 static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* /*context*/, bool succeeded)
78 {
79  std::string ini_path = CrashReporter::getIniFileName();
80  std::ofstream minidump_file(ini_path, std::ios_base::app);
81  minidump_file << "DumpFile=" << descriptor.path() << "\n";
82  minidump_file.close();
83  SAL_WARN("desktop", "minidump generated: " << descriptor.path());
84  return succeeded;
85 }
86 #elif defined WNT
87 static bool dumpCallback(const wchar_t* path, const wchar_t* id,
88  void* /*context*/, EXCEPTION_POINTERS* /*exinfo*/,
89  MDRawAssertionInfo* /*assertion*/,
90  bool succeeded)
91 {
92  std::string ini_path = CrashReporter::getIniFileName();
93  std::ofstream minidump_file(ini_path, std::ios_base::app);
94  // TODO: moggi: can we avoid this conversion
95 #ifdef _MSC_VER
96 #pragma warning (disable: 4996)
97 #endif
98  std::wstring_convert<std::codecvt_utf8<wchar_t>> conv1;
99  std::string aPath = conv1.to_bytes(std::wstring(path)) + conv1.to_bytes(std::wstring(id)) + ".dmp";
100  minidump_file << "DumpFile=" << aPath << "\n";
101  minidump_file << "GDIHandles=" << ::GetGuiResources (::GetCurrentProcess(), GR_GDIOBJECTS) << "\n";
102  minidump_file.close();
103  SAL_WARN("desktop", "minidump generated: " << aPath);
104  return succeeded;
105 }
106 #endif
107 
108 #endif
110 {
111 #if HAVE_FEATURE_BREAKPAD
112 
113 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
114  google_breakpad::MinidumpDescriptor descriptor("/tmp");
115  google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, nullptr, true, -1);
116 
118 #elif defined WNT
119  google_breakpad::ExceptionHandler eh(L".", nullptr, dumpCallback, nullptr, google_breakpad::ExceptionHandler::HANDLER_ALL);
120 
122 #endif
123 #endif
124 
125 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) && HAVE_FEATURE_OPENGL
126  /* Run test for OpenGL support in own process to avoid crash with broken
127  * OpenGL drivers. Start process as early as possible.
128  * In non-headless mode, the process will be reaped in X11OpenGLDeviceInfo::GetData
129  * (vcl/opengl/x11/X11DeviceInfo.cxx). In headless mode, the process will be reaped late in
130  * Desktop::Main (desktop/source/app/app.cxx), in a code block that needs to be covered by the
131  * same #if condition as this code block.
132  */
133  bool bSuccess = fire_glxtest_process();
134  SAL_WARN_IF(!bSuccess, "desktop.opengl", "problems with glxtest");
135 #endif
136 
137 #if defined ANDROID
138  try {
139  rtl::Bootstrap::setIniFilename("file:///assets/program/lofficerc");
140 #endif
142 
143  desktop::Desktop aDesktop;
144  // This string is used during initialization of the Gtk+ VCL module
145  Application::SetAppName( "soffice" );
146 
147  // handle --version and --help already here, otherwise they would be handled
148  // after VCL initialization that might fail if $DISPLAY is not set
150  const OUString& aUnknown( rCmdLineArgs.GetUnknown() );
151  if ( !aUnknown.isEmpty() )
152  {
154  desktop::displayCmdlineHelp( aUnknown );
155  return EXIT_FAILURE;
156  }
157  if ( rCmdLineArgs.IsHelp() )
158  {
160  desktop::displayCmdlineHelp( OUString() );
161  return EXIT_SUCCESS;
162  }
163  if ( rCmdLineArgs.IsVersion() )
164  {
167  return EXIT_SUCCESS;
168  }
169 
170  return SVMain();
171 #if defined ANDROID
172  } catch (const css::uno::Exception &e) {
173  LOGI("Unhandled UNO exception: '%s'",
174  OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
175  throw; // to get exception type printed
176  }
177 #endif
178 }
179 
180 /* 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:75
const OUString & GetUnknown() const
Definition: cmdlineargs.hxx:99
bool fire_glxtest_process()
static CommandLineArgs & GetCommandLineArgs()
Definition: app.cxx:387
static std::string getIniFileName()
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
#define SAL_WARN_IF(condition, area, stream)
int DESKTOP_DLLPUBLIC soffice_main()
#define SAL_WARN(area, stream)
void extendApplicationEnvironment()