|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62157 - in sandbox/SOC/2010/process/boost/process: . detail
From: fotanus_at_[hidden]
Date: 2010-05-22 17:20:23
Author: fotanus
Date: 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
New Revision: 62157
URL: http://svn.boost.org/trac/boost/changeset/62157
Log:
The pipes are now working correctly on POSIX.
Removed:
sandbox/SOC/2010/process/boost/process/detail/posix_ops.hpp
Text files modified:
sandbox/SOC/2010/process/boost/process/child.hpp | 4 +-
sandbox/SOC/2010/process/boost/process/detail/file_handle.hpp | 9 ++++-
sandbox/SOC/2010/process/boost/process/detail/pipe.hpp | 2
sandbox/SOC/2010/process/boost/process/detail/posix_helpers.hpp | 22 +++++++++------
sandbox/SOC/2010/process/boost/process/detail/stream_detail.hpp | 33 +++++++++++++---------
sandbox/SOC/2010/process/boost/process/detail/systembuf.hpp | 2
sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp | 2
sandbox/SOC/2010/process/boost/process/operations.hpp | 57 ++++++++++++++++++++++++++++-----------
sandbox/SOC/2010/process/boost/process/status.hpp | 2
9 files changed, 85 insertions(+), 48 deletions(-)
Modified: sandbox/SOC/2010/process/boost/process/child.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/child.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/child.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -17,7 +17,7 @@
#ifndef BOOST_PROCESS_CHILD_HPP
#define BOOST_PROCESS_CHILD_HPP
-
+#include <iostream>
#include <boost/process/config.hpp>
#if defined(BOOST_POSIX_API)
@@ -109,7 +109,7 @@
* It is only used on Windows as the implementation of wait() needs a
* process handle.
*/
- child(id_type id, detail::file_handle fhstdin, detail::file_handle fhstdout, detail::file_handle fhstderr, detail::file_handle fhprocess = detail::file_handle())
+ child(id_type id, detail::file_handle &fhstdin, detail::file_handle &fhstdout, detail::file_handle &fhstderr, detail::file_handle fhprocess = detail::file_handle())
: process(id)
#if defined(BOOST_WINDOWS_API)
, process_handle_(fhprocess.release(), ::CloseHandle)
Modified: sandbox/SOC/2010/process/boost/process/detail/file_handle.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/file_handle.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/file_handle.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -243,18 +243,23 @@
* \throw boost::system::system_error If the internal remapping
* operation fails.
*/
- void posix_remap(handle_type h){
+ void posix_remap(handle_type &h){
BOOST_ASSERT(valid());
+ /*
if (::dup2(handle_, h) == -1)
boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::file_handle::posix_remap: dup2(2) failed"));
if (::close(handle_) == -1){
::close(h);
boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::file_handle::posix_remap: close(2) failed"));
- }
+ } */
+ if( ::dup2(handle_,h) == -1 ){
+ boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::file_handle::posix_remap: dup2(2) failed"));
+
+ }
handle_ = h;
}
Modified: sandbox/SOC/2010/process/boost/process/detail/pipe.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/pipe.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/pipe.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -82,7 +82,7 @@
file_handle::handle_type hs[2];
#if defined(BOOST_POSIX_API)
- if (::pipe(hs) == -1)
+ if (::pipe(hs) == -1)
boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::pipe::pipe: pipe(2) failed"));
#elif defined(BOOST_WINDOWS_API)
SECURITY_ATTRIBUTES sa;
Modified: sandbox/SOC/2010/process/boost/process/detail/posix_helpers.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/posix_helpers.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/posix_helpers.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -23,6 +23,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
+ #include <stdio.h>
#endif
#include <map>
#include <string.h>
@@ -36,7 +37,8 @@
namespace boost{
namespace process{
namespace detail{
-
+
+
/*
* This is the declaration of configure_stream function.
@@ -46,7 +48,7 @@
* Note that this function is meant to be called on a brand-new child.
*
*/
-inline configure_posix_stream(stream_detail &s){
+inline configure_child_posix_stream(stream_detail &s){
switch(s.behavior){
case dummy:{
@@ -67,14 +69,16 @@
boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::setup_input: open(2) of " + s.object.file_ + " failed"));
s.object.handle_ = file_handle(fd);
- s.object.handle_.posix_remap(s.stream_handler);
+ s.object.handle_.posix_remap(s.stream_handle);
s.object.handle_.release();
break;
}
case closed:
- //?
+ #if defined(BOOST_POSIX_API)
+ ::close(s.stream_handle);
+ #endif
break;
case inherit:
@@ -82,15 +86,15 @@
break;
case capture:
- s.object.pipe_ = pipe();
if(s.stream_type == stdin_type){
- s.object.pipe_->wend().close();
- s.object.pipe_->rend().posix_remap(s.stream_handler);
+ s.object.pipe_.wend().close();
+ s.object.pipe_.rend().posix_remap(s.stream_handle);
}
else{
- s.object.pipe_->rend().close();
- s.object.pipe_->wend().posix_remap(s.stream_handler);
+ s.object.pipe_.rend().close();
+ s.object.pipe_.wend().posix_remap(s.stream_handle);
}
+
break;
default:
Deleted: sandbox/SOC/2010/process/boost/process/detail/posix_ops.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/posix_ops.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
+++ (empty file)
@@ -1,495 +0,0 @@
-//
-// Boost.Process
-// ~~~~~~~~~~~~~
-//
-// Copyright (c) 2006, 2007 Julio M. Merino Vidal
-// Copyright (c) 2008, 2009 Boris Schaeling
-//
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-/**
- * \file boost/process/detail/posix_ops.hpp
- *
- * Provides some convenience functions to start processes under POSIX
- * operating systems.
- */
-
-#ifndef BOOST_PROCESS_DETAIL_POSIX_OPS_HPP
-#define BOOST_PROCESS_DETAIL_POSIX_OPS_HPP
-
-#include <boost/process/environment.hpp>
-#include <boost/process/detail/file_handle.hpp>
-#include <boost/process/detail/pipe.hpp>
-#include <boost/process/detail/stream_info.hpp>
-#include <boost/scoped_array.hpp>
-#include <boost/assert.hpp>
-#include <boost/system/system_error.hpp>
-#include <boost/throw_exception.hpp>
-#include <map>
-#include <utility>
-#include <string>
-#include <cerrno>
-#include <cstdlib>
-#include <cstring>
-#include <fcntl.h>
-#include <unistd.h>
-
-namespace boost {
-namespace process {
-namespace detail {
-
-/**
- * Converts the command line to an array of C strings.
- *
- * Converts the command line's list of arguments to the format expected
- * by the \a argv parameter in the POSIX execve() system call.
- *
- * This operation is only available on POSIX systems.
- *
- * \return The first argument of the pair is an integer that indicates
- * how many strings are stored in the second argument. The
- * second argument is a NULL-terminated, dynamically allocated
- * array of dynamically allocated strings holding the arguments
- * to the executable. The caller is responsible of freeing them.
- */
-template <class Arguments>
-inline std::pair<std::size_t, char**> collection_to_posix_argv(const Arguments &args)
-{
- std::size_t nargs = args.size();
- BOOST_ASSERT(nargs > 0);
-
- char **argv = new char*[nargs + 1];
- typename Arguments::size_type i = 0;
- for (typename Arguments::const_iterator it = args.begin(); it != args.end(); ++it)
- {
- argv[i] = new char[it->size() + 1];
- std::strncpy(argv[i], it->c_str(), it->size() + 1);
- ++i;
- }
- argv[nargs] = 0;
-
- return std::pair<std::size_t, char**>(nargs, argv);
-}
-
-/**
- * Converts an environment to a char** table as used by execve().
- *
- * Converts the environment's contents to the format used by the
- * execve() system call. The returned char** array is allocated
- * in dynamic memory; the caller must free it when not used any
- * more. Each entry is also allocated in dynamic memory and is a
- * NULL-terminated string of the form var=value; these must also be
- * released by the caller.
- *
- * \return A dynamically allocated char** array that represents
- * the environment's content. Each array entry is a
- * NULL-terminated string of the form var=value.
- */
-inline char **environment_to_envp(const environment &env)
-{
- char **envp = new char*[env.size() + 1];
-
- environment::size_type i = 0;
- for (environment::const_iterator it = env.begin(); it != env.end(); ++it)
- {
- std::string s = it->first + "=" + it->second;
- envp[i] = new char[s.size() + 1];
- std::strncpy(envp[i], s.c_str(), s.size() + 1);
- ++i;
- }
- envp[i] = 0;
-
- return envp;
-}
-
-/**
- * Holds a mapping between native file descriptors and their corresponding
- * pipes to set up communication between the parent and the %child process.
- */
-typedef std::map<int, stream_info> info_map;
-
-/**
- * Helper class to configure a POSIX %child.
- *
- * This helper class is used to hold all the attributes that configure a
- * new POSIX %child process and to centralize all the actions needed to
- * make them effective.
- *
- * All its fields are public for simplicity. It is only intended for
- * internal use and it is heavily coupled with the Context
- * implementations.
- */
-struct posix_setup
-{
- /**
- * The work directory.
- *
- * This string specifies the directory in which the %child process
- * starts execution. It cannot be empty.
- */
- std::string work_directory;
-
- /**
- * The chroot directory, if any.
- *
- * Specifies the directory in which the %child process is chrooted
- * before execution. Empty if this feature is not desired.
- */
- std::string chroot;
-
- /**
- * The user credentials.
- *
- * UID that specifies the user credentials to use to run the %child
- * process. Defaults to the current UID.
- */
- uid_t uid;
-
- /**
- * The effective user credentials.
- *
- * EUID that specifies the effective user credentials to use to run
- * the %child process. Defaults to the current EUID.
- */
- uid_t euid;
-
- /**
- * The group credentials.
- *
- * GID that specifies the group credentials to use to run the %child
- * process. Defaults to the current GID.
- */
- gid_t gid;
-
- /**
- * The effective group credentials.
- *
- * EGID that specifies the effective group credentials to use to run
- * the %child process. Defaults to the current EGID.
- */
- gid_t egid;
-
- /**
- * Creates a new properties set.
- *
- * Creates a new object that has sensible default values for all the
- * properties.
- */
- posix_setup()
- : uid(::getuid()),
- euid(::geteuid()),
- gid(::getgid()),
- egid(::getegid())
- {
- }
-
- /**
- * Sets up the execution environment.
- *
- * Modifies the current execution environment (that of the %child) so
- * that the properties become effective.
- *
- * \throw boost::system::system_error If any error ocurred during
- * environment configuration. The child process should abort
- * execution if this happens because its start conditions
- * cannot be met.
- */
- void operator()() const
- {
- if (!chroot.empty() && ::chroot(chroot.c_str()) == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_setup: chroot(2) failed"));
-
- if (gid != ::getgid() && ::setgid(gid) == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_setup: setgid(2) failed"));
-
- if (egid != ::getegid() && ::setegid(egid) == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_setup: setegid(2) failed"));
-
- if (uid != ::getuid() && ::setuid(uid) == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_setup: setuid(2) failed"));
-
- if (euid != ::geteuid() && ::seteuid(euid) == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_setup: seteuid(2) failed"));
-
- BOOST_ASSERT(!work_directory.empty());
- if (::chdir(work_directory.c_str()) == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_setup: chdir(2) failed"));
- }
-};
-
-/**
- * Configures child process' input streams.
- *
- * Sets up the current process' input streams to behave according to the
- * information in the \a info map. \a closeflags is modified to reflect
- * those descriptors that should not be closed because they where modified
- * by the function.
- *
- * Modifies the current execution environment, so this should only be run
- * on the child process after the fork(2) has happened.
- *
- * \throw boost::system::system_error If any error occurs during the
- * configuration.
- */
-inline void setup_input(info_map &info, bool *closeflags, int maxdescs)
-{
- for (info_map::iterator it = info.begin(); it != info.end(); ++it)
- {
- int d = it->first;
- stream_info &si = it->second;
-
- BOOST_ASSERT(d < maxdescs);
- closeflags[d] = false;
-
- switch (si.type_)
- {
- case stream_info::use_file:
- {
- int fd = ::open(si.file_.c_str(), O_RDONLY);
- if (fd == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::setup_input: open(2) of " + si.file_ + " failed"));
- if (fd != d)
- {
- file_handle h(fd);
- h.posix_remap(d);
- h.release();
- }
- break;
- }
- case stream_info::use_handle:
- {
- if (si.handle_.get() != d)
- si.handle_.posix_remap(d);
- break;
- }
- case stream_info::use_pipe:
- {
- si.pipe_->wend().close();
- if (d != si.pipe_->rend().get())
- si.pipe_->rend().posix_remap(d);
- break;
- }
- default:
- {
- BOOST_ASSERT(si.type_ == stream_info::inherit);
- break;
- }
- }
- }
-}
-
-/**
- * Configures child process' output streams.
- *
- * Sets up the current process' output streams to behave according to the
- * information in the \a info map. \a closeflags is modified to reflect
- * those descriptors that should not be closed because they where
- * modified by the function.
- *
- * Modifies the current execution environment, so this should only be run
- * on the child process after the fork(2) has happened.
- *
- * \throw boost::system::system_error If any error occurs during the
- * configuration.
- */
-inline void setup_output(info_map &info, bool *closeflags, int maxdescs)
-{
- for (info_map::iterator it = info.begin(); it != info.end(); ++it)
- {
- int d = it->first;
- stream_info &si = it->second;
-
- BOOST_ASSERT(d < maxdescs);
- closeflags[d] = false;
-
- switch (si.type_)
- {
- case stream_info::redirect:
- {
- break;
- }
- case stream_info::use_file:
- {
- int fd = ::open(si.file_.c_str(), O_WRONLY);
- if (fd == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::setup_output: open(2) of " + si.file_ + " failed"));
- if (fd != d)
- {
- file_handle h(fd);
- h.posix_remap(d);
- h.release();
- }
- break;
- }
- case stream_info::use_handle:
- {
- if (si.handle_.get() != d)
- si.handle_.posix_remap(d);
- break;
- }
- case stream_info::use_pipe:
- {
- si.pipe_->rend().close();
- if (d != si.pipe_->wend().get())
- si.pipe_->wend().posix_remap(d);
- break;
- }
- default:
- {
- BOOST_ASSERT(si.type_ == stream_info::inherit);
- break;
- }
- }
- }
-
- for (info_map::const_iterator it = info.begin(); it != info.end(); ++it)
- {
- int d = it->first;
- const stream_info &si = it->second;
-
- if (si.type_ == stream_info::redirect)
- file_handle::posix_dup(si.desc_to_, d).release();
- }
-}
-
-/**
- * Starts a new child process in a POSIX operating system.
- *
- * This helper functions is provided to simplify the Context's task when
- * it comes to starting up a new process in a POSIX operating system.
- * The function hides all the details of the fork/exec pair of calls as
- * well as all the setup of communication pipes and execution environment.
- *
- * \param exe The executable to spawn the child process.
- * \param args The arguments for the executable.
- * \param env The environment variables that the new child process
- * receives.
- * \param infoin A map describing all input file descriptors to be
- * redirected.
- * \param infoout A map describing all output file descriptors to be
- * redirected.
- * \param setup A helper object used to configure the child's execution
- * environment.
- * \return The new process' PID. The caller is responsible of creating
- * an appropriate Child representation for it.
- */
-template <class Executable, class Arguments>
-inline pid_t posix_start(const Executable &exe, const Arguments &args, const environment &env, info_map &infoin, info_map &infoout, const posix_setup &setup)
-{
- pid_t pid = ::fork();
- if (pid == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_start: fork(2) failed"));
- else if (pid == 0)
- {
-#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);
-
- 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 = collection_to_posix_argv(args);
- char **envp = environment_to_envp(env);
-
- ::execve(exe.c_str(), argcv.second, envp);
- boost::system::system_error e(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_start: execve(2) failed");
-
- for (std::size_t i = 0; i < argcv.first; ++i)
- delete[] argcv.second[i];
- delete[] argcv.second;
-
- for (std::size_t i = 0; i < env.size(); ++i)
- delete[] envp[i];
- delete[] envp;
-
- ::write(STDERR_FILENO, e.what(), std::strlen(e.what()));
- ::write(STDERR_FILENO, "\n", 1);
- std::exit(EXIT_FAILURE);
- }
-
- BOOST_ASSERT(pid > 0);
-
- for (info_map::iterator it = infoin.begin(); it != infoin.end(); ++it)
- {
- stream_info &si = it->second;
- if (si.type_ == stream_info::use_pipe)
- si.pipe_->rend().close();
- }
-
- for (info_map::iterator it = infoout.begin(); it != infoout.end(); ++it)
- {
- stream_info &si = it->second;
- if (si.type_ == stream_info::use_pipe)
- si.pipe_->wend().close();
- }
-
- return pid;
-}
-
-/**
- * Locates a communication pipe and returns one of its endpoints.
- *
- * Given a \a info map, and a file descriptor \a desc, searches for its
- * communicataion pipe in the map and returns one of its endpoints as
- * indicated by the \a out flag. This is intended to be used by a
- * parent process after a fork(2) call.
- *
- * \pre If the info map contains the given descriptor, it is configured
- * to use a pipe.
- * \post The info map does not contain the given descriptor.
- * \return If the file descriptor is found in the map, returns the pipe's
- * read end if out is true; otherwise its write end. If the
- * descriptor is not found returns an invalid file handle.
- */
-inline file_handle posix_info_locate_pipe(info_map &info, int desc, bool out)
-{
- file_handle fh;
-
- info_map::iterator it = info.find(desc);
- if (it != info.end())
- {
- stream_info &si = it->second;
- if (si.type_ == stream_info::use_pipe)
- {
- fh = out ? si.pipe_->rend().release() : si.pipe_->wend().release();
- BOOST_ASSERT(fh.valid());
- }
- info.erase(it);
- }
-
- return fh;
-}
-
-}
-}
-}
-
-#endif
Modified: sandbox/SOC/2010/process/boost/process/detail/stream_detail.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/stream_detail.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/stream_detail.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -22,6 +22,7 @@
#include <map>
#include <boost/optional.hpp>
#include <boost/process/stream_behavior.hpp>
+#include <boost/process/detail/file_handle.hpp>
#include <boost/process/detail/pipe.hpp>
@@ -44,7 +45,7 @@
int desc_to;
std::string file_;
file_handle handle_;
- boost::optional<pipe> pipe_;
+ pipe pipe_;
};
@@ -52,7 +53,7 @@
* This defines the std_stream_type enum.
* It lists all possible std stream types.
*/
-enum std_stream_type {stdin_type, stdout_type, stderr_type};
+enum std_stream_type {stdin_type=0, stdout_type=1, stderr_type=2};
/*
@@ -69,39 +70,43 @@
*/
struct stream_detail {
- int stream_handler;
+ detail::file_handle::handle_type stream_handle;
struct stream_object object;
std_stream_type stream_type;
stream_behavior behavior;
stream_detail(std_stream_type st){
+ stream_type = st;
+ object.pipe_ = pipe();
switch(st){
case stdin_type:{
- stream_type = st;
#if defined(BOOST_POSIX_API)
- stream_handler = STDIN_FILENO;
+ stream_handle = STDIN_FILENO;
#elif defined(BOOST_WINDOWS_API)
- stream_handler = STD_INPUT_HANDLE;
+ stream_handle = STD_INPUT_HANDLE;
#endif
+ break;
}
case stdout_type:{
- stream_type = st;
-
#if defined(BOOST_POSIX_API)
- stream_handler = STDOUT_FILENO;
+ stream_handle = STDOUT_FILENO;
#elif defined(BOOST_WINDOWS_API)
- stream_handler = STD_OUTPUT_HANDLE;
+ stream_handle = STD_OUTPUT_HANDLE;
#endif
+ break;
}
case stderr_type:{
- stream_type = st;
-
#if defined(BOOST_POSIX_API)
- stream_handler = STDERR_FILENO;
+ stream_handle = STDERR_FILENO;
#elif defined(BOOST_WINDOWS_API)
- stream_handler = STD_ERROR_HANDLE;
+ stream_handle = STD_ERROR_HANDLE;
#endif
+ break;
+ }
+ default:{
+
+ BOOST_ASSERT(false);
}
}
Modified: sandbox/SOC/2010/process/boost/process/detail/systembuf.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/systembuf.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/systembuf.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -153,7 +153,7 @@
* \returns traits_type::eof() if a write error occurrs. Otherwise
* returns traits_type::not_eof(c).
*/
- virtual int_type overflow(int c){
+ int_type overflow(int c){
BOOST_ASSERT(pptr() >= epptr());
if (sync() == -1)
Modified: sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -151,7 +151,7 @@
}
case inherit:{
- return_handle = file_handle::win32_dup_std(sd.stream_handler, true);
+ return_handle = file_handle::win32_dup_std(sd.stream_handle, true);
break;
}
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-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -24,6 +24,7 @@
#include <boost/process/detail/posix_helpers.hpp>
#include <stdlib.h>
#include <unistd.h>
+ #include <semaphore.h>
#if defined(__CYGWIN__)
#include <boost/scoped_array.hpp>
#include <sys/cygwin.h>
@@ -88,11 +89,16 @@
std::string result;
#if defined(BOOST_POSIX_API)
+
if (path.empty()){
const char *envpath = ::getenv("PATH");
- if (!envpath)
- boost::throw_exception(boost::filesystem::filesystem_error("boost::process::find_executable_in_path: retrieving PATH failed", file, boost::system::errc::make_error_code(boost::system::errc::no_such_file_or_directory)));
-
+ if (!envpath) {
+ boost::throw_exception(
+ boost::filesystem::filesystem_error(
+ "boost::process::find_executable_in_path: retrieving PATH failed", file,
+ boost::system::errc::make_error_code(
+ boost::system::errc::no_such_file_or_directory)));
+ }
path = envpath;
}
@@ -148,8 +154,13 @@
}
#endif
- if (result.empty())
- boost::throw_exception(boost::filesystem::filesystem_error("boost::process::find_executable_in_path: file not found", file, boost::system::errc::make_error_code(boost::system::errc::no_such_file_or_directory)));
+ if (result.empty()){
+ boost::throw_exception(
+ boost::filesystem::filesystem_error(
+ "boost::process::find_executable_in_path: file not found", file,
+ boost::system::errc::make_error_code(
+ boost::system::errc::no_such_file_or_directory)));
+ }
return result;
}
@@ -222,15 +233,27 @@
#if defined(BOOST_POSIX_API)
+ static sem_t * sem_stream_config;
+
+ ::sem_unlink("boost_sem_stream_config");
+ sem_stream_config = ::sem_open("boost_sem_stream_config",O_CREAT,511,0);
+ BOOST_ASSERT( sem_stream_config != SEM_FAILED);
+
child::id_type pid = ::fork();
- if (pid == -1)
- boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::detail::posix_start: fork(2) failed"));
- else if (pid == 0){
+ if (pid == -1){
+ boost::throw_exception(
+ boost::system::system_error(
+ boost::system::error_code(errno, boost::system::get_system_category()),
+ "boost::process::detail::posix_start: fork(2) failed"));
+ }
+
+ if (pid == 0){
detail::configure_posix_stream(stdin_stream);
detail::configure_posix_stream(stdout_stream);
- detail::configure_posix_stream(stderr_stream);
+ detail::configure_posix_stream(stderr_stream);
+ ::sem_post(sem_stream_config);
std::pair<std::size_t, char**> argcv = detail::collection_to_posix_argv(args);
char **envp = detail::environment_to_envp(ctx.environment);
@@ -242,28 +265,28 @@
}
BOOST_ASSERT(pid > 0);
+ ::sem_wait(sem_stream_config);
-
- //TODO: turn this in a helper
if(ctx.stdin_behavior == capture){
- stdin_stream.object.pipe_->rend().close();
- fhstdin = stdin_stream.object.pipe_->rend().release();
+ stdin_stream.object.pipe_.rend().close();
+ fhstdin = stdin_stream.object.pipe_.wend().release();
BOOST_ASSERT(fhstdin.valid());
}
if(ctx.stdout_behavior == capture){
- stdout_stream.object.pipe_->wend().close();
- fhstdout = stdout_stream.object.pipe_->wend().release();
+ stdout_stream.object.pipe_.wend().close();
+ fhstdout = stdout_stream.object.pipe_.wend().release();
BOOST_ASSERT(fhstdout.valid());
}
if(ctx.stderr_behavior == capture){
- stderr_stream.object.pipe_->wend().close();
- fhstderr = stderr_stream.object.pipe_->wend().release();
+ stderr_stream.object.pipe_.wend().close();
+ fhstderr = stderr_stream.object.pipe_.wend().release();
BOOST_ASSERT(fhstderr.valid());
}
+
return child(pid, fhstdin, fhstdout, fhstderr);
Modified: sandbox/SOC/2010/process/boost/process/status.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/status.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/status.hpp 2010-05-22 17:20:21 EDT (Sat, 22 May 2010)
@@ -69,7 +69,7 @@
* \pre exited() is true.
*/
- int exit_status() const{
+ int exit_code() const{
BOOST_ASSERT(exited());
#if defined(BOOST_POSIX_API)
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