a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt// Copyright (c) 2008 The NetBSD Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// All rights reserved.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt//
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// Redistribution and use in source and binary forms, with or without
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// modification, are permitted provided that the following conditions
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// are met:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// 1. Redistributions of source code must retain the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// notice, this list of conditions and the following disclaimer.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// 2. Redistributions in binary form must reproduce the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// notice, this list of conditions and the following disclaimer in the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// documentation and/or other materials provided with the distribution.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt//
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#if !defined(ATF_CXX_DETAIL_PROCESS_HPP)
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#define ATF_CXX_DETAIL_PROCESS_HPP
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntextern "C" {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <sys/types.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include <atf-c/detail/process.h>
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include <atf-c/error.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <string>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <vector>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include <atf-c++/detail/auto_array.hpp>
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include <atf-c++/detail/exceptions.hpp>
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include <atf-c++/detail/fs.hpp>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntnamespace atf {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntnamespace process {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// The "argv_array" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass argv_array {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt typedef std::vector< std::string > args_vector;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt args_vector m_args;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // TODO: This is immutable, so we should be able to use
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // std::tr1::shared_array instead when it becomes widely available.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // The reason would be to remove all copy constructors and assignment
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // operators from this class.
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt auto_array< const char* > m_exec_argv;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt void ctor_init_exec_argv(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt typedef args_vector::const_iterator const_iterator;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt typedef args_vector::size_type size_type;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv_array(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv_array(const char*, ...);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt explicit argv_array(const char* const*);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class C > explicit argv_array(const C&);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv_array(const argv_array&);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char* const* exec_argv(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt size_type size(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char* operator[](int) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const_iterator begin(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const_iterator end(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv_array& operator=(const argv_array&);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunttemplate< class C >
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntargv_array::argv_array(const C& c)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for (typename C::const_iterator iter = c.begin(); iter != c.end();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt iter++)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt m_args.push_back(*iter);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ctor_init_exec_argv();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// The "stream" types.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass basic_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntprotected:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t m_sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool m_inited;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const atf_process_stream_t* get_sb(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt basic_stream(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ~basic_stream(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass stream_capture : basic_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // Allow access to the getters.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt child fork(void (*)(void*), const OutStream&, const ErrStream&, void*);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status exec(const atf::fs::path&, const argv_array&,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt const OutStream&, const ErrStream&, void (*)(void));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt stream_capture(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass stream_connect : basic_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // Allow access to the getters.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt child fork(void (*)(void*), const OutStream&, const ErrStream&, void*);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status exec(const atf::fs::path&, const argv_array&,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt const OutStream&, const ErrStream&, void (*)(void));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt stream_connect(const int, const int);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass stream_inherit : basic_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // Allow access to the getters.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt child fork(void (*)(void*), const OutStream&, const ErrStream&, void*);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status exec(const atf::fs::path&, const argv_array&,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt const OutStream&, const ErrStream&, void (*)(void));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt stream_inherit(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass stream_redirect_fd : basic_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // Allow access to the getters.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt child fork(void (*)(void*), const OutStream&, const ErrStream&, void*);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status exec(const atf::fs::path&, const argv_array&,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt const OutStream&, const ErrStream&, void (*)(void));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt stream_redirect_fd(const int);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass stream_redirect_path : basic_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // Allow access to the getters.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt child fork(void (*)(void*), const OutStream&, const ErrStream&, void*);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status exec(const atf::fs::path&, const argv_array&,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt const OutStream&, const ErrStream&, void (*)(void));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt stream_redirect_path(const fs::path&);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// The "status" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass status {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t m_status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt friend class child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status exec(const atf::fs::path&, const argv_array&,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt const OutStream&, const ErrStream&, void (*)(void));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status(atf_process_status_t&);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ~status(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool exited(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int exitstatus(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool signaled(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int termsig(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool coredump(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// The "child" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntclass child {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_child_t m_child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool m_waited;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt template< class OutStream, class ErrStream > friend
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt child fork(void (*)(void*), const OutStream&, const ErrStream&, void*);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt child(atf_process_child_t& c);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntpublic:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ~child(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status wait(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt pid_t pid(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int stdout_fd(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int stderr_fd(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// Free functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntnamespace detail {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid flush_streams(void);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt} // namespace detail
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// TODO: The void* cookie can probably be templatized, thus also allowing
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// const data structures.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunttemplate< class OutStream, class ErrStream >
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntchild
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntfork(void (*start)(void*), const OutStream& outsb,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const ErrStream& errsb, void* v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_child_t c;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt detail::flush_streams();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err = atf_process_fork(&c, start, outsb.get_sb(),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt errsb.get_sb(), v);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt throw_atf_error(err);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return child(c);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunttemplate< class OutStream, class ErrStream >
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatus
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntexec(const atf::fs::path& prog, const argv_array& argv,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt const OutStream& outsb, const ErrStream& errsb,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt void (*prehook)(void))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t s;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt detail::flush_streams();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err = atf_process_exec_array(&s, prog.c_path(),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv.exec_argv(),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt outsb.get_sb(),
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt errsb.get_sb(),
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt prehook);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt throw_atf_error(err);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return status(s);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunttemplate< class OutStream, class ErrStream >
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntstatus
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntexec(const atf::fs::path& prog, const argv_array& argv,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt const OutStream& outsb, const ErrStream& errsb)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt return exec(prog, argv, outsb, errsb, NULL);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt}
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt} // namespace process
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt} // namespace atf
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#endif // !defined(ATF_CXX_DETAIL_PROCESS_HPP)