697eb64
From 1b3cf7e967aa103181a3203f5d504d49b49a5ab2 Mon Sep 17 00:00:00 2001
697eb64
From: Stephan Bergmann <sbergman@redhat.com>
697eb64
Date: Thu, 19 Apr 2018 13:59:16 +0200
697eb64
Subject: [PATCH] tdf#95843: Wait for fire_glxtest_process also in --headless
697eb64
 mode
697eb64
697eb64
Discussed with mmeeks on IRC that fire_glxtest_process is probably called as
697eb64
early as possible so that its reuslt is ready by the time it is needed in the
697eb64
non-headless case.  So best fix for headless is probably to just wait for the
697eb64
sub-process at an opportune point, instead of redesigning the whole mess so that
697eb64
fire_glxtest_process would only be called once its result is actually needed.
697eb64
697eb64
Change-Id: I4ea9c9d54b83c9695a3b72317e68fed0c410da0e
697eb64
Reviewed-on: https://gerrit.libreoffice.org/53154
697eb64
Tested-by: Jenkins <ci@libreoffice.org>
697eb64
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
697eb64
(cherry picked from commit 4bacf58f4af44ac8c4632b43289ccfcc07e5820c)
697eb64
---
697eb64
 desktop/inc/app.hxx                |  1 +
697eb64
 desktop/source/app/app.cxx         |  9 +++++++++
697eb64
 desktop/source/app/sofficemain.cxx |  4 ++++
697eb64
 vcl/inc/opengl/x11/glxtest.hxx     |  2 ++
697eb64
 vcl/unx/glxtest.cxx                | 16 ++++++++++++++++
697eb64
 5 files changed, 32 insertions(+)
697eb64
697eb64
diff --git a/desktop/inc/app.hxx b/desktop/inc/app.hxx
697eb64
index 0e5f8774d3c3..d0ef2a66818a 100644
697eb64
--- a/desktop/inc/app.hxx
697eb64
+++ b/desktop/inc/app.hxx
697eb64
@@ -181,6 +181,7 @@ OUString ReplaceStringHookProc(const OUString& rStr);
697eb64
 
697eb64
 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined LIBO_HEADLESS
697eb64
 bool fire_glxtest_process();
697eb64
+void reap_glxtest_process();
697eb64
 #endif
697eb64
 
697eb64
 #endif // INCLUDED_DESKTOP_INC_APP_HXX
697eb64
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
697eb64
index 192793ea42f1..583ea189165f 100644
697eb64
--- a/desktop/source/app/app.cxx
697eb64
+++ b/desktop/source/app/app.cxx
697eb64
@@ -1595,6 +1595,15 @@ int Desktop::Main()
697eb64
         CheckOpenCLCompute(xDesktop);
697eb64
 #endif
697eb64
 
697eb64
+        // In headless mode, reap the process started by fire_glxtest_process() early in soffice_main
697eb64
+        // (desktop/source/app/sofficemain.cxx), in a code block that needs to be covered by the same
697eb64
+        // #if condition as this code block:
697eb64
+#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) && HAVE_FEATURE_OPENGL
697eb64
+        if (rCmdLineArgs.IsHeadless()) {
697eb64
+            reap_glxtest_process();
697eb64
+        }
697eb64
+#endif
697eb64
+
697eb64
         // Release solar mutex just before we wait for our client to connect
697eb64
         {
697eb64
             SolarMutexReleaser aReleaser;
697eb64
diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx
697eb64
index 657614962489..67c1efe4a799 100644
697eb64
--- a/desktop/source/app/sofficemain.cxx
697eb64
+++ b/desktop/source/app/sofficemain.cxx
697eb64
@@ -122,6 +122,10 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main()
697eb64
 #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) && HAVE_FEATURE_OPENGL
697eb64
     /* Run test for OpenGL support in own process to avoid crash with broken
697eb64
      * OpenGL drivers. Start process as early as possible.
697eb64
+     * In non-headless mode, the process will be reaped in X11OpenGLDeviceInfo::GetData
697eb64
+     * (vcl/opengl/x11/X11DeviceInfo.cxx).  In headless mode, the process will be reaped late in
697eb64
+     * Desktop::Main (desktop/source/app/app.cxx), in a code block that needs to be covered by the
697eb64
+     * same #if condition as this code block.
697eb64
      */
697eb64
     bool bSuccess = fire_glxtest_process();
697eb64
     SAL_WARN_IF(!bSuccess, "desktop.opengl", "problems with glxtest");
697eb64
diff --git a/vcl/inc/opengl/x11/glxtest.hxx b/vcl/inc/opengl/x11/glxtest.hxx
697eb64
index 979f795de139..d74436aae111 100644
697eb64
--- a/vcl/inc/opengl/x11/glxtest.hxx
697eb64
+++ b/vcl/inc/opengl/x11/glxtest.hxx
697eb64
@@ -18,6 +18,8 @@ VCL_DLLPUBLIC pid_t* getGlxPid();
697eb64
 
697eb64
 bool fire_glxtest_process();
697eb64
 
697eb64
+void reap_glxtest_process();
697eb64
+
697eb64
 #endif
697eb64
 
697eb64
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
697eb64
diff --git a/vcl/unx/glxtest.cxx b/vcl/unx/glxtest.cxx
697eb64
index b0cdde234c2b..70d34fb7318d 100644
697eb64
--- a/vcl/unx/glxtest.cxx
697eb64
+++ b/vcl/unx/glxtest.cxx
697eb64
@@ -27,6 +27,8 @@
697eb64
 #include <string.h>
697eb64
 #include <signal.h>
697eb64
 
697eb64
+#include <sys/wait.h>
697eb64
+
697eb64
 #include <opengl/x11/glxtest.hxx>
697eb64
 
697eb64
 #ifdef __SUNPRO_CC
697eb64
@@ -36,6 +38,8 @@
697eb64
 #include <X11/Xlib.h>
697eb64
 #include <X11/Xutil.h>
697eb64
 
697eb64
+#include <sal/log.hxx>
697eb64
+
697eb64
 // stuff from glx.h
697eb64
 typedef struct __GLXcontextRec *GLXContext;
697eb64
 typedef XID GLXPixmap;
697eb64
@@ -275,3 +279,15 @@ bool fire_glxtest_process()
697eb64
   *glxtest_pid = pid;
697eb64
   return true;
697eb64
 }
697eb64
+
697eb64
+void reap_glxtest_process() {
697eb64
+    pid_t * pid = getGlxPid();
697eb64
+    if (*pid != 0) {
697eb64
+        // Use WNOHANG, as it is probably better to have a (rather harmless) zombie child process
697eb64
+        // hanging around for the duration of the calling process, than to potentially block the
697eb64
+        // calling process here:
697eb64
+        pid_t e = waitpid(*pid, nullptr, WNOHANG);
697eb64
+        SAL_INFO_IF(
697eb64
+            e <= 0, "vcl.opengl", "waiting for glxtest process " << *pid << " failed with " << e);
697eb64
+    }
697eb64
+}
697eb64
-- 
697eb64
2.14.3
697eb64