desktop/unx/source/start.c  |   19 +++++++++++++++++--
 jvmfwk/source/framework.cxx |    7 ++++++-
 2 files changed, 23 insertions(+), 3 deletions(-)

New commits:
commit 6352710e02c12783280afccb3b5e03aab7948f19
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Sep 19 13:19:30 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Mon Sep 19 18:28:33 2022 +0200

    try harder to remove "OSL_PIPE" pipe on SIGTERM
    
    a) When oosplash got SIGTERM it used SIGKILL on soffice.bin, (concealed
    behind osl_terminateProcess) so soffice.bin has no chance to cleanup.
    
    Try SIGTERM, followed by SIGKILL if that doesn't work, to give
    soffice.bin a chance.
    
    b) java intercepts SIGTERM so if JNI_CreateJavaVM was called then
    our SIGTERM handler doesn't get called. Add -Xrs to jvm args to
    avoid this.
    
    Change-Id: I09f93d8093bc7c094482eda73b4eadc5a6cebb83
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140152
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/desktop/unx/source/start.c b/desktop/unx/source/start.c
index f959565665cc..ca2579c33a18 100644
--- a/desktop/unx/source/start.c
+++ b/desktop/unx/source/start.c
@@ -722,8 +722,23 @@ static void sigterm_handler(int ignored)
     (void) ignored;
 
     if (g_pProcess) {
-        osl_terminateProcess(g_pProcess); // forward signal to soffice.bin
-        osl_joinProcess(g_pProcess);
+        int SigTermSucceded = 0;
+        oslProcessInfo info;
+        info.Size = sizeof(oslProcessInfo);
+
+        // forward SIGTERM to soffice.bin and give it a chance to 
semi-gracefully exit
+        // enough to remove named pipe
+        if (osl_getProcessInfo(g_pProcess, osl_Process_IDENTIFIER, &info) == 
osl_Process_E_None) {
+            TimeValue delay = { 1, 0 }; // 1 sec
+            SigTermSucceded = kill(info.Ident, SIGTERM) == 0 &&
+                              osl_joinProcessWithTimeout(g_pProcess, &delay) 
== osl_Process_E_None;
+        }
+
+        // didn't work, SIGKILL instead
+        if (!SigTermSucceded) {
+            osl_terminateProcess(g_pProcess); // uses SIGKILL to terminate 
soffice.bin
+            osl_joinProcess(g_pProcess);
+        }
     }
 
     _exit(255);
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 8aa85082b838..5f83e7be739e 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -229,7 +229,7 @@ javaFrameworkError jfw_startVM(
         //options dialog
         std::unique_ptr<JavaVMOption[]> sarJOptions(
             new JavaVMOption[
-                arOptions.size() + (sUserClassPath.isEmpty() ? 1 : 2) + 
vmParams.size()]);
+                arOptions.size() + (sUserClassPath.isEmpty() ? 2 : 3) + 
vmParams.size()]);
         JavaVMOption * arOpt = sarJOptions.get();
         if (! arOpt)
             return JFW_E_ERROR;
@@ -248,6 +248,11 @@ javaFrameworkError jfw_startVM(
         arOpt[index].extraInfo = nullptr;
         ++index;
 
+        // Don't intercept SIGTERM
+        arOpt[index].optionString = const_cast<char *>("-Xrs");
+        arOpt[index].extraInfo = nullptr;
+        ++index;
+
         //add the options set by options dialog
         for (auto const & vmParam : vmParams)
         {

Reply via email to