//
// Automated Testing Framework (atf)
//
// Copyright (c) 2008 The NetBSD Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
//
// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
extern "C" {
#include <fcntl.h>
#include <signal.h>
}
#include <cassert>
#include <cstdarg>
#include <cerrno>
#include <cstring>
#include <iostream>
#include "defs.hpp"
#include "exceptions.hpp"
#include "text.hpp"
#include "process.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
// ------------------------------------------------------------------------
template< class C >
tools::auto_array< const char* >
collection_to_argv(const C& c)
{
iter++) {
pos++;
}
return argv;
}
template< class C >
C
{
C c;
return c;
}
static
void
{
"Could not allocate file descriptor",
errno);
} else {
}
}
}
static
int
{
#define UNCONST(a) ((void *)(unsigned long)(const void *)(a))
}
void
{
}
// ------------------------------------------------------------------------
// The "argv_array" type.
// ------------------------------------------------------------------------
{
}
{
{
const char* nextarg;
}
}
{
}
{
}
void
{
}
const char* const*
const
{
return m_exec_argv.get();
}
const
{
}
const char*
const
{
}
const
{
}
const
{
}
{
if (this != &a) {
}
return *this;
}
// ------------------------------------------------------------------------
// The "stream" types.
// ------------------------------------------------------------------------
{
for (int i = 0; i < 2; i++)
m_pipefds[i] = -1;
}
{
for (int i = 0; i < 2; i++)
if (m_pipefds[i] != -1)
}
void
{
"Failed to create pipe", errno);
}
int
{
m_pipefds[0] = -1;
return fd;
}
void
{
}
}
{
}
void
{
}
int
{
return -1;
}
void
{
}
{
}
void
{
}
int
{
return -1;
}
void
{
}
{
}
void
{
}
int
{
return -1;
}
void
{
}
m_path(p)
{
}
void
{
}
int
{
return -1;
}
void
{
if (aux == -1)
else
}
// ------------------------------------------------------------------------
// The "status" type.
// ------------------------------------------------------------------------
m_status(s)
{
}
{
}
bool
const
{
return WIFEXITED(mutable_status);
}
int
const
{
return WEXITSTATUS(mutable_status);
}
bool
const
{
return WIFSIGNALED(mutable_status);
}
int
const
{
return WTERMSIG(mutable_status);
}
bool
const
{
#if defined(WCOREDUMP)
return WCOREDUMP(mutable_status);
#else
return false;
#endif
}
// ------------------------------------------------------------------------
// The "child" type.
// ------------------------------------------------------------------------
const int stderr_fd_arg) :
m_waited(false)
{
}
{
if (!m_waited) {
(void)wait();
if (m_stdout != -1)
if (m_stderr != -1)
}
}
{
int s;
if (m_stdout != -1)
if (m_stderr != -1)
m_waited = true;
return status(s);
}
const
{
return m_pid;
}
int
{
return m_stdout;
}
int
{
return m_stderr;
}
// ------------------------------------------------------------------------
// Free functions.
// ------------------------------------------------------------------------
void
{
// This is a weird hack to ensure that the output of the parent process
// is flushed before executing a child which prevents, for example, the
// output of the atf-run hooks to appear before the output of atf-run
// itself.
//
// TODO: This should only be executed when inheriting the stdout or
// stderr file descriptors. However, the flushing is specific to the
// iostreams, so we cannot do it from the C library where all the process
// logic is performed. Come up with a better design.
}