[X2Go-Commits] [x2goclient] 15/17: src/{unixhelper.cpp, x2goclient.cpp}: fix errno usage - save before use.

git-admin at x2go.org git-admin at x2go.org
Thu Sep 22 04:20:17 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 b5084f49c077d30e8643d9a6a5e0fdbbbbdb8d7c
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Sat Aug 13 23:42:53 2016 +0200

    src/{unixhelper.cpp,x2goclient.cpp}: fix errno usage - save before use.
---
 debian/changelog   |    1 +
 src/unixhelper.cpp |   18 ++++++++++++------
 src/x2goclient.cpp |    9 ++++++---
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 0a97c9a..5c39aaa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -371,6 +371,7 @@ x2goclient (4.0.5.3-0x2go1) UNRELEASED; urgency=medium
       process group are killed.
     - src/pulsemanager.cpp: remove unused variables.
     - src/unixhelper.cpp: code cleanup.
+    - src/{unixhelper.cpp,x2goclient.cpp}: fix errno usage - save before use.
 
  -- X2Go Release Manager <git-admin at x2go.org>  Mon, 19 Sep 2016 09:07:07 +0200
 
diff --git a/src/unixhelper.cpp b/src/unixhelper.cpp
index d6b4993..406cdda 100644
--- a/src/unixhelper.cpp
+++ b/src/unixhelper.cpp
@@ -79,7 +79,8 @@ namespace unixhelper {
   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;
+      const int saved_errno = errno;
+      std::cerr << "WARNING: unable to send SIGTERM to process group '" << pgid << "': " << std::strerror (saved_errno) << std::endl;
     }
 
     /* Grant a grace period of (at least) 10 seconds. */
@@ -95,7 +96,8 @@ namespace unixhelper {
      * Let's handle errors and exit, if necessary.
      */
     if (0 != kill_ret) {
-      std::cerr << "WARNING: failed to kill process group '" << pgid << "': " << std::strerror (err_str) << std::endl;
+      const int saved_errno = errno;
+      std::cerr << "WARNING: failed to kill process group '" << pgid << "': " << std::strerror (saved_errno) << std::endl;
     }
 
     std::exit (EXIT_SUCCESS);
@@ -108,14 +110,16 @@ namespace unixhelper {
      */
     sigset_t empty_set;
     if (0 != sigemptyset (&empty_set)) {
-      std::cerr << "Unable to fetch empty signal set: " << std::strerror (errno) << std::endl;
+      const int saved_errno = errno;
+      std::cerr << "Unable to fetch empty signal set: " << std::strerror (saved_errno) << std::endl;
       kill_pgroup (-1);
 
       /* Anything here shall be unreachable. */
     }
 
     if (0 != sigprocmask (SIG_SETMASK, &empty_set, NULL)) {
-      std::cerr << "Unable to set empty signal set: " << std::strerror (errno) << std::endl;
+      const int saved_errno = errno;
+      std::cerr << "Unable to set empty signal set: " << std::strerror (saved_errno) << std::endl;
       kill_pgroup (-1);
 
       /* Anything here shall be unreachable. */
@@ -137,7 +141,8 @@ namespace unixhelper {
 
       /* Set up signal handler to ignore the current signal. */
       if (0 != sigaction (*it, &sig_action, NULL)) {
-        std::cerr << "Unable to ignore signal " << strsignal (*it) << ": " << std::strerror (errno) << std::endl;
+        const int saved_errno = errno;
+        std::cerr << "Unable to ignore signal " << strsignal (*it) << ": " << std::strerror (saved_errno) << std::endl;
         kill_pgroup (-1);
 
         /* Anything here shall be unreachable. */
@@ -151,7 +156,8 @@ namespace unixhelper {
       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;
+        const int saved_errno = errno;
+        std::cerr << "Unable to set up signal handler for SIGHUP: " << std::strerror (saved_errno) << std::endl;
         kill_pgroup (-1);
 
         /* Anything here shall be unreachable. */
diff --git a/src/x2goclient.cpp b/src/x2goclient.cpp
index b201a4e..431a01e 100644
--- a/src/x2goclient.cpp
+++ b/src/x2goclient.cpp
@@ -58,13 +58,15 @@ int fork_helper (int argc, char **argv) {
     new_argv_c_str->push_back (0);
 
     if (0 != execv (new_argv_c_str->front (), &(new_argv_c_str->front ()))) {
-      std::cerr << "Failed to re-execute process as UNIX cleanup helper tool: " << std::strerror (errno) << "\n"
+      const int saved_errno = errno;
+      std::cerr << "Failed to re-execute process as UNIX cleanup helper tool: " << std::strerror (saved_errno) << "\n"
                 << "Terminating and killing parent." << "\n"
                 << "Please report a bug, refer to this documentation: http://wiki.x2go.org/doku.php/wiki:bugs" << std::endl;
 
       pid_t parent_pid = getppid ();
       if (0 != kill (parent_pid, SIGTERM)) {
-        std::cerr << "Failed to kill parent process: " << std::strerror (errno) << std::endl;
+        const int saved_errno = errno;
+        std::cerr << "Failed to kill parent process: " << std::strerror (saved_errno) << std::endl;
       }
 
       std::exit (EXIT_FAILURE);
@@ -75,7 +77,8 @@ int fork_helper (int argc, char **argv) {
   }
   /* Error. */
   else if (-1 == tmp_pid) {
-    std::cerr << "Unable to create a new process for the UNIX cleanup watchdog: " << std::strerror (errno) << "\n";
+    const int saved_errno = errno;
+    std::cerr << "Unable to create a new process for the UNIX cleanup watchdog: " << std::strerror (saved_errno) << "\n";
     std::cerr << "Terminating. Please report a bug, refer to this documentation: http://wiki.x2go.org/doku.php/wiki:bugs" << std::endl;
 
     std::exit (EXIT_FAILURE);

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