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 <desktop/crashreport.hxx>
49 
50 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
51 #include <client/linux/handler/exception_handler.h>
52 #elif defined WNT
53 #if defined __clang__
54 #pragma clang diagnostic push
55 #pragma clang diagnostic ignored "-Wmicrosoft-enum-value"
56 #endif
57 #include <client/windows/handler/exception_handler.h>
58 #if defined __clang__
59 #pragma clang diagnostic pop
60 #endif
61 #include <locale>
62 #include <codecvt>
63 #endif
64 
65 #endif
66 
67 #include <postwin.h>
68 
69 #ifdef ANDROID
70 # include <jni.h>
71 # include <android/log.h>
72 # include <salhelper/thread.hxx>
73 
74 # define LOGTAG "LibreOffice/sofficemain"
75 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
76 #endif
77 
78 #if HAVE_FEATURE_BREAKPAD
79 
80 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
81 static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* /*context*/, bool succeeded)
82 {
83  CrashReporter::addKeyValue("DumpFile", OStringToOUString(descriptor.path(), RTL_TEXTENCODING_UTF8), CrashReporter::Write);
84  SAL_WARN("desktop", "minidump generated: " << descriptor.path());
85 
86  return succeeded;
87 }
88 #elif defined WNT
89 static bool dumpCallback(const wchar_t* path, const wchar_t* id,
90  void* /*context*/, EXCEPTION_POINTERS* /*exinfo*/,
91  MDRawAssertionInfo* /*assertion*/,
92  bool succeeded)
93 {
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  CrashReporter::addKeyValue("DumpFile", OStringToOUString(aPath.c_str(), RTL_TEXTENCODING_UTF8), CrashReporter::AddItem);
101  CrashReporter::addKeyValue("GDIHandles", OUString::number(::GetGuiResources (::GetCurrentProcess(), GR_GDIOBJECTS)), CrashReporter::Write);
102  SAL_WARN("desktop", "minidump generated: " << aPath);
103  return succeeded;
104 }
105 #endif
106 
107 #endif
109 {
110  sal_detail_initialize(sal::detail::InitializeSoffice, nullptr);
111 
112 #if HAVE_FEATURE_BREAKPAD
113 
114 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
115  google_breakpad::MinidumpDescriptor descriptor("/tmp");
116  google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, nullptr, true, -1);
117 
118  CrashReporter::storeExceptionHandler(&eh);
119 #elif defined WNT
120  google_breakpad::ExceptionHandler eh(L".", nullptr, dumpCallback, nullptr, google_breakpad::ExceptionHandler::HANDLER_ALL);
121 
122  CrashReporter::storeExceptionHandler(&eh);
123 #endif
124 #endif
125 
126 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && HAVE_FEATURE_UI && HAVE_FEATURE_OPENGL
127  /* Run test for OpenGL support in own process to avoid crash with broken
128  * OpenGL drivers. Start process as early as possible.
129  * In non-headless mode, the process will be reaped in X11OpenGLDeviceInfo::GetData
130  * (vcl/opengl/x11/X11DeviceInfo.cxx). In headless mode, the process will be reaped late in
131  * Desktop::Main (desktop/source/app/app.cxx), in a code block that needs to be covered by the
132  * same #if condition as this code block.
133  */
134  bool bSuccess = fire_glxtest_process();
135  SAL_WARN_IF(!bSuccess, "desktop.opengl", "problems with glxtest");
136 #endif
137 
138 #if defined ANDROID
139  try {
140  rtl::Bootstrap::setIniFilename("file:///assets/program/lofficerc");
141 #endif
143 
144  desktop::Desktop aDesktop;
145  // This string is used during initialization of the Gtk+ VCL module
146  Application::SetAppName( "soffice" );
147 
148  // handle --version and --help already here, otherwise they would be handled
149  // after VCL initialization that might fail if $DISPLAY is not set
151  const OUString& aUnknown( rCmdLineArgs.GetUnknown() );
152  if ( !aUnknown.isEmpty() )
153  {
155  desktop::displayCmdlineHelp( aUnknown );
156  return EXIT_FAILURE;
157  }
158  if ( rCmdLineArgs.IsHelp() )
159  {
161  desktop::displayCmdlineHelp( OUString() );
162  return EXIT_SUCCESS;
163  }
164  if ( rCmdLineArgs.IsVersion() )
165  {
168  return EXIT_SUCCESS;
169  }
170 
171  return SVMain();
172 #if defined ANDROID
173  } catch (const css::uno::Exception &e) {
174  LOGI("Unhandled UNO exception: '%s'",
175  OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
176  throw; // to get exception type printed
177  }
178 #endif
179 }
180 
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void displayCmdlineHelp(OUString const &unknown)
#define DESKTOP_DLLPUBLIC
Definition: dllapi.h:19
int SVMain()
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:384
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()
static void addKeyValue(SAL_UNUSED_PARAMETER const OUString &, SAL_UNUSED_PARAMETER const OUString &, SAL_UNUSED_PARAMETER tAddKeyHandling)
Definition: crashreport.hxx:87