in startProcess use _exit instead of exit after fork in child; test command with...
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 19 May 2014 13:14:43 +0000 (15:14 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 19 May 2014 13:14:43 +0000 (15:14 +0200)
asyncio/async_process.cpp
utils/asyncio_system_tools.cpp
utils/asyncio_system_tools.hpp

index 5169b5c..f93e320 100644 (file)
@@ -445,6 +445,14 @@ bool ProcessImplementation::startProcess( IOImplementation2 *stderr )
       // process still/already running...
       return false;
    }
+
+   Utils::FileStat stat(m_path);
+   if (! stat.is_exec_file())
+   {
+       // command to execute does not exist or is not executable
+       return false;
+   }
+
    m_exit_code= 0;
 
    if (stderr == _StderrOnStdout)
@@ -540,7 +548,7 @@ bool ProcessImplementation::startProcess( IOImplementation2 *stderr )
          if (r !=0 )
          {
             //TODO?
-            exit(255);
+            _exit(255);
          }
       }
 
@@ -568,9 +576,11 @@ bool ProcessImplementation::startProcess( IOImplementation2 *stderr )
       // execute:
       execv(m_path.c_str(), argv);
       // exit if exec failed
-      exit(255);
+      _exit(255);
       //cleanup! ... just joking; we exec or we exit, in either case the system cleans
       // everything which needs to be cleaned up.
+      // Using _exit instead of exit, it will not clean up the clone of parent's memory
+      //   in case of failure to exec m_path
    }
    return false; // keep the compiler happy...
 } // eo ProcessImplementation::startProcess()
index e505473..54bfd0e 100644 (file)
@@ -79,6 +79,7 @@ void FileStat::refresh()
     m_is_fifo= S_ISFIFO(file_stat->st_mode);
     m_is_symbolic_link= S_ISLNK(file_stat->st_mode);
     m_is_socket= S_ISSOCK(file_stat->st_mode);
+    m_is_exec_file = m_is_regular_file && (file_stat->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH));
     // TODO: implement more!
 } // end of FileStat::refresh()
 
index 0bc0e5f..4617add 100644 (file)
@@ -83,6 +83,7 @@ class FileStat
         bool is_symbolic_link() const { return m_is_symbolic_link; }
         bool is_link() const { return m_is_symbolic_link; }
         bool is_socket() const { return m_is_socket; }
+        bool is_exec_file() const { return m_is_exec_file; }
 
     private:
         std::string m_path;
@@ -99,6 +100,7 @@ class FileStat
         bool m_is_fifo              :1;
         bool m_is_symbolic_link     :1;
         bool m_is_socket            :1;
+        bool m_is_exec_file         :1;
 
 }; // end of FileStat