From 01b0bd2049dd5840148c5edd8f2bcd9f3acff128 Mon Sep 17 00:00:00 2001
From: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
Date: Sun, 18 Oct 2026 09:21:26 -0300
Subject: Improve GStreamer helper lifecycle diagnostics
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
---
 src/gstplayer.cpp | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/gstplayer.cpp b/src/gstplayer.cpp
index e213a4a..e22a8f8 100644
--- a/src/gstplayer.cpp
+++ b/src/gstplayer.cpp
@@ -20,7 +20,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
-#ifdef __linux__
+#include <errno.h>
+#include <tqglobal.h>
+#ifdef Q_OS_LINUX
 #include <signal.h>
 #include <sys/prctl.h>
 #include <unistd.h>
@@ -999,7 +1001,7 @@ protected:
 };
 
 int main(int argc, char **argv) {
-#ifdef __linux__
+#ifdef Q_OS_LINUX
     pid_t parent = getppid ();
 #endif
     if (!XInitThreads ()) {
@@ -1056,12 +1058,16 @@ int main(int argc, char **argv) {
         }
     }
 
-#ifdef __linux__
+#ifdef Q_OS_LINUX
     if (callback) {
         if (prctl (PR_SET_PDEATHSIG, SIGTERM) < 0)
-            perror ("prctl (PR_SET_PDEATHSIG)");
-        if (getppid () != parent)
+            fprintf (stderr, "prctl (PR_SET_PDEATHSIG) failed: %s\n", strerror (errno));
+        pid_t current_parent = getppid ();
+        if (current_parent != parent) {
+            fprintf (stderr, "Parent process changed from %ld to %ld; terminating helper\n",
+                    (long) parent, (long) current_parent);
             raise (SIGTERM);
+        }
     }
 #endif
     DCOPClient dcopclient;
-- 
cgit v1.2.3

