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