From f8f95d47c51704dd0249bbae140e0b83f48c7e8e Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 4 Aug 2012 18:39:03 +0200 Subject: [PATCH] Added: #1440 A proper way to run child processes --HG-- branch : build_pipeline_v3 --- .../service/pipeline_process_impl.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/code/nel/tools/pipeline/service/pipeline_process_impl.cpp b/code/nel/tools/pipeline/service/pipeline_process_impl.cpp index 95824e101..b6480fe60 100644 --- a/code/nel/tools/pipeline/service/pipeline_process_impl.cpp +++ b/code/nel/tools/pipeline/service/pipeline_process_impl.cpp @@ -30,6 +30,9 @@ // STL includes #include +#ifndef NL_OS_WINDOWS +# include +#endif // NeL includes #include @@ -177,12 +180,32 @@ void CPipelineProcessImpl::makePaths(const std::vector &outputPaths void CPipelineProcessImpl::runConsoleTool(const std::string &executablePath, const std::vector &arguments) { +#ifdef NL_OS_WINDOWS // FIXME: NOT SAFE FOR ARGUMENTS WITH SPACES std::stringstream ss; ss << executablePath; for (std::vector::const_iterator it = arguments.begin(), end = arguments.end(); it != end; ++it) ss << " " << *it; system(ss.str().c_str()); +#else + pid_t fork_id = fork(); + if (fork_id) + { + int exitCode; + while (wait(&exitCode) != fork_id) { /* ... */ } + } + else + { + std::vector argv; + argv.reserve(arguments.size() + 1); + argv.push_back(const_cast(executablePath.c_str())); + for (std::vector::const_iterator it = arguments.begin(), end = arguments.end(); it != end; ++it) + argv.push_back(const_cast((*it).c_str())); + argv.push_back(NULL); + execv(argv[0], &argv[0]); + exit(1); // failure + } +#endif } } /* namespace PIPELINE */