a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt// Copyright (c) 2008 The NetBSD Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// All rights reserved.
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// 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// 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// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// The "argv_array" type.
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.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt typedef args_vector::const_iterator const_iterator;
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 const char* const* exec_argv(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char* operator[](int) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunttemplate< class C >
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for (typename C::const_iterator iter = c.begin(); iter != c.end();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// The "stream" types.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
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 // 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 stream_connect(const int, const int);
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 // 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 // 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 Hunt// The "status" type.
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 bool exited(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int exitstatus(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool signaled(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int termsig(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool coredump(void) const;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// The "child" type.
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// Free functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt} // namespace detail
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// TODO: The void* cookie can probably be templatized, thus also allowing
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// const data structures.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err = atf_process_fork(&c, start, outsb.get_sb(),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntexec(const atf::fs::path& prog, const argv_array& argv,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt void (*prehook)(void))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err = atf_process_exec_array(&s, prog.c_path(),
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntexec(const atf::fs::path& prog, const argv_array& argv,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt} // namespace process
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt} // namespace atf
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#endif // !defined(ATF_CXX_DETAIL_PROCESS_HPP)