Initial import from SVN
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// 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_CHILD_HPP
|
||||
#define BOOST_PROCESS_POSIX_CHILD_HPP
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
struct child
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
explicit child(pid_t p) : pid(p) {}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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_CREATE_PIPE_HPP
|
||||
#define BOOST_PROCESS_POSIX_CREATE_PIPE_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/process/posix/pipe.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
inline pipe create_pipe()
|
||||
{
|
||||
int fds[2];
|
||||
if (::pipe(fds) == -1)
|
||||
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("pipe(2) failed");
|
||||
return pipe(fds[0], fds[1]);
|
||||
}
|
||||
|
||||
inline pipe create_pipe(boost::system::error_code &ec)
|
||||
{
|
||||
int fds[2];
|
||||
if (::pipe(fds) == -1)
|
||||
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
|
||||
else
|
||||
ec.clear();
|
||||
return pipe(fds[0], fds[1]);
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
// 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_EXECUTE_HPP
|
||||
#define BOOST_PROCESS_POSIX_EXECUTE_HPP
|
||||
|
||||
#include <boost/process/posix/executor.hpp>
|
||||
#include <boost/process/posix/child.hpp>
|
||||
#include <boost/fusion/tuple/make_tuple.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
template <class I0>
|
||||
child execute(const I0 &i0)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0)));
|
||||
}
|
||||
|
||||
template <class I0, class I1>
|
||||
child execute(const I0 &i0, const I1 &i1)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1)));
|
||||
}
|
||||
|
||||
template <class I0, class I1, class I2>
|
||||
child execute(const I0 &i0, const I1 &i1, const I2 &i2)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1), boost::cref(i2)));
|
||||
}
|
||||
|
||||
template <class I0, class I1, class I2, class I3>
|
||||
child execute(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1), boost::cref(i2), boost::cref(i3)));
|
||||
}
|
||||
|
||||
template <class I0, class I1, class I2, class I3, class I4>
|
||||
child execute(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1), boost::cref(i2), boost::cref(i3), boost::cref(i4)));
|
||||
}
|
||||
|
||||
template <class I0, class I1, class I2, class I3, class I4, class I5>
|
||||
child execute(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4, const I5 &i5)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1), boost::cref(i2), boost::cref(i3), boost::cref(i4), boost::cref(i5)));
|
||||
}
|
||||
|
||||
template <class I0, class I1, class I2, class I3, class I4, class I5, class I6>
|
||||
child execute(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4, const I5 &i5, const I6 &i6)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1), boost::cref(i2), boost::cref(i3), boost::cref(i4), boost::cref(i5), boost::cref(i6)));
|
||||
}
|
||||
|
||||
template <class I0, class I1, class I2, class I3, class I4, class I5, class I6, class I7>
|
||||
child execute(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4, const I5 &i5, const I6 &i6, const I7 &i7)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1), boost::cref(i2), boost::cref(i3), boost::cref(i4), boost::cref(i5), boost::cref(i6), boost::cref(i7)));
|
||||
}
|
||||
|
||||
template <class I0, class I1, class I2, class I3, class I4, class I5, class I6, class I7, class I8>
|
||||
child execute(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4, const I5 &i5, const I6 &i6, const I7 &i7, const I8 &i8)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1), boost::cref(i2), boost::cref(i3), boost::cref(i4), boost::cref(i5), boost::cref(i6), boost::cref(i7), boost::cref(i8)));
|
||||
}
|
||||
|
||||
template <class I0, class I1, class I2, class I3, class I4, class I5, class I6, class I7, class I8, class I9>
|
||||
child execute(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4, const I5 &i5, const I6 &i6, const I7 &i7, const I8 &i8, const I9 &i9)
|
||||
{
|
||||
return executor()(boost::fusion::make_tuple(boost::cref(i0), boost::cref(i1), boost::cref(i2), boost::cref(i3), boost::cref(i4), boost::cref(i5), boost::cref(i6), boost::cref(i7), boost::cref(i8), boost::cref(i9)));
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,120 @@
|
||||
// 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_EXECUTOR_HPP
|
||||
#define BOOST_PROCESS_POSIX_EXECUTOR_HPP
|
||||
|
||||
#include <boost/process/posix/child.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||
#include <cstdlib>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
struct executor
|
||||
{
|
||||
executor() : exe(0), cmd_line(0), env(0) {}
|
||||
|
||||
struct call_on_fork_setup
|
||||
{
|
||||
executor &e_;
|
||||
|
||||
call_on_fork_setup(executor &e) : e_(e) {}
|
||||
|
||||
template <class Arg>
|
||||
void operator()(const Arg &arg) const
|
||||
{
|
||||
arg.on_fork_setup(e_);
|
||||
}
|
||||
};
|
||||
|
||||
struct call_on_fork_error
|
||||
{
|
||||
executor &e_;
|
||||
|
||||
call_on_fork_error(executor &e) : e_(e) {}
|
||||
|
||||
template <class Arg>
|
||||
void operator()(Arg &arg) const
|
||||
{
|
||||
arg.on_fork_error(e_);
|
||||
}
|
||||
};
|
||||
|
||||
struct call_on_fork_success
|
||||
{
|
||||
executor &e_;
|
||||
|
||||
call_on_fork_success(executor &e) : e_(e) {}
|
||||
|
||||
template <class Arg>
|
||||
void operator()(Arg &arg) const
|
||||
{
|
||||
arg.on_fork_success(e_);
|
||||
}
|
||||
};
|
||||
|
||||
struct call_on_exec_setup
|
||||
{
|
||||
executor &e_;
|
||||
|
||||
call_on_exec_setup(executor &e) : e_(e) {}
|
||||
|
||||
template <class Arg>
|
||||
void operator()(Arg &arg) const
|
||||
{
|
||||
arg.on_exec_setup(e_);
|
||||
}
|
||||
};
|
||||
|
||||
struct call_on_exec_error
|
||||
{
|
||||
executor &e_;
|
||||
|
||||
call_on_exec_error(executor &e) : e_(e) {}
|
||||
|
||||
template <class Arg>
|
||||
void operator()(Arg &arg) const
|
||||
{
|
||||
arg.on_exec_error(e_);
|
||||
}
|
||||
};
|
||||
|
||||
template <class InitializerSequence>
|
||||
child operator()(const InitializerSequence &seq)
|
||||
{
|
||||
boost::fusion::for_each(seq, call_on_fork_setup(*this));
|
||||
|
||||
pid_t pid = ::fork();
|
||||
if (pid == -1)
|
||||
{
|
||||
boost::fusion::for_each(seq, call_on_fork_error(*this));
|
||||
}
|
||||
else if (pid == 0)
|
||||
{
|
||||
boost::fusion::for_each(seq, call_on_exec_setup(*this));
|
||||
::execve(exe, cmd_line, env);
|
||||
boost::fusion::for_each(seq, call_on_exec_error(*this));
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
boost::fusion::for_each(seq, call_on_fork_success(*this));
|
||||
|
||||
return child(pid);
|
||||
}
|
||||
|
||||
const char *exe;
|
||||
char **cmd_line;
|
||||
char **env;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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_HPP
|
||||
#define BOOST_PROCESS_POSIX_INITIALIZERS_HPP
|
||||
|
||||
#include <boost/process/posix/initializers/bind_fd.hpp>
|
||||
#include <boost/process/posix/initializers/bind_stderr.hpp>
|
||||
#include <boost/process/posix/initializers/bind_stdin.hpp>
|
||||
#include <boost/process/posix/initializers/bind_stdout.hpp>
|
||||
#include <boost/process/posix/initializers/close_fd.hpp>
|
||||
#include <boost/process/posix/initializers/close_fds.hpp>
|
||||
#include <boost/process/posix/initializers/close_fds_if.hpp>
|
||||
#include <boost/process/posix/initializers/close_stderr.hpp>
|
||||
#include <boost/process/posix/initializers/close_stdin.hpp>
|
||||
#include <boost/process/posix/initializers/close_stdout.hpp>
|
||||
#include <boost/process/posix/initializers/hide_console.hpp>
|
||||
#include <boost/process/posix/initializers/inherit_env.hpp>
|
||||
#include <boost/process/posix/initializers/notify_io_service.hpp>
|
||||
#include <boost/process/posix/initializers/on_exec_error.hpp>
|
||||
#include <boost/process/posix/initializers/on_exec_setup.hpp>
|
||||
#include <boost/process/posix/initializers/on_fork_error.hpp>
|
||||
#include <boost/process/posix/initializers/on_fork_setup.hpp>
|
||||
#include <boost/process/posix/initializers/on_fork_success.hpp>
|
||||
#include <boost/process/posix/initializers/run_exe.hpp>
|
||||
#include <boost/process/posix/initializers/set_args.hpp>
|
||||
#include <boost/process/posix/initializers/set_cmd_line.hpp>
|
||||
#include <boost/process/posix/initializers/set_env.hpp>
|
||||
#include <boost/process/posix/initializers/set_on_error.hpp>
|
||||
#include <boost/process/posix/initializers/start_in_dir.hpp>
|
||||
#include <boost/process/posix/initializers/throw_on_error.hpp>
|
||||
|
||||
#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_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
|
||||
@@ -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_PIPE_HPP
|
||||
#define BOOST_PROCESS_POSIX_PIPE_HPP
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
struct pipe
|
||||
{
|
||||
int source;
|
||||
int sink;
|
||||
|
||||
pipe(int source, int sink) : source(source), sink(sink) {}
|
||||
};
|
||||
|
||||
inline pipe make_pipe(int source, int sink)
|
||||
{
|
||||
return pipe(source, sink);
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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_SEARCH_PATH_HPP
|
||||
#define BOOST_PROCESS_POSIX_SEARCH_PATH_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
inline std::string search_path(const std::string &filename,
|
||||
std::string path = "")
|
||||
{
|
||||
if (path.empty())
|
||||
{
|
||||
path = ::getenv("PATH");
|
||||
if (path.empty())
|
||||
BOOST_PROCESS_THROW(std::runtime_error(
|
||||
"Environment variable PATH not found"));
|
||||
}
|
||||
|
||||
std::string result;
|
||||
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
||||
boost::char_separator<char> sep(":");
|
||||
tokenizer tok(path, sep);
|
||||
for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
|
||||
{
|
||||
boost::filesystem::path p = *it;
|
||||
p /= filename;
|
||||
if (!::access(p.c_str(), X_OK))
|
||||
{
|
||||
result = p.string();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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_SHELL_PATH_HPP
|
||||
#define BOOST_PROCESS_POSIX_SHELL_PATH_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
inline boost::filesystem::path shell_path()
|
||||
{
|
||||
return "/bin/sh";
|
||||
}
|
||||
|
||||
inline boost::filesystem::path shell_path(boost::system::error_code &ec)
|
||||
{
|
||||
ec.clear();
|
||||
return "/bin/sh";
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#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_TERMINATE_HPP
|
||||
#define BOOST_PROCESS_POSIX_TERMINATE_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <signal.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
template <class Process>
|
||||
void terminate(const Process &p)
|
||||
{
|
||||
if (::kill(p.pid, SIGKILL) == -1)
|
||||
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("kill(2) failed");
|
||||
}
|
||||
|
||||
template <class Process>
|
||||
void terminate(const Process &p, boost::system::error_code &ec)
|
||||
{
|
||||
if (::kill(p.pid, SIGKILL) == -1)
|
||||
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
|
||||
else
|
||||
ec.clear();
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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_WAIT_FOR_EXIT_HPP
|
||||
#define BOOST_PROCESS_POSIX_WAIT_FOR_EXIT_HPP
|
||||
|
||||
#include <boost/process/config.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
namespace boost { namespace process { namespace posix {
|
||||
|
||||
template <class Process>
|
||||
inline int wait_for_exit(const Process &p)
|
||||
{
|
||||
pid_t ret;
|
||||
int status;
|
||||
do
|
||||
{
|
||||
ret = ::waitpid(p.pid, &status, 0);
|
||||
} while ((ret == -1 && errno == EINTR) || (ret != -1 && !WIFEXITED(status)));
|
||||
if (ret == -1)
|
||||
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("waitpid(2) failed");
|
||||
return status;
|
||||
}
|
||||
|
||||
template <class Process>
|
||||
inline int wait_for_exit(const Process &p, boost::system::error_code &ec)
|
||||
{
|
||||
pid_t ret;
|
||||
int status;
|
||||
do
|
||||
{
|
||||
ret = ::waitpid(p.pid, &status, 0);
|
||||
} while ((ret == -1 && errno == EINTR) || (ret != -1 && !WIFEXITED(status)));
|
||||
if (ret == -1)
|
||||
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
|
||||
else
|
||||
ec.clear();
|
||||
return status;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user