[X2Go-Commits] [x2goclient] 23/116: {unixhelper.{cpp, h}, x2goclient.cpp}: switch main cleanup handling to parent PID polling.

git-admin at x2go.org git-admin at x2go.org
Mon Nov 30 05:07:29 CET 2015


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch bugfix/osx
in repository x2goclient.

commit cbd5b6b461a055b5294e2c27e1236dc195524a67
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Wed Mar 18 21:15:08 2015 +0100

    {unixhelper.{cpp,h},x2goclient.cpp}: switch main cleanup handling to parent PID polling.
---
 debian/changelog   |    2 ++
 src/unixhelper.cpp |    9 ++++++++-
 src/unixhelper.h   |   11 +++++++++--
 src/x2goclient.cpp |    2 +-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 72c8afa..0a488c4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -45,6 +45,8 @@ x2goclient (4.0.5.1-0x2go1) UNRELEASED; urgency=low
       (which is what execv is doing.)
     - unixhelper.{cpp,h}: raise sleeping time to two seconds and grace period
       to 10 seconds.
+    - {unixhelper.{cpp,h},x2goclient.cpp}: switch main cleanup handling to
+      parent PID polling.
 
   [ Oleksandr Shneyder ]
   * New upstream release (4.0.5.1):
diff --git a/src/unixhelper.cpp b/src/unixhelper.cpp
index d4698df..410c320 100644
--- a/src/unixhelper.cpp
+++ b/src/unixhelper.cpp
@@ -49,7 +49,7 @@ namespace unixhelper {
   }
 
 
-  int unix_cleanup () {
+  int unix_cleanup (const pid_t parent) {
     /*
      * Unblock all signals first.
      * Signal blocks are inherited, so you never you what is currently set.
@@ -100,6 +100,13 @@ namespace unixhelper {
 
     /* Sleep forever... at least two seconds in each run. */
     for (;;) {
+      pid_t cur_ppid = getppid ();
+
+      /* cur_ppid should match parent, otherwise the parent died. */
+      if (cur_ppid != parent) {
+        kill_pgroup (SIGHUP);
+      }
+
       sleep (2);
     }
   }
diff --git a/src/unixhelper.h b/src/unixhelper.h
index 9f213a8..7511d4d 100644
--- a/src/unixhelper.h
+++ b/src/unixhelper.h
@@ -22,6 +22,7 @@
 #define UNIXHELPER_H
 
 #include <QtCore/qglobal.h>
+#include <unistd.h>
 
 #ifdef Q_OS_UNIX
 
@@ -35,8 +36,12 @@ namespace unixhelper {
    * the whole process group killed.
    *
    * Loops indefinitely afterwards.
+   *
+   * In this loop, the current parent PID is polled and compared against
+   * the original value passed via parameter parent.
+   * Should they mismatch, the parent died and kill_pgroup() is called.
    */
-  int unix_cleanup ();
+  int unix_cleanup (const pid_t parent);
 
   /*
    * Kills the whole process group.
@@ -49,7 +54,9 @@ namespace unixhelper {
    * signal may be any of:
    *   * -1       to indicate an error leading to emergency termination
    *   * SIGHUP   as the standard signal that is sent when the
-   *              group leeader dies
+   *              group leader dies under specific circumstances
+   *              (we cannot rely that this always happens, though,
+   *               so a polling solution is needed, see unix_cleanup().)
    */
   void kill_pgroup (int signal);
 }
diff --git a/src/x2goclient.cpp b/src/x2goclient.cpp
index 479d564..92d614d 100644
--- a/src/x2goclient.cpp
+++ b/src/x2goclient.cpp
@@ -109,7 +109,7 @@ int main (int argc, char **argv) {
 
   if (unix_helper_request) {
     /* We were instructed to start as the UNIX cleanup helper tool. */
-    return (unixhelper::unix_cleanup ());
+    return (unixhelper::unix_cleanup (getppid ()));
   }
   else {
     /*

--
Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git


More information about the x2go-commits mailing list