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

2016-09-20 Thread git-admin
This is an automated email from the git hooks/post-receive script.

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

commit f430fe7bc58d0405cba6cf983da687d0b1bdf1ce
Author: Mihai Moldovan 
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 4dd3eb8..5dbc0b2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -363,6 +363,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   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 
 #include 
 #include 
+#include 
+#include 
 
 /* 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


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

2016-08-27 Thread git-admin
This is an automated email from the git hooks/post-receive script.

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

commit 4330afe5fc1782dd61ac86e1f14636887d2bdff5
Author: Mihai Moldovan 
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 1edb449..ac2629b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -396,6 +396,8 @@ x2goclient (4.0.5.2-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 ().
   * debian/control:
 - Maintainer change in package: X2Go Developers .
 - Uploaders: add myself. Also, force a rebuild due to the changed
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 
 #include 
 #include 
+#include 
+#include 
 
 /* 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