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

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