[X2Go-Commits] [x2goclient] 17/139: unixhelper.cpp: port from std::signal() to sigaction(). Handle errors.

git-admin at x2go.org git-admin at x2go.org
Wed Jan 13 18:41:27 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 1566ca541f674d8e4a926565a5617adc13d12f11
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Mon Mar 16 23:08:13 2015 +0100

    unixhelper.cpp: port from std::signal() to sigaction(). Handle errors.
---
 debian/changelog   |    1 +
 src/unixhelper.cpp |   33 ++++++++++++++++++++++++++-------
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 67b4348..f904e24 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -40,6 +40,7 @@ x2goclient (4.0.5.1-0x2go1) UNRELEASED; urgency=low
     - unixhelper.cpp: kill process group on error.
     - unixhelper.{cpp,h}: implement signal unblocking in
       unixhelper::unix_cleanup(). Update documentation.
+    - unixhelper.cpp: port from std::signal() to sigaction(). Handle errors.
   * debian/control:
     - Change apache2-dev | libc6-dev build dependency back to apache2-dev
       only. Otherwise, apache2-dev is not installed at all, even though
diff --git a/src/unixhelper.cpp b/src/unixhelper.cpp
index f2cc11c..fdcaac9 100644
--- a/src/unixhelper.cpp
+++ b/src/unixhelper.cpp
@@ -69,15 +69,34 @@ namespace unixhelper {
       /* Anything here shall be unreachable. */
     }
 
-    /* Set up signal handler to ignore SIGTERM. */
-    if (SIG_ERR == std::signal (SIGTERM, SIG_IGN)) {
-      std::cerr << "Unable to ignore SIGTERM: " << std::strerror (errno) << std::endl;
-      std::exit (1);
-
-      /* Anything here shall be unreachable. */
+    {
+      struct sigaction sig_action;
+      sig_action.sa_handler = SIG_IGN;
+      sig_action.sa_mask = empty_set;
+      sig_action.sa_flags = SA_RESTART;
+
+      /* Set up signal handler to ignore SIGTERM. */
+      if (0 != sigaction (SIGTERM, &sig_action, NULL)) {
+        std::cerr << "Unable to ignore SIGTERM: " << std::strerror (errno) << std::endl;
+        kill_pgroup (-1);
+
+        /* Anything here shall be unreachable. */
+      }
     }
 
-    std::signal (SIGHUP, kill_pgroup);
+    {
+      struct sigaction sig_action;
+      sig_action.sa_handler = kill_pgroup;
+      sig_action.sa_mask = empty_set;
+      sig_action.sa_flags = SA_RESTART;
+
+      if (0 != sigaction (SIGHUP, &sig_action, NULL)) {
+        std::cerr << "Unable to set up signal handler for SIGHUP: " << std::strerror (errno) << std::endl;
+        kill_pgroup (-1);
+
+        /* Anything here shall be unreachable. */
+      }
+    }
 
     /* Sleep forever... at least one second in each run. */
     for (;;) {

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