From: Christian Herdtweck Date: Mon, 19 May 2014 13:14:43 +0000 (+0200) Subject: in startProcess use _exit instead of exit after fork in child; test command with... X-Git-Tag: v0.3~9 X-Git-Url: http://developer.intra2net.com/git/?p=libasyncio;a=commitdiff_plain;h=c3b830a20207a249874d15fdc0744a923187a88a in startProcess use _exit instead of exit after fork in child; test command with new FileStat::is_exec_file in asyncio/utils --- diff --git a/asyncio/async_process.cpp b/asyncio/async_process.cpp index 5169b5c..f93e320 100644 --- a/asyncio/async_process.cpp +++ b/asyncio/async_process.cpp @@ -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() diff --git a/utils/asyncio_system_tools.cpp b/utils/asyncio_system_tools.cpp index e505473..54bfd0e 100644 --- a/utils/asyncio_system_tools.cpp +++ b/utils/asyncio_system_tools.cpp @@ -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() diff --git a/utils/asyncio_system_tools.hpp b/utils/asyncio_system_tools.hpp index 0bc0e5f..4617add 100644 --- a/utils/asyncio_system_tools.hpp +++ b/utils/asyncio_system_tools.hpp @@ -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