Initial import from SVN
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_BIND_FD_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_BIND_FD_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class FileDescriptor>
|
||||
class bind_fd_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
bind_fd_(int id, const FileDescriptor &fd) : id_(id), fd_(fd) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::dup2(fd_.handle(), id_);
|
||||
}
|
||||
|
||||
private:
|
||||
int id_;
|
||||
FileDescriptor fd_;
|
||||
};
|
||||
|
||||
template <class FileDescriptor>
|
||||
bind_fd_<FileDescriptor> bind_fd(int id, const FileDescriptor &fd)
|
||||
{
|
||||
return bind_fd_<FileDescriptor>(id, fd);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_BIND_STDERR_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_BIND_STDERR_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class bind_stderr : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit bind_stderr(const boost::iostreams::file_descriptor_sink &sink)
|
||||
: sink_(sink) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::dup2(sink_.handle(), STDERR_FILENO);
|
||||
}
|
||||
|
||||
private:
|
||||
boost::iostreams::file_descriptor_sink sink_;
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_BIND_STDIN_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_BIND_STDIN_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class bind_stdin : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit bind_stdin(const boost::iostreams::file_descriptor_source &source)
|
||||
: source_(source) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::dup2(source_.handle(), STDIN_FILENO);
|
||||
}
|
||||
|
||||
private:
|
||||
boost::iostreams::file_descriptor_source source_;
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_BIND_STDOUT_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_BIND_STDOUT_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class bind_stdout : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit bind_stdout(const boost::iostreams::file_descriptor_sink &sink)
|
||||
: sink_(sink) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::dup2(sink_.handle(), STDOUT_FILENO);
|
||||
}
|
||||
|
||||
private:
|
||||
boost::iostreams::file_descriptor_sink sink_;
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_FD_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_FD_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class close_fd : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit close_fd(int fd) : fd_(fd) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::close(fd_);
|
||||
}
|
||||
|
||||
private:
|
||||
int fd_;
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_FDS_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_FDS_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/range/algorithm/for_each.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Range>
|
||||
class close_fds_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit close_fds_(const Range &fds) : fds_(fds) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
boost::for_each(fds_, ::close);
|
||||
}
|
||||
|
||||
private:
|
||||
Range fds_;
|
||||
};
|
||||
|
||||
template <class Range>
|
||||
close_fds_<Range> close_fds(const Range &fds)
|
||||
{
|
||||
return close_fds_<Range>(fds);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_FDS_IF_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_FDS_IF_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/iterator/counting_iterator.hpp>
|
||||
#include <boost/range/counting_range.hpp>
|
||||
#include <boost/range/adaptor/filtered.hpp>
|
||||
#include <boost/range/algorithm/for_each.hpp>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_MAX_FD
|
||||
# define BOOST_PROCESS_POSIX_MAX_FD 32
|
||||
#endif
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Predicate>
|
||||
class close_fds_if_ : public initializer_base
|
||||
{
|
||||
private:
|
||||
static void close(int fd)
|
||||
{
|
||||
::fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit close_fds_if_(const Predicate &pred) : pred_(pred) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
boost::for_each(
|
||||
boost::adaptors::filter(
|
||||
boost::counting_range(0, upper_bound()),
|
||||
pred_
|
||||
),
|
||||
close
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
static int upper_bound()
|
||||
{
|
||||
int up;
|
||||
#if defined(F_MAXFD)
|
||||
do
|
||||
{
|
||||
up = ::fcntl(0, F_MAXFD);
|
||||
} while (up == -1 && errno == EINTR);
|
||||
if (up == -1)
|
||||
#endif
|
||||
up = ::sysconf(_SC_OPEN_MAX);
|
||||
if (up == -1)
|
||||
up = BOOST_PROCESS_POSIX_MAX_FD;
|
||||
return up;
|
||||
}
|
||||
|
||||
Predicate pred_;
|
||||
};
|
||||
|
||||
template <class Predicate>
|
||||
close_fds_if_<Predicate> close_fds_if(const Predicate &pred)
|
||||
{
|
||||
return close_fds_if_<Predicate>(pred);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_STDERR_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_STDERR_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class close_stderr : public initializer_base
|
||||
{
|
||||
public:
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::close(STDERR_FILENO);
|
||||
}
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_STDIN_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_STDIN_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class close_stdin : public initializer_base
|
||||
{
|
||||
public:
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::close(STDIN_FILENO);
|
||||
}
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_STDOUT_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_CLOSE_STDOUT_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class close_stdout : public initializer_base
|
||||
{
|
||||
public:
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::close(STDOUT_FILENO);
|
||||
}
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_HIDE_CONSOLE_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_HIDE_CONSOLE_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class hide_console : public initializer_base
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_INHERIT_ENV_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_INHERIT_ENV_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
// From <https://svn.boost.org/trac/boost/changeset/67768>
|
||||
#if defined(__APPLE__) && defined(__DYNAMIC__)
|
||||
extern "C" { extern char ***_NSGetEnviron(void); }
|
||||
# define environ (*_NSGetEnviron())
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class inherit_env : public initializer_base
|
||||
{
|
||||
public:
|
||||
template <class PosixExecutor>
|
||||
void on_fork_setup(PosixExecutor &e) const
|
||||
{
|
||||
e.env = environ;
|
||||
}
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_INITIALIZER_BASE_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_INITIALIZER_BASE_HPP
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
struct initializer_base
|
||||
{
|
||||
template <class PosixExecutor>
|
||||
void on_fork_setup(PosixExecutor&) const {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_error(PosixExecutor&) const {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_success(PosixExecutor&) const {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_error(PosixExecutor&) const {}
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_NOTIFY_IO_SERVICE_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_NOTIFY_IO_SERVICE_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class IOService>
|
||||
class notify_io_service_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit notify_io_service_(IOService &io_service) :
|
||||
io_service_(io_service) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_setup(PosixExecutor&) const
|
||||
{
|
||||
io_service_.notify_fork(IOService::fork_prepare);
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_success(PosixExecutor&) const
|
||||
{
|
||||
io_service_.notify_fork(IOService::fork_parent);
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
io_service_.notify_fork(IOService::fork_child);
|
||||
}
|
||||
|
||||
private:
|
||||
IOService &io_service_;
|
||||
};
|
||||
|
||||
template <class IOService>
|
||||
notify_io_service_<IOService> notify_io_service(IOService &io_service)
|
||||
{
|
||||
return notify_io_service_<IOService>(io_service);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_ON_EXEC_ERROR_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_ON_EXEC_ERROR_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Handler>
|
||||
class on_exec_error_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit on_exec_error_(Handler handler) : handler_(handler) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_error(PosixExecutor &e) const
|
||||
{
|
||||
handler_(e);
|
||||
}
|
||||
|
||||
private:
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
template <class Handler>
|
||||
on_exec_error_<Handler> on_exec_error(Handler handler)
|
||||
{
|
||||
return on_exec_error_<Handler>(handler);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_ON_EXEC_SETUP_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_ON_EXEC_SETUP_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Handler>
|
||||
class on_exec_setup_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit on_exec_setup_(Handler handler) : handler_(handler) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor &e) const
|
||||
{
|
||||
handler_(e);
|
||||
}
|
||||
|
||||
private:
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
template <class Handler>
|
||||
on_exec_setup_<Handler> on_exec_setup(Handler handler)
|
||||
{
|
||||
return on_exec_setup_<Handler>(handler);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_ON_FORK_ERROR_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_ON_FORK_ERROR_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Handler>
|
||||
class on_fork_error_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit on_fork_error_(Handler handler) : handler_(handler) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_error(PosixExecutor &e) const
|
||||
{
|
||||
handler_(e);
|
||||
}
|
||||
|
||||
private:
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
template <class Handler>
|
||||
on_fork_error_<Handler> on_fork_error(Handler handler)
|
||||
{
|
||||
return on_fork_error_<Handler>(handler);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_ON_FORK_SETUP_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_ON_FORK_SETUP_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Handler>
|
||||
class on_fork_setup_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit on_fork_setup_(Handler handler) : handler_(handler) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_setup(PosixExecutor &e) const
|
||||
{
|
||||
handler_(e);
|
||||
}
|
||||
|
||||
private:
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
template <class Handler>
|
||||
on_fork_setup_<Handler> on_fork_setup(Handler handler)
|
||||
{
|
||||
return on_fork_setup_<Handler>(handler);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_ON_FORK_SUCCESS_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_ON_FORK_SUCCESS_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Handler>
|
||||
class on_fork_success_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit on_fork_success_(Handler handler) : handler_(handler) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_success(PosixExecutor &e) const
|
||||
{
|
||||
handler_(e);
|
||||
}
|
||||
|
||||
private:
|
||||
Handler handler_;
|
||||
};
|
||||
|
||||
template <class Handler>
|
||||
on_fork_success_<Handler> on_fork_success(Handler handler)
|
||||
{
|
||||
return on_fork_success_<Handler>(handler);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_RUN_EXE_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_RUN_EXE_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class run_exe_ : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit run_exe_(const std::string &s) : s_(s), cmd_line_(new char*[2])
|
||||
{
|
||||
cmd_line_[0] = const_cast<char*>(s_.c_str());
|
||||
cmd_line_[1] = 0;
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor &e) const
|
||||
{
|
||||
e.exe = s_.c_str();
|
||||
if (!e.cmd_line)
|
||||
e.cmd_line = cmd_line_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string s_;
|
||||
boost::shared_array<char*> cmd_line_;
|
||||
};
|
||||
|
||||
inline run_exe_ run_exe(const char *s)
|
||||
{
|
||||
return run_exe_(s);
|
||||
}
|
||||
|
||||
inline run_exe_ run_exe(const std::string &s)
|
||||
{
|
||||
return run_exe_(s);
|
||||
}
|
||||
|
||||
inline run_exe_ run_exe(const boost::filesystem::path &p)
|
||||
{
|
||||
return run_exe_(p.string());
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_SET_ARGS_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_SET_ARGS_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/range/algorithm/transform.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Range>
|
||||
class set_args_ : public initializer_base
|
||||
{
|
||||
private:
|
||||
static char *c_str(const std::string &s)
|
||||
{
|
||||
return const_cast<char*>(s.c_str());
|
||||
}
|
||||
|
||||
public:
|
||||
explicit set_args_(const Range &args)
|
||||
{
|
||||
args_.reset(new char*[args.size() + 1]);
|
||||
boost::transform(args, args_.get(), c_str);
|
||||
args_[args.size()] = 0;
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor &e) const
|
||||
{
|
||||
e.cmd_line = args_.get();
|
||||
if (!e.exe && *args_[0])
|
||||
e.exe = args_[0];
|
||||
}
|
||||
|
||||
private:
|
||||
boost::shared_array<char*> args_;
|
||||
};
|
||||
|
||||
template <class Range>
|
||||
set_args_<Range> set_args(const Range &range)
|
||||
{
|
||||
return set_args_<Range>(range);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_SET_CMD_LINE_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_SET_CMD_LINE_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class set_cmd_line : public initializer_base
|
||||
{
|
||||
private:
|
||||
static char *c_str(const std::string &s)
|
||||
{
|
||||
return const_cast<char*>(s.c_str());
|
||||
}
|
||||
|
||||
public:
|
||||
explicit set_cmd_line(const std::string &s)
|
||||
{
|
||||
typedef boost::tokenizer<boost::escaped_list_separator<char> > tokenizer;
|
||||
boost::escaped_list_separator<char> sep('\\', ' ', '\"');
|
||||
tokenizer tok(s, sep);
|
||||
args_.assign(tok.begin(), tok.end());
|
||||
cmd_line_.reset(new char*[args_.size() + 1]);
|
||||
boost::transform(args_, cmd_line_.get(), c_str);
|
||||
cmd_line_[args_.size()] = 0;
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor &e) const
|
||||
{
|
||||
e.cmd_line = cmd_line_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> args_;
|
||||
boost::shared_array<char*> cmd_line_;
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_SET_ENV_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_SET_ENV_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/range/algorithm/transform.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
template <class Range>
|
||||
class set_env_ : public initializer_base
|
||||
{
|
||||
private:
|
||||
static char *get_ptr(const std::string &s)
|
||||
{
|
||||
return const_cast<char*>(s.c_str());
|
||||
}
|
||||
|
||||
public:
|
||||
explicit set_env_(const Range &envs) : env_(new char*[envs.size() + 1])
|
||||
{
|
||||
boost::transform(envs, env_.get(), get_ptr);
|
||||
env_[envs.size()] = 0;
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_setup(PosixExecutor &e) const
|
||||
{
|
||||
e.env = env_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
boost::shared_array<char*> env_;
|
||||
};
|
||||
|
||||
template <class Range>
|
||||
set_env_<Range> set_env(const Range &envs)
|
||||
{
|
||||
return set_env_<Range>(envs);
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_SET_ON_ERROR_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_SET_ON_ERROR_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class set_on_error : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit set_on_error(boost::system::error_code &ec) : ec_(ec) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_setup(PosixExecutor&) const
|
||||
{
|
||||
if (::pipe(fds_) == -1)
|
||||
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec_);
|
||||
if (::fcntl(fds_[1], F_SETFD, FD_CLOEXEC) == -1)
|
||||
{
|
||||
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec_);
|
||||
::close(fds_[0]);
|
||||
::close(fds_[1]);
|
||||
}
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_error(PosixExecutor&) const
|
||||
{
|
||||
if (!ec_)
|
||||
{
|
||||
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec_);
|
||||
::close(fds_[0]);
|
||||
::close(fds_[1]);
|
||||
}
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_success(PosixExecutor&) const
|
||||
{
|
||||
if (!ec_)
|
||||
{
|
||||
::close(fds_[1]);
|
||||
int code;
|
||||
if (::read(fds_[0], &code, sizeof(int)) > 0)
|
||||
{
|
||||
ec_ = boost::system::error_code(code,
|
||||
boost::system::system_category());
|
||||
}
|
||||
::close(fds_[0]);
|
||||
}
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
if (!ec_)
|
||||
{
|
||||
::close(fds_[0]);
|
||||
}
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_error(PosixExecutor&) const
|
||||
{
|
||||
if (!ec_)
|
||||
{
|
||||
int e = errno;
|
||||
while (::write(fds_[1], &e, sizeof(int)) == -1 && errno == EINTR)
|
||||
;
|
||||
::close(fds_[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
boost::system::error_code &ec_;
|
||||
mutable int fds_[2];
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_START_IN_DIR_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_START_IN_DIR_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class start_in_dir : public initializer_base
|
||||
{
|
||||
public:
|
||||
explicit start_in_dir(const std::string &s) : s_(s) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::chdir(s_.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
std::string s_;
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,90 @@
|
||||
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
|
||||
// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
|
||||
// Copyright (c) 2009 Boris Schaeling
|
||||
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
|
||||
// Copyright (c) 2011, 2012 Jeff Flinn, 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)
|
||||
|
||||
#ifndef BOOST_PROCESS_POSIX_INITIALIZERS_THROW_ON_ERROR_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_THROW_ON_ERROR_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/initializers/initializer_base.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix { namespace initializers {
|
||||
|
||||
class throw_on_error : public initializer_base
|
||||
{
|
||||
public:
|
||||
template <class PosixExecutor>
|
||||
void on_fork_setup(PosixExecutor&) const
|
||||
{
|
||||
if (::pipe(fds_) == -1)
|
||||
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("pipe(2) failed");
|
||||
if (::fcntl(fds_[1], F_SETFD, FD_CLOEXEC) == -1)
|
||||
{
|
||||
int e = errno;
|
||||
::close(fds_[0]);
|
||||
::close(fds_[1]);
|
||||
BOOST_PROCESS_THROW(boost::system::system_error(
|
||||
boost::system::error_code(e, boost::system::system_category()),
|
||||
BOOST_PROCESS_SOURCE_LOCATION "fcntl(2) failed"));
|
||||
}
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_error(PosixExecutor&) const
|
||||
{
|
||||
int e = errno;
|
||||
::close(fds_[0]);
|
||||
::close(fds_[1]);
|
||||
BOOST_PROCESS_THROW(boost::system::system_error(
|
||||
boost::system::error_code(e, boost::system::system_category()),
|
||||
BOOST_PROCESS_SOURCE_LOCATION "fork(2) failed"));
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_fork_success(PosixExecutor&) const
|
||||
{
|
||||
::close(fds_[1]);
|
||||
int code;
|
||||
if (::read(fds_[0], &code, sizeof(int)) > 0)
|
||||
{
|
||||
::close(fds_[0]);
|
||||
BOOST_PROCESS_THROW(boost::system::system_error(
|
||||
boost::system::error_code(code,
|
||||
boost::system::system_category()),
|
||||
BOOST_PROCESS_SOURCE_LOCATION "execve(2) failed"));
|
||||
}
|
||||
::close(fds_[0]);
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::close(fds_[0]);
|
||||
}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_error(PosixExecutor&) const
|
||||
{
|
||||
int e = errno;
|
||||
while (::write(fds_[1], &e, sizeof(int)) == -1 && errno == EINTR)
|
||||
;
|
||||
::close(fds_[1]);
|
||||
}
|
||||
|
||||
private:
|
||||
mutable int fds_[2];
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user