Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63822 - sandbox/SOC/2010/process/boost/process
From: fotanus_at_[hidden]
Date: 2010-07-10 15:13:31


Author: fotanus
Date: 2010-07-10 15:13:30 EDT (Sat, 10 Jul 2010)
New Revision: 63822
URL: http://svn.boost.org/trac/boost/changeset/63822

Log:
Changed the way that childs are created on POSIX.

Text files modified:
   sandbox/SOC/2010/process/boost/process/operations.hpp | 47 +++++++++++++++++++++++++++++++++++++--
   1 files changed, 44 insertions(+), 3 deletions(-)

Modified: sandbox/SOC/2010/process/boost/process/operations.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/operations.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/operations.hpp 2010-07-10 15:13:30 EDT (Sat, 10 Jul 2010)
@@ -187,9 +187,50 @@
 
     if (pid == 0)
     {
- dup2(ctx.stdin_behavior->get_child_end(),STDIN_FILENO);
- dup2(ctx.stdout_behavior->get_child_end(),STDOUT_FILENO);
- dup2(ctx.stderr_behavior->get_child_end(),STDERR_FILENO);
+#if defined(F_MAXFD)
+ int maxdescs = ::fcntl(-1, F_MAXFD, 0);
+ if (maxdescs == -1)
+ maxdescs = ::sysconf(_SC_OPEN_MAX);
+#else
+ int maxdescs = ::sysconf(_SC_OPEN_MAX);
+#endif
+ if (maxdescs == -1)
+ maxdescs = 1024;
+ try
+ {
+ boost::scoped_array<bool> closeflags(new bool[maxdescs]);
+ for (int i = 0; i < maxdescs; ++i)
+ closeflags[i] = true;
+
+ // setup_input(infoin, closeflags.get(), maxdescs);
+ // setup_output(infoout, closeflags.get(), maxdescs);
+
+ int stdin_fd = ctx.stdin_behavior->get_child_end();
+ if (stdin_fd != -1 && stdin_fd < maxdescs)
+ closeflags[stdin_fd] = false;
+
+ int stdout_fd = ctx.stdout_behavior->get_child_end();
+ if (stdout_fd != -1 && stdout_fd < maxdescs)
+ closeflags[stdout_fd] = false;
+
+ int stderr_fd = ctx.stderr_behavior->get_child_end();
+ if (stderr_fd != -1 && stderr_fd < maxdescs)
+ closeflags[stderr_fd] = false;
+
+ for (int i = 0; i < maxdescs; ++i)
+ {
+ if (closeflags[i])
+ ::close(i);
+ }
+
+ // setup();
+ }
+ catch (const boost::system::system_error &e)
+ {
+ ::write(STDERR_FILENO, e.what(), std::strlen(e.what()));
+ ::write(STDERR_FILENO, "\n", 1);
+ std::exit(EXIT_FAILURE);
+ }
 
         std::pair<std::size_t, char**> argcv = detail::collection_to_posix_argv(args);
         char **envp = detail::environment_to_envp(ctx.environment);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk