[X2Go-Commits] [x2goclient] 05/05: src/unixhelper.{cpp, h}: rewrite kill_pgroup () to act as a wrapper around real_kill_pgroup ().
git-admin at x2go.org
git-admin at x2go.org
Fri Aug 12 09:23:38 CEST 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 15461fd32410691fe12682e45aed5a014f715ae7
Author: Mihai Moldovan <ionic at ionic.de>
Date: Fri Aug 12 09:11:16 2016 +0200
src/unixhelper.{cpp,h}: rewrite kill_pgroup () to act as a wrapper around real_kill_pgroup ().
Adjust comment.
We need to do this so the cleanup process doesn't kill itself before all
other processes in the process group are killed.
---
debian/changelog | 4 ++++
src/unixhelper.cpp | 38 ++++++++++++++++++++++++++++++++++++++
src/unixhelper.h | 12 ++++++------
3 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 8e12b42..f3bcfff 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -396,6 +396,10 @@ x2goclient (4.0.5.2-0x2go1) UNRELEASED; urgency=medium
- 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 ().
+ - src/unixhelper.{cpp,h}: rewrite kill_pgroup () to act as a wrapper
+ around real_kill_pgroup (). Adjust comment. We need to do this so the
+ cleanup process doesn't kill itself before all other processes in the
+ process group are killed.
* debian/control:
- Maintainer change in package: X2Go Developers <x2go-dev at lists.x2go.org>.
- Uploaders: add myself. Also, force a rebuild due to the changed
diff --git a/src/unixhelper.cpp b/src/unixhelper.cpp
index 4d9c56f..82e4374 100644
--- a/src/unixhelper.cpp
+++ b/src/unixhelper.cpp
@@ -37,6 +37,44 @@
namespace unixhelper {
void kill_pgroup (const int signal) {
+ pid_t pgid_to_kill = getpgrp ();
+
+ if ((SIGHUP == signal) || (-1 == signal)) {
+ /*
+ * In order to not kill ourselves, we need to run this
+ * code in a new process group.
+ */
+ pid_t tmp_pid = fork ();
+
+ /* Child. */
+ if (0 == tmp_pid) {
+ /* Create new pgid. */
+ int err = setpgid (0, 0);
+
+ if (0 != err) {
+ std::perror ("WARNING: unable to change PGID");
+ std::cerr << "Continuing with normal operation, but process might kill itself before tree vanishes." << std::endl;
+ }
+
+ real_kill_pgroup (pgid_to_kill);
+ }
+ /* Error. */
+ else if (-1 == tmp_pid) {
+ perror ("WARNING: unable to fork off another process to kill original process group");
+ std::cerr << "Proceeding with normal operation, but process might kill itself before tree vanishes." << std::endl;
+
+ real_kill_pgroup (pgid_to_kill);
+ }
+ /* Parent. */
+ else {
+ /*
+ * No need to do anything, just exit here in order to not
+ * spawn a bunch of new processes due to subsequent calls
+ * to kill_pgroup () from unix_cleanup ().
+ */
+ exit (EXIT_SUCCESS);
+ }
+ }
}
void real_kill_pgroup (const pid_t pgid) {
diff --git a/src/unixhelper.h b/src/unixhelper.h
index 662b3be..7d30bcf 100644
--- a/src/unixhelper.h
+++ b/src/unixhelper.h
@@ -47,12 +47,12 @@ namespace unixhelper {
int unix_cleanup (const pid_t parent);
/*
- * 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.
+ * Wrapper for killing a whole process group.
+ * The "real" killing work is done by real_kill_pgroup ().
+ * This function tries to fork off another process and change
+ * the new function's process group ID.
+ * If any of these operations fail, killing the original process
+ * group ID will still continue, albeit with warning messages.
*
* signal may be any of:
* * -1 to indicate an error leading to emergency termination
--
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