This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch bugfix/osx in repository x2goclient.
commit b4c4fe81d94546505cf324d5e1d78f5386f9136f Author: Mihai Moldovan <io...@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 c4c8c40..759e4d1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -369,6 +369,10 @@ x2goclient (4.0.5.3-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. -- 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 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 _______________________________________________ x2go-commits mailing list x2go-commits@lists.x2go.org http://lists.x2go.org/listinfo/x2go-commits