[X2Go-Commits] [x2goclient] 213/276: src/unixhelper.{cpp, h}: split off core functionality of kill_pgroup () into a new function called real_kill_pgroup ().

git-admin at x2go.org git-admin at x2go.org
Sat Dec 31 01:35:26 CET 2016


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

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

commit e40b7820660070e1db8c7423ebf108c0d8bbb032
Author: Mihai Moldovan <ionic at 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 4489615..b60b7e2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -373,6 +373,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 ().
 
   [ Bernard Cafarelli ]
   * New upstream version (4.0.5.3):
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


More information about the x2go-commits mailing list