Blame SOURCES/0001-tdf-95843-Wait-for-fire_glxtest_process-also-in-head.patch

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