[vlc-commits] Qt: move run-time QApplication probe out of process

Rémi Denis-Courmont git at videolan.org
Thu Feb 8 23:16:17 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Feb  7 23:57:01 2018 +0200| [fb22fa854f203542a87dac8bb3bfc6e7b5328160] | committer: Rémi Denis-Courmont

Qt: move run-time QApplication probe out of process

This ensures that the QApplication constructor will not abort the whole
VLC process if it fails to initialize.

Unfortunately, this can be really slow depending how slow the
QApplication constructor is.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fb22fa854f203542a87dac8bb3bfc6e7b5328160
---

 modules/gui/qt/qt.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index c4c32f3f31..5a01d14bcf 100644
--- a/modules/gui/qt/qt.cpp
+++ b/modules/gui/qt/qt.cpp
@@ -28,6 +28,18 @@
 
 #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
 
+#include <stdlib.h>
+#include <unistd.h>
+#ifndef _POSIX_SPAWN
+# define _POSIX_SPAWN (-1)
+#endif
+#if (_POSIX_SPAWN >= 0)
+# include <spawn.h>
+# include <sys/wait.h>
+
+extern "C" char **environ;
+#endif
+
 #include <QApplication>
 #include <QDate>
 #include <QMutex>
@@ -422,6 +434,38 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
         return VLC_EGENERIC;
 #endif
 
+#if (_POSIX_SPAWN >= 0)
+    /* Check if QApplication works */
+    char *libdir = config_GetLibDir();
+    if (likely(libdir != NULL))
+    {
+        char *path;
+
+        if (unlikely(asprintf(&path, "%s/vlc-qt-check", libdir) < 0))
+            path = NULL;
+        free(libdir);
+        if (unlikely(path == NULL))
+            return VLC_ENOMEM;
+
+        char *argv[] = { path, NULL };
+        pid_t pid;
+
+        int val = posix_spawn(&pid, path, NULL, NULL, argv, environ);
+        free(path);
+        if (val)
+            return VLC_ENOMEM;
+
+        int status;
+        while (waitpid(pid, &status, 0) == -1);
+
+        if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+        {
+            msg_Dbg(p_this, "Qt check failed (%d). Skipping.", status);
+            return VLC_EGENERIC;
+        }
+    }
+#endif
+
     QMutexLocker locker (&lock);
     if (busy)
     {



More information about the vlc-commits mailing list