desktop/source/app/sofficemain.cxx |    3 ++
 include/sal/main.h                 |    7 ++++++
 sal/Library_sal.mk                 |    1 
 sal/osl/unx/salinit.cxx            |    6 +++++
 sal/osl/unx/signal.cxx             |   40 +------------------------------------
 sal/osl/unx/soffice.cxx            |   25 +++++++++++++++++++++++
 sal/osl/unx/soffice.hxx            |   26 ++++++++++++++++++++++++
 sal/osl/w32/salinit.cxx            |    4 +++
 8 files changed, 74 insertions(+), 38 deletions(-)

New commits:
commit 629dfff3c7289f185268c7088e67931f6bbd9ce0
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Fri Aug 30 09:16:55 2019 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Fri Aug 30 14:48:26 2019 +0200

    Replace is_soffice_Impl hack with a better(?) hack
    
    ...that involves adding a second, one-off special meaning to the existing
    sal_detail_initialize function.  This at least gets rid of the
    "osl_getExecutableFile contains 'soffice' substring" guesswork (and of the
    osl_systemPathGetFileNameOrLastDirectoryPart call there, which is what I'm
    actually after, for a different change to come).
    
    Change-Id: I4dd6eef1fd0411bf66943ffea415876c92d08526
    Reviewed-on: https://gerrit.libreoffice.org/78291
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/desktop/source/app/sofficemain.cxx 
b/desktop/source/app/sofficemain.cxx
index 805c4f07602e..2a692fdae8d4 100644
--- a/desktop/source/app/sofficemain.cxx
+++ b/desktop/source/app/sofficemain.cxx
@@ -32,6 +32,7 @@
 #include <osl/file.hxx>
 #include <rtl/bootstrap.hxx>
 #include <sal/log.hxx>
+#include <sal/main.h>
 #include <tools/extendapplicationenvironment.hxx>
 #include <vcl/glxtestprocess.hxx>
 #include <vcl/svmain.hxx>
