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

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

commit c77f3e03875b90e0941e3ab50effdb566ce7d5d3
Author: Mihai Moldovan <io...@ionic.de>
Date:   Fri Aug 12 09:00:41 2016 +0200

    src/unixhelper.{cpp,h}: split off core functionality of kill_pgroup () into 
a new function called real_kill_pgroup ().
---
 debian/changelog   |    2 ++
 src/unixhelper.cpp |   37 +++++++++++++++++++++++++++----------
 src/unixhelper.h   |   12 ++++++++++++
 3 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index c9e4373..c4c8c40 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -367,6 +367,8 @@ x2goclient (4.0.5.3-0x2go1) UNRELEASED; urgency=medium
     - src/pulsemanager.cpp: fix PA version fetching on OS X again.
     - src/unixhelper.{cpp,h}: make argument of kill_pgroup () const.
     - src/unixhelper.h: style and general fixes within comments.
+    - src/unixhelper.{cpp,h}: split off core functionality of kill_pgroup ()
+      into a new function called real_kill_pgroup ().
 
  -- X2Go Release Manager <git-ad...@x2go.org>  Mon, 19 Sep 2016 09:07:07 +0200
 
diff --git a/src/unixhelper.cpp b/src/unixhelper.cpp
index 4488786..4d9c56f 100644
--- a/src/unixhelper.cpp
+++ b/src/unixhelper.cpp
@@ -30,25 +30,42 @@
 #include <cerrno>
 #include <vector>
 #include <cstdlib>
+#include <stdio.h>
+#include <string.h>
 
 /* For documentation please see unixhelper.h. */
 
 namespace unixhelper {
   void kill_pgroup (const int signal) {
-    if (SIGHUP == signal) {
-      /* Try to kill via SIGTERM first. */
-      if (0 != killpg (getpgrp (), SIGTERM)) {
-        std::cerr << "WARNING: unable to send SIGTERM to process group: " << 
std::strerror (errno) << std::endl;
-      }
+  }
+
+  void real_kill_pgroup (const pid_t pgid) {
+    /* Try to kill via SIGTERM first. */
+    if (0 != killpg (pgid, SIGTERM)) {
+      std::cerr << "WARNING: unable to send SIGTERM to process group '" << 
pgid << "': " << std::strerror (errno) << std::endl;
+    }
+
+    /* Grant a grace period of (at least) 10 seconds. */
+    sleep (10);
 
-      /* Grant a grace period of (at least) 10 seconds. */
-      sleep (10);
+    int kill_ret = killpg (pgid, SIGKILL);
 
-      /* Don't handle any errors here, because we die anyway. */
-      killpg (getpgrp (), SIGKILL);
+    /*
+     * Might be unreachable.
+     * Depending upon which pgroup we just killed, this
+     * code is either unreachable (because killpg () killed
+     * itself already), or being executed.
+     * Let's handle errors and exit, if necessary.
+     */
+    if (0 != kill_ret) {
+      char err_str[512] = { };
+      snprintf (err_str, 512, "WARNING: failed to kill process group '%d'", 
pgid);
+
+      perror (err_str);
     }
-  }
 
+    exit (EXIT_SUCCESS);
+  }
 
   int unix_cleanup (const pid_t parent) {
     /*
diff --git a/src/unixhelper.h b/src/unixhelper.h
index d67f3ed..662b3be 100644
--- a/src/unixhelper.h
+++ b/src/unixhelper.h
@@ -63,6 +63,18 @@ namespace unixhelper {
    * Other values are not handled.
    */
   void kill_pgroup (const int signal);
+
+  /*
+   * Kills the whole process group.
+   * First, SIGTERM is sent to the group.
+   * A 10 seconds grace period is granted to make sure
+   * processes exit cleanly on their own.
+   * Lastly, SIGKILL is sent to the group -- which also
+   * implies the demise of this program.
+   *
+   * pgid is the process group ID to be killed.
+   */
+  void real_kill_pgroup (const pid_t pgid);
 }
 
 #endif /* defined (Q_OS_UNIX) */

--
Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email 
on /srv/git/code.x2go.org/x2goclient.git
_______________________________________________
x2go-commits mailing list
x2go-commits@lists.x2go.org
http://lists.x2go.org/listinfo/x2go-commits

Reply via email to