[X2Go-Commits] [x2goclient] 02/217: unixhelper.{cpp, h}: implement cleanup program for process group.

git-admin at x2go.org git-admin at x2go.org
Sat Aug 27 19:24:11 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 dd90512815fc258a87b9264ccd3a71ee3be75875
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Sat Mar 14 23:57:49 2015 +0100

    unixhelper.{cpp,h}: implement cleanup program for process group.
---
 debian/changelog   |    1 +
 src/unixhelper.cpp |   38 ++++++++++++++++++++++++++++++++++++++
 src/unixhelper.h   |    9 +++++++++
 3 files changed, 48 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 0ca4d0a..e595125 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -39,6 +39,7 @@ x2goclient (4.0.5.2-0x2go1) UNRELEASED; urgency=medium
     - src/onmainwindow.cpp: work around changed SSH host key locations in OS X
       10.11+. Fixes: #1079. Also check /etc/ssh/ for keys.
     - {unixhelper.{cpp,h},x2goclient.pro{,.maemo}}: add unixhelper stub.
+    - unixhelper.{cpp,h}: implement cleanup program for process group.
   * 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 221bdb2..545c2c1 100644
--- a/src/unixhelper.cpp
+++ b/src/unixhelper.cpp
@@ -19,5 +19,43 @@
 
 #ifdef Q_OS_UNIX
 
+#include <csignal>
+#include <unistd.h>
+#include <iostream>
+#include <cstring>
+#include <cerrno>
+#include <cstdlib>
+
+#include "unixhelper.h"
+
+void unixhelper::kill_pgroup (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;
+    }
+
+    /* Grant a grace period of (at least) 5 seconds. */
+    sleep (5);
+
+    /* Don't handle any errors here, because we die anyway. */
+    killpg (getpgrp (), SIGKILL);
+  }
+}
+
+
+int unixhelper::unix_cleanup () {
+  if (SIG_ERR == std::signal (SIGTERM, SIG_IGN)) {
+    std::cerr << "Unable to ignore SIGTERM: " << std::strerror (errno) << std::endl;
+    std::exit (1);
+  }
+
+  std::signal (SIGHUP, kill_pgroup);
+
+  /* Sleep forever... at least one second in each run. */
+  for (;;) {
+    sleep (1);
+  }
+}
 
 #endif /* defined (Q_OS_UNIX) */
diff --git a/src/unixhelper.h b/src/unixhelper.h
index 31d983e..fab611e 100644
--- a/src/unixhelper.h
+++ b/src/unixhelper.h
@@ -22,7 +22,16 @@
 #ifndef UNIXHELPER_H
 #define UNIXHELPER_H
 
+class unixhelper {
+  public:
+    unixhelper () {}
+    ~unixhelper () {}
+    unix_cleanup ();
 
+  private:
+    unixhelper (const unixhelper &other);
+    void kill_pgroup (int signal);
+};
 
 #endif /* !defined (UNIXHELPER_H) */
 

--
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