@@ -108,6 +109,8 @@ static bool dumpCallback(const wchar_t* path, const 
wchar_t* id,
 #endif
 extern "C" int DESKTOP_DLLPUBLIC soffice_main()
 {
+    sal_detail_initialize(sal::detail::InitializeSoffice, nullptr);
+
 #if HAVE_FEATURE_BREAKPAD
 
 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
diff --git a/include/sal/main.h b/include/sal/main.h
index 9b5ba2b8d69b..d8a87c3e7f61 100644
--- a/include/sal/main.h
+++ b/include/sal/main.h
@@ -33,6 +33,13 @@
 extern "C" {
 #endif
 
+#if defined LIBO_INTERNAL_ONLY && defined __cplusplus
+// Special token for sal_detail_initialize argc parameter, used by the 
soffice.bin process to tell
+// SAL that it is running as part of that process (see 
sal/osl/unx/soffice.hxx); argv should be null
+// in such a sal_detail_initialize call:
+namespace sal::detail { constexpr int InitializeSoffice = -1; }
+#endif
+
 SAL_DLLPUBLIC void SAL_CALL sal_detail_initialize(int argc, char ** argv);
 SAL_DLLPUBLIC void SAL_CALL sal_detail_deinitialize(void);
 
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk
index a02c333852b7..86f2158f039a 100644
--- a/sal/Library_sal.mk
+++ b/sal/Library_sal.mk
@@ -175,6 +175,7 @@ $(eval $(call gb_Library_add_exception_objects,sal,\
        sal/osl/unx/security \
        sal/osl/unx/signal \
        sal/osl/unx/socket \
+       sal/osl/unx/soffice \
        sal/osl/unx/tempfile \
        sal/osl/unx/thread \
        sal/osl/unx/time \
diff --git a/sal/osl/unx/salinit.cxx b/sal/osl/unx/salinit.cxx
index 81a2d02ca31e..9424089dbba0 100644
--- a/sal/osl/unx/salinit.cxx
+++ b/sal/osl/unx/salinit.cxx
@@ -34,6 +34,7 @@
 #include <sal/types.h>
 
 #include "saltime.hxx"
+#include "soffice.hxx"
 #include <salusesyslog.hxx>
 
 #if HAVE_SYSLOG_H
@@ -45,6 +46,11 @@
 extern "C" {
 
 void sal_detail_initialize(int argc, char ** argv) {
+    if (argc == sal::detail::InitializeSoffice)
+    {
+        sal::detail::setSoffice();
+        return;
+    }
 #if defined MACOSX && !HAVE_FEATURE_MACOSX_SANDBOX
     // On macOS when not sandboxed, soffice can restart itself via exec (see
     // restartOnMac in desktop/source/app/app.cxx), which leaves all file
diff --git a/sal/osl/unx/signal.cxx b/sal/osl/unx/signal.cxx
index 085f14d8ec0c..55d09b4f6249 100644
--- a/sal/osl/unx/signal.cxx
+++ b/sal/osl/unx/signal.cxx
@@ -23,6 +23,7 @@
 
 #include <config_features.h>
 
+#include "soffice.hxx"
 /* system headers */
 #include "system.hxx"
 
@@ -54,8 +55,6 @@
 
 #include <osl/diagnose.h>
 #include <osl/signal.h>
-#include <osl/process.h>
-#include <osl/thread.h>
 #include <sal/log.hxx>
 #include <sal/macros.h>
 #include <rtl/bootstrap.h>
@@ -155,41 +154,6 @@ bool bSetILLHandler = false;
 
 void signalHandlerFunction(int, siginfo_t *, void *);
 
-void getExecutableName_Impl (rtl_String ** ppstrProgName)
-{
-    rtl_uString* ustrProgFile = nullptr;
-    osl_getExecutableFile (&ustrProgFile);
-    if (ustrProgFile)
-    {
-        rtl_uString * ustrProgName = nullptr;
-        osl_systemPathGetFileNameOrLastDirectoryPart (ustrProgFile, 
&ustrProgName);
-        if (ustrProgName != nullptr)
-        {
-            rtl_uString2String (
-                ppstrProgName,
-                rtl_uString_getStr (ustrProgName), rtl_uString_getLength 
(ustrProgName),
-                osl_getThreadTextEncoding(),
-                OUSTRING_TO_OSTRING_CVTFLAGS);
-            rtl_uString_release (ustrProgName);
-        }
-        rtl_uString_release (ustrProgFile);
-    }
-}
-
-bool is_soffice_Impl()
-{
-    sal_Int32 idx = -1;
-    rtl_String* strProgName = nullptr;
-
-    getExecutableName_Impl (&strProgName);
-    if (strProgName)
-    {
-        idx = rtl_str_indexOfStr (rtl_string_getStr (strProgName), "soffice");
-        rtl_string_release (strProgName);
-    }
-    return (idx != -1);
-}
-
 #if HAVE_FEATURE_BREAKPAD
 bool is_unset_signal(int signal)
 {
@@ -208,7 +172,7 @@ bool is_unset_signal(int signal)
 
 bool onInitSignal()
 {
-    if (is_soffice_Impl())
+    if (sal::detail::isSoffice())
     {
         // WORKAROUND FOR SEGV HANDLER CONFLICT
         //
diff --git a/sal/osl/unx/soffice.cxx b/sal/osl/unx/soffice.cxx
new file mode 100644
index 000000000000..bcead388ba4c
--- /dev/null
+++ b/sal/osl/unx/soffice.cxx
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <atomic>
+
+#include "soffice.hxx"
+
+namespace
+{
+std::atomic<bool> flag(false);
+}
+
+void sal::detail::setSoffice() { flag = true; }
+
+bool sal::detail::isSoffice() { return flag; }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sal/osl/unx/soffice.hxx b/sal/osl/unx/soffice.hxx
new file mode 100644
index 000000000000..da1b684af4ab
--- /dev/null
+++ b/sal/osl/unx/soffice.hxx
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SAL_OSL_UNX_SOFFICE_HXX
+#define INCLUDED_SAL_OSL_UNX_SOFFICE_HXX
+
+#include <sal/config.h>
+
+// Used to communicate special sal::detail::InitializeSoffice 
sal_detail_initialize call:
+
+namespace sal::detail
+{
+void setSoffice();
+
+bool isSoffice();
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sal/osl/w32/salinit.cxx b/sal/osl/w32/salinit.cxx
index 77cb5da781e5..9b89cebc20ab 100644
--- a/sal/osl/w32/salinit.cxx
+++ b/sal/osl/w32/salinit.cxx
@@ -32,6 +32,10 @@ extern "C" {
 
 void sal_detail_initialize(int argc, char ** argv)
 {
+    if (argc == sal::detail::InitializeSoffice)
+    {
+        return;
+    }
     sal_initGlobalTimer();
 #ifndef _WIN64
     SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to